@sqb/nestjs 4.2.1 → 4.5.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/README.md +67 -0
- package/{dist → cjs}/index.js +4 -4
- package/cjs/package.json +3 -0
- package/{dist → cjs}/sqb-core.module.js +15 -13
- package/{dist → cjs}/sqb.constants.js +0 -0
- package/{dist → cjs}/sqb.decorators.js +2 -2
- package/{dist → cjs}/sqb.interface.js +0 -0
- package/{dist → cjs}/sqb.module.js +3 -3
- package/{dist → cjs}/sqb.utils.js +0 -0
- package/esm/index.d.ts +5 -0
- package/esm/index.js +5 -0
- package/{dist → esm}/sqb-core.module.d.ts +1 -1
- package/esm/sqb-core.module.js +127 -0
- package/{dist → esm}/sqb.constants.d.ts +0 -0
- package/esm/sqb.constants.js +2 -0
- package/{dist → esm}/sqb.decorators.d.ts +0 -0
- package/esm/sqb.decorators.js +3 -0
- package/{dist → esm}/sqb.interface.d.ts +0 -0
- package/esm/sqb.interface.js +1 -0
- package/{dist → esm}/sqb.module.d.ts +1 -1
- package/esm/sqb.module.js +22 -0
- package/{dist → esm}/sqb.utils.d.ts +0 -0
- package/esm/sqb.utils.js +35 -0
- package/package.json +68 -57
- package/dist/index.d.ts +0 -5
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
|
|
2
|
+
<p style="text-align:center">
|
|
3
|
+
<img src="https://user-images.githubusercontent.com/3836517/32965280-1a2b63ce-cbe7-11e7-8ee1-ba47313503c5.png" width="500px" alt="SQB Logo"/>
|
|
4
|
+
</p>
|
|
5
|
+
|
|
6
|
+
<br>
|
|
7
|
+
|
|
8
|
+
[![NPM Version][npm-image]][npm-url]
|
|
9
|
+
[![NPM Downloads][downloads-image]][downloads-url]
|
|
10
|
+
[![Build Status][travis-image]][travis-url]
|
|
11
|
+
[![Test Coverage][coveralls-image]][coveralls-url]
|
|
12
|
+
[![Dependencies][dependencies-image]][dependencies-url]
|
|
13
|
+
[![DevDependencies][devdependencies-image]][devdependencies-url]
|
|
14
|
+
[![Package Quality][quality-image]][quality-url]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## About SQB
|
|
18
|
+
|
|
19
|
+
SQB is an extensible, multi-dialect SQL query builder and Database connection wrapper for NodeJS.
|
|
20
|
+
|
|
21
|
+
## Main goals
|
|
22
|
+
|
|
23
|
+
- Single code base for any sql based database
|
|
24
|
+
- Powerful and simplified query coding scheme
|
|
25
|
+
- Fast applications with low memory requirements
|
|
26
|
+
- Let applications work with large data tables efficiently
|
|
27
|
+
- Support latest JavaScript language standards
|
|
28
|
+
- Lightweight and extensible framework.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
You can report bugs and discuss features on the [GitHub issues](https://github.com/sqbjs/sqb/issues) page
|
|
32
|
+
|
|
33
|
+
Thanks to all of the great [contributions](https://github.com/sqbjs/sqb/graphs/contributors) to the project.
|
|
34
|
+
|
|
35
|
+
You may want to check detailed [DOCUMENTATION](https://sqbjs.github.io/sqb/)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
$ npm install @sqb/nestjs --save
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Node Compatibility
|
|
45
|
+
|
|
46
|
+
- node >= 16.x
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### License
|
|
50
|
+
SQB is available under [MIT](LICENSE) license.
|
|
51
|
+
|
|
52
|
+
[npm-image]: https://img.shields.io/npm/v/@sqb/nestjs.svg
|
|
53
|
+
[npm-url]: https://npmjs.org/package/@sqb/nestjs
|
|
54
|
+
[travis-image]: https://img.shields.io/travis/sqbjs/@sqb/nestjs/master.svg
|
|
55
|
+
[travis-url]: https://travis-ci.org/sqbjs/@sqb/nestjs
|
|
56
|
+
[coveralls-image]: https://img.shields.io/coveralls/sqbjs/@sqb/nestjs/master.svg
|
|
57
|
+
[coveralls-url]: https://coveralls.io/r/sqbjs/@sqb/nestjs
|
|
58
|
+
[downloads-image]: https://img.shields.io/npm/dm/@sqb/nestjs.svg
|
|
59
|
+
[downloads-url]: https://npmjs.org/package/@sqb/nestjs
|
|
60
|
+
[gitter-image]: https://badges.gitter.im/sqbjs/@sqb/nestjs.svg
|
|
61
|
+
[gitter-url]: https://gitter.im/sqbjs/@sqb/nestjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
|
|
62
|
+
[dependencies-image]: https://david-dm.org/sqbjs/@sqb/nestjs/status.svg
|
|
63
|
+
[dependencies-url]:https://david-dm.org/sqbjs/@sqb/nestjs
|
|
64
|
+
[devdependencies-image]: https://david-dm.org/sqbjs/@sqb/nestjs/dev-status.svg
|
|
65
|
+
[devdependencies-url]:https://david-dm.org/sqbjs/@sqb/nestjs?type=dev
|
|
66
|
+
[quality-image]: http://npm.packagequality.com/shield/@sqb/nestjs.png
|
|
67
|
+
[quality-url]: http://packagequality.com/#?package=@sqb/nestjs
|
package/{dist → cjs}/index.js
RENAMED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SqbClient = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
tslib_1.__exportStar(require("./sqb.decorators"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./sqb.interface"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./sqb.module"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./sqb.utils"), exports);
|
|
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
9
|
var connect_1 = require("@sqb/connect");
|
|
10
10
|
Object.defineProperty(exports, "SqbClient", { enumerable: true, get: function () { return connect_1.SqbClient; } });
|
package/cjs/package.json
ADDED
|
@@ -9,20 +9,22 @@ const rxjs = tslib_1.__importStar(require("rxjs"));
|
|
|
9
9
|
const common_1 = require("@nestjs/common");
|
|
10
10
|
const core_1 = require("@nestjs/core");
|
|
11
11
|
const connect_1 = require("@sqb/connect");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
12
|
+
const sqb_constants_js_1 = require("./sqb.constants.js");
|
|
13
|
+
const sqb_utils_js_1 = require("./sqb.utils.js");
|
|
14
14
|
let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
15
|
+
options;
|
|
16
|
+
moduleRef;
|
|
15
17
|
constructor(options, moduleRef) {
|
|
16
18
|
this.options = options;
|
|
17
19
|
this.moduleRef = moduleRef;
|
|
18
20
|
}
|
|
19
21
|
static forRoot(options = {}) {
|
|
20
22
|
const optionsProvider = {
|
|
21
|
-
provide:
|
|
23
|
+
provide: sqb_constants_js_1.SQB_MODULE_OPTIONS,
|
|
22
24
|
useValue: options,
|
|
23
25
|
};
|
|
24
26
|
const connectionProvider = {
|
|
25
|
-
provide: (0,
|
|
27
|
+
provide: (0, sqb_utils_js_1.getSQBToken)(options.name),
|
|
26
28
|
useFactory: () => this.createConnection(options),
|
|
27
29
|
};
|
|
28
30
|
return {
|
|
@@ -33,8 +35,8 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
33
35
|
}
|
|
34
36
|
static forRootAsync(options) {
|
|
35
37
|
const connectionProvider = {
|
|
36
|
-
provide: (0,
|
|
37
|
-
inject: [
|
|
38
|
+
provide: (0, sqb_utils_js_1.getSQBToken)(options.name),
|
|
39
|
+
inject: [sqb_constants_js_1.SQB_MODULE_OPTIONS],
|
|
38
40
|
useFactory: async (sqbOptions) => {
|
|
39
41
|
const name = options.name || sqbOptions.name;
|
|
40
42
|
return this.createConnection({
|
|
@@ -51,7 +53,7 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
51
53
|
...asyncProviders,
|
|
52
54
|
connectionProvider,
|
|
53
55
|
{
|
|
54
|
-
provide:
|
|
56
|
+
provide: sqb_constants_js_1.SQB_MODULE_ID,
|
|
55
57
|
useValue: crypto.randomUUID(),
|
|
56
58
|
},
|
|
57
59
|
],
|
|
@@ -59,7 +61,7 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
59
61
|
};
|
|
60
62
|
}
|
|
61
63
|
async onApplicationShutdown() {
|
|
62
|
-
const client = this.moduleRef.get((0,
|
|
64
|
+
const client = this.moduleRef.get((0, sqb_utils_js_1.getSQBToken)(this.options.name));
|
|
63
65
|
if (client)
|
|
64
66
|
await client.close(this.options.shutdownWaitMs);
|
|
65
67
|
}
|
|
@@ -79,7 +81,7 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
79
81
|
static createAsyncOptionsProvider(options) {
|
|
80
82
|
if (options.useFactory) {
|
|
81
83
|
return {
|
|
82
|
-
provide:
|
|
84
|
+
provide: sqb_constants_js_1.SQB_MODULE_OPTIONS,
|
|
83
85
|
useFactory: options.useFactory,
|
|
84
86
|
inject: options.inject || [],
|
|
85
87
|
};
|
|
@@ -87,7 +89,7 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
87
89
|
const useClass = options.useClass || options.useExisting;
|
|
88
90
|
if (useClass) {
|
|
89
91
|
return {
|
|
90
|
-
provide:
|
|
92
|
+
provide: sqb_constants_js_1.SQB_MODULE_OPTIONS,
|
|
91
93
|
useFactory: (optionsFactory) => optionsFactory.createSqbOptions(options.name),
|
|
92
94
|
inject: [useClass],
|
|
93
95
|
};
|
|
@@ -104,7 +106,7 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
104
106
|
const client = new connect_1.SqbClient(options);
|
|
105
107
|
await client.test();
|
|
106
108
|
return client;
|
|
107
|
-
}).pipe((0,
|
|
109
|
+
}).pipe((0, sqb_utils_js_1.handleRetry)(connectionToken, options.retryAttempts, options.retryDelay, options.verboseRetryLog, options.toRetry)));
|
|
108
110
|
}
|
|
109
111
|
else {
|
|
110
112
|
// NestJS 7
|
|
@@ -114,7 +116,7 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
114
116
|
await client.test();
|
|
115
117
|
return client;
|
|
116
118
|
})
|
|
117
|
-
.pipe((0,
|
|
119
|
+
.pipe((0, sqb_utils_js_1.handleRetry)(connectionToken, options.retryAttempts, options.retryDelay, options.verboseRetryLog, options.toRetry))
|
|
118
120
|
.toPromise();
|
|
119
121
|
}
|
|
120
122
|
}
|
|
@@ -122,7 +124,7 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
122
124
|
SqbCoreModule = SqbCoreModule_1 = tslib_1.__decorate([
|
|
123
125
|
(0, common_1.Global)(),
|
|
124
126
|
(0, common_1.Module)({}),
|
|
125
|
-
tslib_1.__param(0, (0, common_1.Inject)(
|
|
127
|
+
tslib_1.__param(0, (0, common_1.Inject)(sqb_constants_js_1.SQB_MODULE_OPTIONS)),
|
|
126
128
|
tslib_1.__metadata("design:paramtypes", [Object, core_1.ModuleRef])
|
|
127
129
|
], SqbCoreModule);
|
|
128
130
|
exports.SqbCoreModule = SqbCoreModule;
|
|
File without changes
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InjectSQB = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
|
-
const
|
|
6
|
-
const InjectSQB = (name) => (0, common_1.Inject)((0,
|
|
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
7
|
exports.InjectSQB = InjectSQB;
|
|
File without changes
|
|
@@ -4,18 +4,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.SqbModule = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const common_1 = require("@nestjs/common");
|
|
7
|
-
const
|
|
7
|
+
const sqb_core_module_js_1 = require("./sqb-core.module.js");
|
|
8
8
|
let SqbModule = SqbModule_1 = class SqbModule {
|
|
9
9
|
static forRoot(options) {
|
|
10
10
|
return {
|
|
11
11
|
module: SqbModule_1,
|
|
12
|
-
imports: [
|
|
12
|
+
imports: [sqb_core_module_js_1.SqbCoreModule.forRoot(options)]
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
static forRootAsync(options) {
|
|
16
16
|
return {
|
|
17
17
|
module: SqbModule_1,
|
|
18
|
-
imports: [
|
|
18
|
+
imports: [sqb_core_module_js_1.SqbCoreModule.forRootAsync(options)]
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
};
|
|
File without changes
|
package/esm/index.d.ts
ADDED
package/esm/index.js
ADDED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DynamicModule, OnApplicationShutdown } from '@nestjs/common';
|
|
2
2
|
import { ModuleRef } from '@nestjs/core';
|
|
3
|
-
import { SqbModuleAsyncOptions, SqbModuleOptions } from './sqb.interface';
|
|
3
|
+
import { SqbModuleAsyncOptions, SqbModuleOptions } from './sqb.interface.js';
|
|
4
4
|
export declare class SqbCoreModule implements OnApplicationShutdown {
|
|
5
5
|
private readonly options;
|
|
6
6
|
private readonly moduleRef;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
var SqbCoreModule_1;
|
|
2
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
3
|
+
import * as crypto from 'crypto';
|
|
4
|
+
import { defer } from 'rxjs';
|
|
5
|
+
import * as rxjs from 'rxjs';
|
|
6
|
+
import { Global, Inject, Module } from '@nestjs/common';
|
|
7
|
+
import { ModuleRef } from '@nestjs/core';
|
|
8
|
+
import { SqbClient } from '@sqb/connect';
|
|
9
|
+
import { SQB_MODULE_ID, SQB_MODULE_OPTIONS, } from './sqb.constants.js';
|
|
10
|
+
import { getSQBToken, handleRetry, } from './sqb.utils.js';
|
|
11
|
+
let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
12
|
+
options;
|
|
13
|
+
moduleRef;
|
|
14
|
+
constructor(options, moduleRef) {
|
|
15
|
+
this.options = options;
|
|
16
|
+
this.moduleRef = moduleRef;
|
|
17
|
+
}
|
|
18
|
+
static forRoot(options = {}) {
|
|
19
|
+
const optionsProvider = {
|
|
20
|
+
provide: SQB_MODULE_OPTIONS,
|
|
21
|
+
useValue: options,
|
|
22
|
+
};
|
|
23
|
+
const connectionProvider = {
|
|
24
|
+
provide: getSQBToken(options.name),
|
|
25
|
+
useFactory: () => this.createConnection(options),
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
module: SqbCoreModule_1,
|
|
29
|
+
providers: [connectionProvider, optionsProvider],
|
|
30
|
+
exports: [connectionProvider],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
static forRootAsync(options) {
|
|
34
|
+
const connectionProvider = {
|
|
35
|
+
provide: getSQBToken(options.name),
|
|
36
|
+
inject: [SQB_MODULE_OPTIONS],
|
|
37
|
+
useFactory: async (sqbOptions) => {
|
|
38
|
+
const name = options.name || sqbOptions.name;
|
|
39
|
+
return this.createConnection({
|
|
40
|
+
...sqbOptions,
|
|
41
|
+
name
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const asyncProviders = this.createAsyncProviders(options);
|
|
46
|
+
return {
|
|
47
|
+
module: SqbCoreModule_1,
|
|
48
|
+
imports: options.imports,
|
|
49
|
+
providers: [
|
|
50
|
+
...asyncProviders,
|
|
51
|
+
connectionProvider,
|
|
52
|
+
{
|
|
53
|
+
provide: SQB_MODULE_ID,
|
|
54
|
+
useValue: crypto.randomUUID(),
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
exports: [connectionProvider],
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async onApplicationShutdown() {
|
|
61
|
+
const client = this.moduleRef.get(getSQBToken(this.options.name));
|
|
62
|
+
if (client)
|
|
63
|
+
await client.close(this.options.shutdownWaitMs);
|
|
64
|
+
}
|
|
65
|
+
static createAsyncProviders(options) {
|
|
66
|
+
if (options.useExisting || options.useFactory)
|
|
67
|
+
return [this.createAsyncOptionsProvider(options)];
|
|
68
|
+
if (options.useClass)
|
|
69
|
+
return [
|
|
70
|
+
this.createAsyncOptionsProvider(options),
|
|
71
|
+
{
|
|
72
|
+
provide: options.useClass,
|
|
73
|
+
useClass: options.useClass
|
|
74
|
+
}
|
|
75
|
+
];
|
|
76
|
+
throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting');
|
|
77
|
+
}
|
|
78
|
+
static createAsyncOptionsProvider(options) {
|
|
79
|
+
if (options.useFactory) {
|
|
80
|
+
return {
|
|
81
|
+
provide: SQB_MODULE_OPTIONS,
|
|
82
|
+
useFactory: options.useFactory,
|
|
83
|
+
inject: options.inject || [],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const useClass = options.useClass || options.useExisting;
|
|
87
|
+
if (useClass) {
|
|
88
|
+
return {
|
|
89
|
+
provide: SQB_MODULE_OPTIONS,
|
|
90
|
+
useFactory: (optionsFactory) => optionsFactory.createSqbOptions(options.name),
|
|
91
|
+
inject: [useClass],
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting');
|
|
95
|
+
}
|
|
96
|
+
static async createConnection(options) {
|
|
97
|
+
const connectionToken = options.name;
|
|
98
|
+
// NestJS 8
|
|
99
|
+
// @ts-ignore
|
|
100
|
+
if (rxjs.lastValueFrom) {
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
return await rxjs.lastValueFrom(defer(async () => {
|
|
103
|
+
const client = new SqbClient(options);
|
|
104
|
+
await client.test();
|
|
105
|
+
return client;
|
|
106
|
+
}).pipe(handleRetry(connectionToken, options.retryAttempts, options.retryDelay, options.verboseRetryLog, options.toRetry)));
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// NestJS 7
|
|
110
|
+
// @ts-ignore
|
|
111
|
+
return await defer(async () => {
|
|
112
|
+
const client = new SqbClient(options);
|
|
113
|
+
await client.test();
|
|
114
|
+
return client;
|
|
115
|
+
})
|
|
116
|
+
.pipe(handleRetry(connectionToken, options.retryAttempts, options.retryDelay, options.verboseRetryLog, options.toRetry))
|
|
117
|
+
.toPromise();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
SqbCoreModule = SqbCoreModule_1 = __decorate([
|
|
122
|
+
Global(),
|
|
123
|
+
Module({}),
|
|
124
|
+
__param(0, Inject(SQB_MODULE_OPTIONS)),
|
|
125
|
+
__metadata("design:paramtypes", [Object, ModuleRef])
|
|
126
|
+
], SqbCoreModule);
|
|
127
|
+
export { SqbCoreModule };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DynamicModule } from '@nestjs/common';
|
|
2
|
-
import { SqbModuleAsyncOptions, SqbModuleOptions } from './sqb.interface';
|
|
2
|
+
import { SqbModuleAsyncOptions, SqbModuleOptions } from './sqb.interface.js';
|
|
3
3
|
export declare class SqbModule {
|
|
4
4
|
static forRoot(options?: SqbModuleOptions): DynamicModule;
|
|
5
5
|
static forRootAsync(options: SqbModuleAsyncOptions): DynamicModule;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var SqbModule_1;
|
|
2
|
+
import { __decorate } from "tslib";
|
|
3
|
+
import { Module } from '@nestjs/common';
|
|
4
|
+
import { SqbCoreModule } from './sqb-core.module.js';
|
|
5
|
+
let SqbModule = SqbModule_1 = class SqbModule {
|
|
6
|
+
static forRoot(options) {
|
|
7
|
+
return {
|
|
8
|
+
module: SqbModule_1,
|
|
9
|
+
imports: [SqbCoreModule.forRoot(options)]
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
static forRootAsync(options) {
|
|
13
|
+
return {
|
|
14
|
+
module: SqbModule_1,
|
|
15
|
+
imports: [SqbCoreModule.forRootAsync(options)]
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
SqbModule = SqbModule_1 = __decorate([
|
|
20
|
+
Module({})
|
|
21
|
+
], SqbModule);
|
|
22
|
+
export { SqbModule };
|
|
File without changes
|
package/esm/sqb.utils.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { delay, retryWhen, scan } from 'rxjs/operators';
|
|
2
|
+
import { Logger } from '@nestjs/common';
|
|
3
|
+
import { SqbClient } from '@sqb/connect';
|
|
4
|
+
const logger = new Logger('SqbModule');
|
|
5
|
+
/**
|
|
6
|
+
* This function returns a Connection injection token for the given connection name.
|
|
7
|
+
* @param {string | symbol} [name=SQB_DEFAULT_CONNECTION] This optional parameter is either
|
|
8
|
+
* a SqbClient, or a ConnectionOptions or a string.
|
|
9
|
+
* @returns {string | symbol} The Connection injection token.
|
|
10
|
+
*/
|
|
11
|
+
export function getSQBToken(name) {
|
|
12
|
+
if (!name)
|
|
13
|
+
return SqbClient;
|
|
14
|
+
if (typeof name === 'symbol' || typeof name === 'function')
|
|
15
|
+
return name;
|
|
16
|
+
return `${name}_SqbConnection`;
|
|
17
|
+
}
|
|
18
|
+
export function handleRetry(connectionName, retryAttempts = 9, retryDelay = 3000, verboseRetryLog = false, toRetry) {
|
|
19
|
+
return (source) => source.pipe(retryWhen((e) => e.pipe(scan((errorCount, error) => {
|
|
20
|
+
if (toRetry && !toRetry(error)) {
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
const connectionInfo = !connectionName || connectionName === SqbClient
|
|
24
|
+
? 'default'
|
|
25
|
+
: ` (${String(connectionName)})`;
|
|
26
|
+
const verboseMessage = verboseRetryLog
|
|
27
|
+
? ` Message: ${error.message}.`
|
|
28
|
+
: '';
|
|
29
|
+
logger.error(`Unable to connect to the database ${connectionInfo}.${verboseMessage} Retrying (${errorCount + 1})...`, error.stack);
|
|
30
|
+
if (errorCount + 1 >= retryAttempts) {
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
return errorCount + 1;
|
|
34
|
+
}, 0), delay(retryDelay))));
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,67 +1,78 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "@sqb/nestjs",
|
|
3
|
-
"description": "Nestjs module for data connection using SQB",
|
|
4
|
-
"version": "4.
|
|
5
|
-
"author": "Panates",
|
|
6
|
-
"contributors": [
|
|
7
|
-
"Eray Hanoglu <e.hanoglu@panates.com>"
|
|
2
|
+
"name" : "@sqb/nestjs",
|
|
3
|
+
"description" : "Nestjs module for data connection using SQB",
|
|
4
|
+
"version" : "4.5.0",
|
|
5
|
+
"author" : "Panates",
|
|
6
|
+
"contributors" : [
|
|
7
|
+
"Eray Hanoglu <e.hanoglu@panates.com>",
|
|
8
|
+
"Ilker Gurelli <i.gurelli@panates.com>"
|
|
8
9
|
],
|
|
9
|
-
"license": "Apache-2.0",
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "https://github.com/sqbjs/sqb.git",
|
|
13
|
-
"directory": "packages/nestjs"
|
|
10
|
+
"license" : "Apache-2.0",
|
|
11
|
+
"repository" : {
|
|
12
|
+
"type" : "git",
|
|
13
|
+
"url" : "https://github.com/sqbjs/sqb.git",
|
|
14
|
+
"directory" : "packages/nestjs"
|
|
14
15
|
},
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
16
|
+
"scripts" : {
|
|
17
|
+
"compile" : "tsc",
|
|
18
|
+
"prebuild" : "npm run lint && npm run clean",
|
|
19
|
+
"build" : "npm run build:cjs && npm run build:esm",
|
|
20
|
+
"build:cjs" : "tsc -b tsconfig-build-cjs.json",
|
|
21
|
+
"build:esm" : "tsc -b tsconfig-build-esm.json",
|
|
22
|
+
"postbuild" : "cp README.md package.json ../../LICENSE ../../build/nestjs && cp ../../package.cjs.json ../../build/nestjs/cjs/package.json",
|
|
23
|
+
"lint" : "eslint .",
|
|
24
|
+
"test" : "jest",
|
|
25
|
+
"cover" : "jest --collect-coverage",
|
|
26
|
+
"clean" : "npm run clean:src | npm run clean:dist | npm run clean:cover",
|
|
27
|
+
"clean:src" : "ts-cleanup -s src --all",
|
|
28
|
+
"clean:dist" : "rimraf ../../build/postgres",
|
|
29
|
+
"clean:cover" : "rimraf ../../coverage/postgres"
|
|
26
30
|
},
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"@nestjs/core": "^9.0.8",
|
|
30
|
-
"@nestjs/platform-express": "^9.0.8",
|
|
31
|
-
"@nestjs/testing": "^9.0.8",
|
|
32
|
-
"postgresql-client": "^2.1.4",
|
|
33
|
-
"rxjs": "^7.5.6",
|
|
34
|
-
"supertest": "^6.2.4"
|
|
31
|
+
"dependencies" : {
|
|
32
|
+
"reflect-metadata" : "^0.1.13"
|
|
35
33
|
},
|
|
36
|
-
"
|
|
37
|
-
"@nestjs/common": "
|
|
38
|
-
"@nestjs/core": "
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"
|
|
34
|
+
"devDependencies" : {
|
|
35
|
+
"@nestjs/common" : "^9.0.11",
|
|
36
|
+
"@nestjs/core" : "^9.0.11",
|
|
37
|
+
"@nestjs/platform-express" : "^9.0.11",
|
|
38
|
+
"@nestjs/testing" : "^9.0.11",
|
|
39
|
+
"postgresql-client" : "^2.1.5",
|
|
40
|
+
"rxjs" : "^7.5.6",
|
|
41
|
+
"supertest" : "^6.2.4"
|
|
42
42
|
},
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
43
|
+
"peerDependencies" : {
|
|
44
|
+
"@nestjs/common" : ">=7.4.0",
|
|
45
|
+
"@nestjs/core" : ">=7.4.0",
|
|
46
|
+
"@sqb/builder" : "^4.5.0",
|
|
47
|
+
"@sqb/connect" : "^4.5.0",
|
|
48
|
+
"rxjs" : ">=6.6.0"
|
|
47
49
|
},
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
"type" : "module",
|
|
51
|
+
"main" : "cjs/index.js",
|
|
52
|
+
"module" : "esm/index.js",
|
|
53
|
+
"types" : "esm/index.d.ts",
|
|
54
|
+
"exports" : {
|
|
55
|
+
"." : {
|
|
56
|
+
"require" : "./cjs/index.js",
|
|
57
|
+
"default" : "./esm/index.js"
|
|
58
|
+
},
|
|
59
|
+
"./cjs" : "./cjs/index.js",
|
|
60
|
+
"./esm" : "./esm/index.js"
|
|
51
61
|
},
|
|
52
|
-
"
|
|
62
|
+
"engines" : {
|
|
63
|
+
"node" : ">=16.0",
|
|
64
|
+
"npm" : ">=7.0.0"
|
|
65
|
+
},
|
|
66
|
+
"files" : [
|
|
67
|
+
"bin/",
|
|
68
|
+
"cjs/",
|
|
69
|
+
"esm/",
|
|
53
70
|
"LICENSE",
|
|
54
|
-
"README"
|
|
55
|
-
"dist/"
|
|
71
|
+
"README.md"
|
|
56
72
|
],
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"compile": "tsc",
|
|
64
|
-
"lint": "eslint src/** --no-error-on-unmatched-pattern",
|
|
65
|
-
"test": "TS_NODE_PROJECT='./test/tsconfig.json' mocha -r ts-node/register -r tsconfig-paths/register --reporter spec test/**/*.spec.ts"
|
|
66
|
-
}
|
|
67
|
-
}
|
|
73
|
+
"keywords" : [
|
|
74
|
+
"sqb",
|
|
75
|
+
"nestjs",
|
|
76
|
+
"nest"
|
|
77
|
+
]
|
|
78
|
+
}
|