@sqb/nestjs 4.20.7 → 4.21.1
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/README.md +33 -0
- package/package.json +10 -26
- package/{types/sqb-core.module.d.ts → sqb-core.module.d.ts} +4 -2
- package/{esm/sqb-core.module.js → sqb-core.module.js} +30 -3
- package/{types/sqb.interface.d.ts → sqb.interface.d.ts} +1 -0
- 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.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/{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/README.md
CHANGED
|
@@ -41,6 +41,38 @@ $ npm install @sqb/nestjs --save
|
|
|
41
41
|
|
|
42
42
|
- node >= 16.x
|
|
43
43
|
|
|
44
|
+
## Environment Variables
|
|
45
|
+
|
|
46
|
+
The library supports configuration through environment variables. Environment variables below is accepted.
|
|
47
|
+
All environment variables starts with prefix (SQB\_). This can be configured while registering the module.
|
|
48
|
+
|
|
49
|
+
<!--- BEGIN env --->
|
|
50
|
+
|
|
51
|
+
| Environment Variable | Type | Default | Description |
|
|
52
|
+
|------------------------------|---------|---------|-------------------------------------------------------|
|
|
53
|
+
| SQB_DIALECT | String | | Database dialect (e.g. postgres, mysql, oracle) |
|
|
54
|
+
| SQB_CONNECTION_NAME | String | | Logical name of the database connection |
|
|
55
|
+
| SQB_HOST | String | | Database server host address |
|
|
56
|
+
| SQB_PORT | Number | | Database server port |
|
|
57
|
+
| SQB_DATABASE | String | | Database name |
|
|
58
|
+
| SQB_SCHEMA | String | | Default database schema |
|
|
59
|
+
| SQB_USER | String | | Database user name |
|
|
60
|
+
| SQB_PASSWORD | String | | Database user password |
|
|
61
|
+
| SQB_DRIVER | String | | Database driver identifier |
|
|
62
|
+
| SQB_POOL_MAX | Number | | Maximum number of connections in the pool |
|
|
63
|
+
| SQB_POOL_MIN | Number | | Minimum number of connections in the pool |
|
|
64
|
+
| SQB_POOL_IDLE_TIMEOUT | Number | | Time (ms) before an idle connection is released |
|
|
65
|
+
| SQB_POOL_ACQUIRE_TIMEOUT | Number | | Timeout (ms) for acquiring a connection |
|
|
66
|
+
| SQB_POOL_ACQUIRE_MAX_RETRIES | Number | | Maximum number of retries when acquiring a connection |
|
|
67
|
+
| SQB_POOL_ACQUIRE_RETRY_WAIT | Number | | Wait time (ms) between acquire retry attempts |
|
|
68
|
+
| SQB_POOL_FIFO | Boolean | | Whether the pool queue operates in FIFO mode |
|
|
69
|
+
| SQB_POOL_MAX_QUEUE | Number | | Maximum number of queued connection requests |
|
|
70
|
+
| SQB_POOL_MIN_IDLE | Number | | Minimum number of idle connections to keep |
|
|
71
|
+
| SQB_POOL_VALIDATION | Boolean | | Enables validation of connections before use |
|
|
72
|
+
| SQB_POOL_HOUSE_KEEP_INTERVAL | Number | | Interval (ms) for pool housekeeping tasks |
|
|
73
|
+
|
|
74
|
+
<!--- END env --->
|
|
75
|
+
|
|
44
76
|
### License
|
|
45
77
|
|
|
46
78
|
SQB is available under [MIT](LICENSE) license.
|
|
@@ -61,3 +93,4 @@ SQB is available under [MIT](LICENSE) license.
|
|
|
61
93
|
[devdependencies-url]: https://david-dm.org/sqbjs/@sqb/nestjs?type=dev
|
|
62
94
|
[quality-image]: http://npm.packagequality.com/shield/@sqb/nestjs.png
|
|
63
95
|
[quality-url]: http://packagequality.com/#?package=@sqb/nestjs
|
|
96
|
+
|
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.1",
|
|
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.1",
|
|
16
|
+
"@sqb/connect": "^4.21.1",
|
|
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",
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { DynamicModule, OnApplicationShutdown } from '@nestjs/common';
|
|
1
|
+
import { DynamicModule, Logger, OnApplicationShutdown } from '@nestjs/common';
|
|
2
2
|
import { ModuleRef } from '@nestjs/core';
|
|
3
3
|
import type { SqbModuleAsyncOptions, SqbModuleOptions } from './sqb.interface.js';
|
|
4
4
|
export declare class SqbCoreModule implements OnApplicationShutdown {
|
|
5
5
|
private readonly options;
|
|
6
6
|
private readonly moduleRef;
|
|
7
|
-
|
|
7
|
+
private logger?;
|
|
8
|
+
constructor(options: SqbModuleOptions, moduleRef: ModuleRef, logger?: Logger | undefined);
|
|
8
9
|
static forRoot(options?: SqbModuleOptions): DynamicModule;
|
|
9
10
|
static forRootAsync(options: SqbModuleAsyncOptions): DynamicModule;
|
|
11
|
+
onApplicationBootstrap(): Promise<void> | undefined;
|
|
10
12
|
onApplicationShutdown(): Promise<void>;
|
|
11
13
|
private static createAsyncProviders;
|
|
12
14
|
private static createAsyncOptionsProvider;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var SqbCoreModule_1;
|
|
2
2
|
import { __decorate, __metadata, __param } from "tslib";
|
|
3
|
-
import { Global, Inject, Module, } from '@nestjs/common';
|
|
3
|
+
import { Global, Inject, Logger, Module, } from '@nestjs/common';
|
|
4
4
|
import { ModuleRef } from '@nestjs/core';
|
|
5
5
|
import { SqbClient } from '@sqb/connect';
|
|
6
6
|
import * as crypto from 'crypto';
|
|
@@ -12,9 +12,11 @@ import { getSQBToken, handleRetry } from './sqb.utils.js';
|
|
|
12
12
|
let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
13
13
|
options;
|
|
14
14
|
moduleRef;
|
|
15
|
-
|
|
15
|
+
logger;
|
|
16
|
+
constructor(options, moduleRef, logger) {
|
|
16
17
|
this.options = options;
|
|
17
18
|
this.moduleRef = moduleRef;
|
|
19
|
+
this.logger = logger;
|
|
18
20
|
}
|
|
19
21
|
static forRoot(options = {}) {
|
|
20
22
|
const optionsProvider = {
|
|
@@ -35,6 +37,12 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
35
37
|
provide: SQB_CONNECTION_OPTIONS,
|
|
36
38
|
useValue: getSqbConfig(options.useValue || {}, options.envPrefix),
|
|
37
39
|
},
|
|
40
|
+
{
|
|
41
|
+
provide: Logger,
|
|
42
|
+
useValue: typeof options.logger === 'string'
|
|
43
|
+
? new Logger(options.logger)
|
|
44
|
+
: options.logger,
|
|
45
|
+
},
|
|
38
46
|
],
|
|
39
47
|
exports: [connectionProvider],
|
|
40
48
|
};
|
|
@@ -60,10 +68,28 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
60
68
|
provide: SQB_MODULE_ID,
|
|
61
69
|
useValue: crypto.randomUUID(),
|
|
62
70
|
},
|
|
71
|
+
{
|
|
72
|
+
provide: Logger,
|
|
73
|
+
useValue: typeof options.logger === 'string'
|
|
74
|
+
? new Logger(options.logger)
|
|
75
|
+
: options.logger,
|
|
76
|
+
},
|
|
63
77
|
],
|
|
64
78
|
exports: [connectionProvider],
|
|
65
79
|
};
|
|
66
80
|
}
|
|
81
|
+
onApplicationBootstrap() {
|
|
82
|
+
const client = this.moduleRef.get(getSQBToken(this.options.name));
|
|
83
|
+
const op = this.moduleRef.get(SQB_CONNECTION_OPTIONS);
|
|
84
|
+
if (this.options.lazyConnect)
|
|
85
|
+
return;
|
|
86
|
+
this.logger?.log(`Connecting to database [${op.database}] at ${op.host}:${op.port} using ${op.dialect} dialect`);
|
|
87
|
+
Logger.flush();
|
|
88
|
+
return client.test().catch(e => {
|
|
89
|
+
this.logger?.error(`${op.dialect} connection failed: ` + e.message);
|
|
90
|
+
throw e;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
67
93
|
async onApplicationShutdown() {
|
|
68
94
|
const client = this.moduleRef.get(getSQBToken(this.options.name));
|
|
69
95
|
const op = this.moduleRef.get(SQB_CONNECTION_OPTIONS);
|
|
@@ -121,6 +147,7 @@ SqbCoreModule = SqbCoreModule_1 = __decorate([
|
|
|
121
147
|
Global(),
|
|
122
148
|
Module({}),
|
|
123
149
|
__param(0, Inject(SQB_MODULE_OPTIONS)),
|
|
124
|
-
__metadata("design:paramtypes", [Object, ModuleRef
|
|
150
|
+
__metadata("design:paramtypes", [Object, ModuleRef,
|
|
151
|
+
Logger])
|
|
125
152
|
], SqbCoreModule);
|
|
126
153
|
export { SqbCoreModule };
|
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
|