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