@sqb/nestjs 4.14.1 → 4.15.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/esm/index.js +10 -5
- package/esm/sqb-core.module.js +32 -29
- package/esm/sqb.constants.js +5 -2
- package/esm/sqb.decorators.js +7 -3
- package/esm/sqb.interface.js +2 -1
- package/esm/sqb.module.js +11 -8
- package/esm/sqb.utils.js +14 -10
- package/package.json +24 -18
- package/cjs/package.json +0 -3
package/esm/index.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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/esm/sqb-core.module.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var SqbCoreModule_1;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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 sqb_constants_js_1 = require("./sqb.constants.js");
|
|
13
|
+
const sqb_utils_js_1 = require("./sqb.utils.js");
|
|
11
14
|
let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
12
15
|
constructor(options, moduleRef) {
|
|
13
16
|
this.options = options;
|
|
@@ -15,11 +18,11 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
15
18
|
}
|
|
16
19
|
static forRoot(options = {}) {
|
|
17
20
|
const optionsProvider = {
|
|
18
|
-
provide: SQB_MODULE_OPTIONS,
|
|
21
|
+
provide: sqb_constants_js_1.SQB_MODULE_OPTIONS,
|
|
19
22
|
useValue: options,
|
|
20
23
|
};
|
|
21
24
|
const connectionProvider = {
|
|
22
|
-
provide: getSQBToken(options.name),
|
|
25
|
+
provide: (0, sqb_utils_js_1.getSQBToken)(options.name),
|
|
23
26
|
useFactory: () => this.createConnection(options),
|
|
24
27
|
};
|
|
25
28
|
return {
|
|
@@ -30,8 +33,8 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
30
33
|
}
|
|
31
34
|
static forRootAsync(options) {
|
|
32
35
|
const connectionProvider = {
|
|
33
|
-
provide: getSQBToken(options.name),
|
|
34
|
-
inject: [SQB_MODULE_OPTIONS],
|
|
36
|
+
provide: (0, sqb_utils_js_1.getSQBToken)(options.name),
|
|
37
|
+
inject: [sqb_constants_js_1.SQB_MODULE_OPTIONS],
|
|
35
38
|
useFactory: async (sqbOptions) => this.createConnection(sqbOptions),
|
|
36
39
|
};
|
|
37
40
|
const asyncProviders = this.createAsyncProviders(options);
|
|
@@ -42,7 +45,7 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
42
45
|
...asyncProviders,
|
|
43
46
|
connectionProvider,
|
|
44
47
|
{
|
|
45
|
-
provide: SQB_MODULE_ID,
|
|
48
|
+
provide: sqb_constants_js_1.SQB_MODULE_ID,
|
|
46
49
|
useValue: crypto.randomUUID(),
|
|
47
50
|
},
|
|
48
51
|
],
|
|
@@ -50,7 +53,7 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
50
53
|
};
|
|
51
54
|
}
|
|
52
55
|
async onApplicationShutdown() {
|
|
53
|
-
const client = this.moduleRef.get(getSQBToken(this.options.name));
|
|
56
|
+
const client = this.moduleRef.get((0, sqb_utils_js_1.getSQBToken)(this.options.name));
|
|
54
57
|
if (client)
|
|
55
58
|
await client.close(this.options.shutdownWaitMs);
|
|
56
59
|
}
|
|
@@ -71,7 +74,7 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
71
74
|
static createAsyncOptionsProvider(options) {
|
|
72
75
|
if (options.useFactory) {
|
|
73
76
|
return {
|
|
74
|
-
provide: SQB_MODULE_OPTIONS,
|
|
77
|
+
provide: sqb_constants_js_1.SQB_MODULE_OPTIONS,
|
|
75
78
|
useFactory: options.useFactory,
|
|
76
79
|
inject: options.inject || [],
|
|
77
80
|
};
|
|
@@ -79,7 +82,7 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
79
82
|
const useClass = options.useClass || options.useExisting;
|
|
80
83
|
if (useClass) {
|
|
81
84
|
return {
|
|
82
|
-
provide: SQB_MODULE_OPTIONS,
|
|
85
|
+
provide: sqb_constants_js_1.SQB_MODULE_OPTIONS,
|
|
83
86
|
useFactory: (optionsFactory) => optionsFactory.createSqbOptions(options.name),
|
|
84
87
|
inject: [useClass],
|
|
85
88
|
};
|
|
@@ -92,27 +95,27 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
92
95
|
// @ts-ignore
|
|
93
96
|
if (rxjs.lastValueFrom) {
|
|
94
97
|
// @ts-ignore
|
|
95
|
-
return await rxjs.lastValueFrom(defer(async () => {
|
|
96
|
-
const client = new SqbClient(options);
|
|
98
|
+
return await rxjs.lastValueFrom((0, rxjs_1.defer)(async () => {
|
|
99
|
+
const client = new connect_1.SqbClient(options);
|
|
97
100
|
await client.test();
|
|
98
101
|
return client;
|
|
99
|
-
}).pipe(handleRetry(connectionToken, options.retryAttempts, options.retryDelay, options.verboseRetryLog, options.toRetry)));
|
|
102
|
+
}).pipe((0, sqb_utils_js_1.handleRetry)(connectionToken, options.retryAttempts, options.retryDelay, options.verboseRetryLog, options.toRetry)));
|
|
100
103
|
}
|
|
101
104
|
// NestJS 7
|
|
102
105
|
// @ts-ignore
|
|
103
|
-
return await defer(async () => {
|
|
104
|
-
const client = new SqbClient(options);
|
|
106
|
+
return await (0, rxjs_1.defer)(async () => {
|
|
107
|
+
const client = new connect_1.SqbClient(options);
|
|
105
108
|
await client.test();
|
|
106
109
|
return client;
|
|
107
110
|
})
|
|
108
|
-
.pipe(handleRetry(connectionToken, options.retryAttempts, options.retryDelay, options.verboseRetryLog, options.toRetry))
|
|
111
|
+
.pipe((0, sqb_utils_js_1.handleRetry)(connectionToken, options.retryAttempts, options.retryDelay, options.verboseRetryLog, options.toRetry))
|
|
109
112
|
.toPromise();
|
|
110
113
|
}
|
|
111
114
|
};
|
|
112
|
-
SqbCoreModule =
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
exports.SqbCoreModule = SqbCoreModule;
|
|
116
|
+
exports.SqbCoreModule = SqbCoreModule = SqbCoreModule_1 = tslib_1.__decorate([
|
|
117
|
+
(0, common_1.Global)(),
|
|
118
|
+
(0, common_1.Module)({}),
|
|
119
|
+
tslib_1.__param(0, (0, common_1.Inject)(sqb_constants_js_1.SQB_MODULE_OPTIONS)),
|
|
120
|
+
tslib_1.__metadata("design:paramtypes", [Object, core_1.ModuleRef])
|
|
117
121
|
], SqbCoreModule);
|
|
118
|
-
export { SqbCoreModule };
|
package/esm/sqb.constants.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SQB_MODULE_ID = exports.SQB_MODULE_OPTIONS = void 0;
|
|
4
|
+
exports.SQB_MODULE_OPTIONS = Symbol('SQB_MODULE_OPTIONS');
|
|
5
|
+
exports.SQB_MODULE_ID = Symbol('SQB_MODULE_ID');
|
package/esm/sqb.decorators.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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/esm/sqb.interface.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/esm/sqb.module.js
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var SqbModule_1;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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");
|
|
5
8
|
let SqbModule = SqbModule_1 = class SqbModule {
|
|
6
9
|
static forRoot(options) {
|
|
7
10
|
return {
|
|
8
11
|
module: SqbModule_1,
|
|
9
|
-
imports: [SqbCoreModule.forRoot(options)],
|
|
12
|
+
imports: [sqb_core_module_js_1.SqbCoreModule.forRoot(options)],
|
|
10
13
|
};
|
|
11
14
|
}
|
|
12
15
|
static forRootAsync(options) {
|
|
13
16
|
return {
|
|
14
17
|
module: SqbModule_1,
|
|
15
|
-
imports: [SqbCoreModule.forRootAsync(options)],
|
|
18
|
+
imports: [sqb_core_module_js_1.SqbCoreModule.forRootAsync(options)],
|
|
16
19
|
};
|
|
17
20
|
}
|
|
18
21
|
};
|
|
19
|
-
SqbModule =
|
|
20
|
-
|
|
22
|
+
exports.SqbModule = SqbModule;
|
|
23
|
+
exports.SqbModule = SqbModule = SqbModule_1 = tslib_1.__decorate([
|
|
24
|
+
(0, common_1.Module)({})
|
|
21
25
|
], SqbModule);
|
|
22
|
-
export { SqbModule };
|
package/esm/sqb.utils.js
CHANGED
|
@@ -1,31 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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');
|
|
5
9
|
/**
|
|
6
10
|
* This function returns a Connection injection token for the given connection name.
|
|
7
11
|
* @param {string | symbol} [name=SQB_DEFAULT_CONNECTION] This optional parameter is either
|
|
8
12
|
* a SqbClient, or a ConnectionOptions or a string.
|
|
9
13
|
* @returns {string | symbol} The Connection injection token.
|
|
10
14
|
*/
|
|
11
|
-
|
|
15
|
+
function getSQBToken(name) {
|
|
12
16
|
if (!name)
|
|
13
|
-
return SqbClient;
|
|
17
|
+
return connect_1.SqbClient;
|
|
14
18
|
if (typeof name === 'symbol' || typeof name === 'function')
|
|
15
19
|
return name;
|
|
16
20
|
return `${name}_SqbConnection`;
|
|
17
21
|
}
|
|
18
|
-
|
|
19
|
-
return (source) => source.pipe(retryWhen(e => e.pipe(scan((errorCount, error) => {
|
|
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) => {
|
|
20
24
|
if (toRetry && !toRetry(error)) {
|
|
21
25
|
throw error;
|
|
22
26
|
}
|
|
23
|
-
const connectionInfo = !connectionName || connectionName === SqbClient ? 'default' : ` (${String(connectionName)})`;
|
|
27
|
+
const connectionInfo = !connectionName || connectionName === connect_1.SqbClient ? 'default' : ` (${String(connectionName)})`;
|
|
24
28
|
const verboseMessage = verboseRetryLog ? ` Message: ${error.message}.` : '';
|
|
25
29
|
logger.error(`Unable to connect to the database ${connectionInfo}.${verboseMessage} Retrying (${errorCount + 1})...`, error.stack);
|
|
26
30
|
if (errorCount + 1 >= retryAttempts) {
|
|
27
31
|
throw error;
|
|
28
32
|
}
|
|
29
33
|
return errorCount + 1;
|
|
30
|
-
}, 0), delay(retryDelay))));
|
|
34
|
+
}, 0), (0, operators_1.delay)(retryDelay))));
|
|
31
35
|
}
|
package/package.json
CHANGED
|
@@ -1,29 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqb/nestjs",
|
|
3
3
|
"description": "Nestjs module for data connection using SQB",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.15.0",
|
|
5
5
|
"author": "Panates",
|
|
6
|
-
"contributors": [
|
|
7
|
-
"Eray Hanoglu <e.hanoglu@panates.com>",
|
|
8
|
-
"Ilker Gurelli <i.gurelli@panates.com>"
|
|
9
|
-
],
|
|
10
6
|
"license": "Apache-2.0",
|
|
11
|
-
"repository": {
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "https://github.com/sqbjs/sqb.git",
|
|
14
|
-
"directory": "packages/nestjs"
|
|
15
|
-
},
|
|
16
|
-
"type": "module",
|
|
17
|
-
"module": "./esm/index.js",
|
|
18
|
-
"main": "./cjs/index.js",
|
|
19
|
-
"types": "./types/index.d.ts",
|
|
20
7
|
"scripts": {
|
|
21
8
|
"compile": "tsc",
|
|
22
9
|
"prebuild": "npm run lint && npm run clean",
|
|
23
10
|
"build": "npm run build:cjs && npm run build:esm",
|
|
24
11
|
"build:cjs": "tsc -b tsconfig-build-cjs.json",
|
|
25
12
|
"build:esm": "tsc -b tsconfig-build-esm.json",
|
|
26
|
-
"postbuild": "cp README.md package.json ../../LICENSE ../../build/nestjs
|
|
13
|
+
"postbuild": "cp README.md package.json ../../LICENSE ../../build/nestjs",
|
|
27
14
|
"lint": "eslint . --max-warnings=0",
|
|
28
15
|
"lint:fix": "eslint . --max-warnings=0 --fix",
|
|
29
16
|
"format": "prettier . --write --log-level=warn",
|
|
@@ -39,18 +26,37 @@
|
|
|
39
26
|
"@nestjs/core": "^10.3.10",
|
|
40
27
|
"@nestjs/platform-express": "^10.3.10",
|
|
41
28
|
"@nestjs/testing": "^10.3.10",
|
|
42
|
-
"postgrejs": "^2.
|
|
29
|
+
"postgrejs": "^2.16.0",
|
|
43
30
|
"rxjs": "^7.8.1",
|
|
44
31
|
"supertest": "^7.0.0"
|
|
45
32
|
},
|
|
46
33
|
"peerDependencies": {
|
|
47
34
|
"@nestjs/common": ">=7.4.0",
|
|
48
35
|
"@nestjs/core": ">=7.4.0",
|
|
49
|
-
"@sqb/builder": "^4.
|
|
50
|
-
"@sqb/connect": "^4.
|
|
36
|
+
"@sqb/builder": "^4.15.0",
|
|
37
|
+
"@sqb/connect": "^4.15.0",
|
|
51
38
|
"reflect-metadata": "^0.2.2",
|
|
52
39
|
"rxjs": ">=6.6.0"
|
|
53
40
|
},
|
|
41
|
+
"main": "./cjs/index.js",
|
|
42
|
+
"module": "./esm/index.js",
|
|
43
|
+
"types": "./types/index.d.ts",
|
|
44
|
+
"exports": {
|
|
45
|
+
".": {
|
|
46
|
+
"require": "./cjs/index.js",
|
|
47
|
+
"import": "./esm/index.js",
|
|
48
|
+
"types": "./types/index.d.ts"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"contributors": [
|
|
52
|
+
"Eray Hanoglu <e.hanoglu@panates.com>",
|
|
53
|
+
"Ilker Gurelli <i.gurelli@panates.com>"
|
|
54
|
+
],
|
|
55
|
+
"repository": {
|
|
56
|
+
"type": "git",
|
|
57
|
+
"url": "https://github.com/sqbjs/sqb.git",
|
|
58
|
+
"directory": "packages/nestjs"
|
|
59
|
+
},
|
|
54
60
|
"engines": {
|
|
55
61
|
"node": ">=16.0",
|
|
56
62
|
"npm": ">=7.0.0"
|
package/cjs/package.json
DELETED