@sqb/nestjs 4.0.1-beta.4 → 4.0.1-beta.48
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/dist/common/sqb.decorators.js +1 -1
- package/dist/common/sqb.utils.js +3 -3
- package/dist/sqb-core.module.js +75 -37
- package/dist/sqb.module.js +1 -1
- package/package.json +17 -18
|
@@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.InjectConnection = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const sqb_utils_1 = require("./sqb.utils");
|
|
6
|
-
const InjectConnection = (connection) => common_1.Inject(sqb_utils_1.getConnectionToken(connection));
|
|
6
|
+
const InjectConnection = (connection) => (0, common_1.Inject)((0, sqb_utils_1.getConnectionToken)(connection));
|
|
7
7
|
exports.InjectConnection = InjectConnection;
|
package/dist/common/sqb.utils.js
CHANGED
|
@@ -21,7 +21,7 @@ function getConnectionToken(client = sqb_constants_1.DEFAULT_CONNECTION_NAME) {
|
|
|
21
21
|
}
|
|
22
22
|
exports.getConnectionToken = getConnectionToken;
|
|
23
23
|
function handleRetry(retryAttempts = 9, retryDelay = 3000, connectionName = sqb_constants_1.DEFAULT_CONNECTION_NAME, verboseRetryLog = false, toRetry) {
|
|
24
|
-
return (source) => source.pipe(operators_1.retryWhen((e) => e.pipe(operators_1.scan((errorCount, error) => {
|
|
24
|
+
return (source) => source.pipe((0, operators_1.retryWhen)((e) => e.pipe((0, operators_1.scan)((errorCount, error) => {
|
|
25
25
|
if (toRetry && !toRetry(error)) {
|
|
26
26
|
throw error;
|
|
27
27
|
}
|
|
@@ -37,8 +37,8 @@ function handleRetry(retryAttempts = 9, retryDelay = 3000, connectionName = sqb_
|
|
|
37
37
|
throw error;
|
|
38
38
|
}
|
|
39
39
|
return errorCount + 1;
|
|
40
|
-
}, 0), operators_1.delay(retryDelay))));
|
|
40
|
+
}, 0), (0, operators_1.delay)(retryDelay))));
|
|
41
41
|
}
|
|
42
42
|
exports.handleRetry = handleRetry;
|
|
43
|
-
const generateString = () => uuid_1.v4();
|
|
43
|
+
const generateString = () => (0, uuid_1.v4)();
|
|
44
44
|
exports.generateString = generateString;
|
package/dist/sqb-core.module.js
CHANGED
|
@@ -1,10 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
2
14
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
15
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
16
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
17
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
18
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
19
|
};
|
|
20
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
+
if (mod && mod.__esModule) return mod;
|
|
22
|
+
var result = {};
|
|
23
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
+
__setModuleDefault(result, mod);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
8
27
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
28
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
29
|
};
|
|
@@ -17,6 +36,7 @@ exports.SqbCoreModule = void 0;
|
|
|
17
36
|
const common_1 = require("@nestjs/common");
|
|
18
37
|
const core_1 = require("@nestjs/core");
|
|
19
38
|
const rxjs_1 = require("rxjs");
|
|
39
|
+
const rxjs = __importStar(require("rxjs"));
|
|
20
40
|
const connect_1 = require("@sqb/connect");
|
|
21
41
|
const sqb_utils_1 = require("./common/sqb.utils");
|
|
22
42
|
const sqb_constants_1 = require("./sqb.constants");
|
|
@@ -26,28 +46,31 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
26
46
|
this.moduleRef = moduleRef;
|
|
27
47
|
}
|
|
28
48
|
static forRoot(options = {}) {
|
|
29
|
-
const
|
|
49
|
+
const optionsProvider = {
|
|
30
50
|
provide: sqb_constants_1.SQB_MODULE_OPTIONS,
|
|
31
51
|
useValue: options,
|
|
32
52
|
};
|
|
33
53
|
const connectionProvider = {
|
|
34
|
-
provide: sqb_utils_1.getConnectionToken(options),
|
|
35
|
-
useFactory:
|
|
54
|
+
provide: (0, sqb_utils_1.getConnectionToken)(options),
|
|
55
|
+
useFactory: () => this.createConnectionFactory(options),
|
|
36
56
|
};
|
|
37
57
|
return {
|
|
38
58
|
module: SqbCoreModule_1,
|
|
39
|
-
providers: [connectionProvider,
|
|
59
|
+
providers: [connectionProvider, optionsProvider],
|
|
40
60
|
exports: [connectionProvider],
|
|
41
61
|
};
|
|
42
62
|
}
|
|
43
63
|
static forRootAsync(options) {
|
|
44
64
|
const connectionProvider = {
|
|
45
|
-
provide: sqb_utils_1.getConnectionToken(options),
|
|
65
|
+
provide: (0, sqb_utils_1.getConnectionToken)(options),
|
|
66
|
+
inject: [sqb_constants_1.SQB_MODULE_OPTIONS],
|
|
46
67
|
useFactory: async (sqbOptions) => {
|
|
47
68
|
const name = options.name || sqbOptions.name;
|
|
48
|
-
return await this.createConnectionFactory(
|
|
49
|
-
|
|
50
|
-
|
|
69
|
+
return await this.createConnectionFactory({
|
|
70
|
+
...sqbOptions,
|
|
71
|
+
name
|
|
72
|
+
});
|
|
73
|
+
}
|
|
51
74
|
};
|
|
52
75
|
const asyncProviders = this.createAsyncProviders(options);
|
|
53
76
|
return {
|
|
@@ -58,28 +81,29 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
58
81
|
connectionProvider,
|
|
59
82
|
{
|
|
60
83
|
provide: sqb_constants_1.SQB_MODULE_ID,
|
|
61
|
-
useValue: sqb_utils_1.generateString(),
|
|
84
|
+
useValue: (0, sqb_utils_1.generateString)(),
|
|
62
85
|
},
|
|
63
86
|
],
|
|
64
87
|
exports: [connectionProvider],
|
|
65
88
|
};
|
|
66
89
|
}
|
|
67
90
|
async onApplicationShutdown() {
|
|
68
|
-
const client = this.moduleRef.get(sqb_utils_1.getConnectionToken(this.options));
|
|
91
|
+
const client = this.moduleRef.get((0, sqb_utils_1.getConnectionToken)(this.options));
|
|
69
92
|
if (client)
|
|
70
93
|
await client.close(this.options.shutdownWaitMs);
|
|
71
94
|
}
|
|
72
95
|
static createAsyncProviders(options) {
|
|
73
96
|
if (options.useExisting || options.useFactory)
|
|
74
97
|
return [this.createAsyncOptionsProvider(options)];
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
98
|
+
if (options.useClass)
|
|
99
|
+
return [
|
|
100
|
+
this.createAsyncOptionsProvider(options),
|
|
101
|
+
{
|
|
102
|
+
provide: options.useClass,
|
|
103
|
+
useClass: options.useClass
|
|
104
|
+
}
|
|
105
|
+
];
|
|
106
|
+
throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting');
|
|
83
107
|
}
|
|
84
108
|
static createAsyncOptionsProvider(options) {
|
|
85
109
|
if (options.useFactory) {
|
|
@@ -89,31 +113,45 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
89
113
|
inject: options.inject || [],
|
|
90
114
|
};
|
|
91
115
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
116
|
+
const useClass = options.useClass || options.useExisting;
|
|
117
|
+
if (useClass) {
|
|
118
|
+
return {
|
|
119
|
+
provide: sqb_constants_1.SQB_MODULE_OPTIONS,
|
|
120
|
+
useFactory: async (optionsFactory) => await optionsFactory.createSqbOptions(options.name),
|
|
121
|
+
inject: [useClass],
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting');
|
|
101
125
|
}
|
|
102
126
|
static async createConnectionFactory(options) {
|
|
103
127
|
const connectionToken = options.name || sqb_constants_1.DEFAULT_CONNECTION_NAME;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
128
|
+
// NestJS 8
|
|
129
|
+
// @ts-ignore
|
|
130
|
+
if (rxjs.lastValueFrom) {
|
|
131
|
+
// @ts-ignore
|
|
132
|
+
return await rxjs.lastValueFrom((0, rxjs_1.defer)(async () => {
|
|
133
|
+
const client = new connect_1.SqbClient(options);
|
|
134
|
+
await client.test();
|
|
135
|
+
return client;
|
|
136
|
+
}).pipe((0, sqb_utils_1.handleRetry)(options.retryAttempts, options.retryDelay, connectionToken, options.verboseRetryLog, options.toRetry)));
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
// NestJS 7
|
|
140
|
+
// @ts-ignore
|
|
141
|
+
return await (0, rxjs_1.defer)(async () => {
|
|
142
|
+
const client = new connect_1.SqbClient(options);
|
|
143
|
+
await client.test();
|
|
144
|
+
return client;
|
|
145
|
+
})
|
|
146
|
+
.pipe((0, sqb_utils_1.handleRetry)(options.retryAttempts, options.retryDelay, connectionToken, options.verboseRetryLog, options.toRetry))
|
|
147
|
+
.toPromise();
|
|
148
|
+
}
|
|
111
149
|
}
|
|
112
150
|
};
|
|
113
151
|
SqbCoreModule = SqbCoreModule_1 = __decorate([
|
|
114
|
-
common_1.Global(),
|
|
115
|
-
common_1.Module({}),
|
|
116
|
-
__param(0, common_1.Inject(sqb_constants_1.SQB_MODULE_OPTIONS)),
|
|
152
|
+
(0, common_1.Global)(),
|
|
153
|
+
(0, common_1.Module)({}),
|
|
154
|
+
__param(0, (0, common_1.Inject)(sqb_constants_1.SQB_MODULE_OPTIONS)),
|
|
117
155
|
__metadata("design:paramtypes", [Object, core_1.ModuleRef])
|
|
118
156
|
], SqbCoreModule);
|
|
119
157
|
exports.SqbCoreModule = SqbCoreModule;
|
package/dist/sqb.module.js
CHANGED
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.0.1-beta.
|
|
4
|
+
"version": "4.0.1-beta.48",
|
|
5
5
|
"author": "Panates Ltd.",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Eray Hanoglu <e.hanoglu@panates.com>"
|
|
@@ -20,31 +20,30 @@
|
|
|
20
20
|
"nest",
|
|
21
21
|
"sql"
|
|
22
22
|
],
|
|
23
|
-
"dependencies": {
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"reflect-metadata": "^0.1.13"
|
|
25
|
+
},
|
|
24
26
|
"devDependencies": {
|
|
25
|
-
"@nestjs/common": "^
|
|
26
|
-
"@nestjs/core": "^
|
|
27
|
-
"@nestjs/
|
|
28
|
-
"@nestjs/
|
|
29
|
-
"
|
|
30
|
-
"postgresql-client": "^1.13.2",
|
|
27
|
+
"@nestjs/common": "^8.0.0",
|
|
28
|
+
"@nestjs/core": "^8.0.0",
|
|
29
|
+
"@nestjs/testing": "^8.0.0",
|
|
30
|
+
"@nestjs/platform-express": "^8.0.0",
|
|
31
|
+
"postgresql-client": "^1.16.7",
|
|
31
32
|
"reflect-metadata": "^0.1.13",
|
|
32
|
-
"rxjs": "^
|
|
33
|
-
"rxjs-compat": "^6.6.3",
|
|
33
|
+
"rxjs": "^7.2.0",
|
|
34
34
|
"supertest": "^6.1.3"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"@sqb/connect": "^4.0.1-beta.4"
|
|
37
|
+
"@sqb/connect": "^4.0.1-beta.48",
|
|
38
|
+
"@sqb/builder": "^4.0.1-beta.48",
|
|
39
|
+
"@nestjs/common": "^7.6.x || >=8.0.0",
|
|
40
|
+
"@nestjs/core": "^7.6.x || >=8.0.0",
|
|
41
|
+
"rxjs": "^6.6.x || ^7.0.0"
|
|
43
42
|
},
|
|
44
43
|
"main": "dist/index.js",
|
|
45
44
|
"types": "dist/index.d.ts",
|
|
46
45
|
"engines": {
|
|
47
|
-
"node": ">=
|
|
46
|
+
"node": ">= 14.0"
|
|
48
47
|
},
|
|
49
48
|
"directories": {
|
|
50
49
|
"lib": "dist",
|
|
@@ -59,7 +58,7 @@
|
|
|
59
58
|
"temp-dir": "./coverage/.nyc_output"
|
|
60
59
|
},
|
|
61
60
|
"scripts": {
|
|
62
|
-
"test": "ts-
|
|
61
|
+
"test": "TS_NODE_PROJECT='./test/tsconfig.json' mocha -r ts-node/register -r tsconfig-paths/register --reporter spec test/**/*.spec.ts",
|
|
63
62
|
"cover": "nyc --reporter=cobertura --reporter html --reporter text npm run test",
|
|
64
63
|
"build": "tsc -b tsconfig-build.json",
|
|
65
64
|
"compile": "tsc -b tsconfig.json",
|