@sqb/nestjs 4.0.2 → 4.0.6
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/index.d.ts +4 -3
- package/dist/index.js +6 -3
- package/dist/sqb-core.module.d.ts +2 -2
- package/dist/sqb-core.module.js +13 -12
- package/dist/sqb.constants.d.ts +2 -3
- package/dist/sqb.constants.js +3 -4
- package/dist/sqb.decorators.d.ts +1 -0
- package/dist/sqb.decorators.js +7 -0
- package/dist/{interfaces/sqb-options.interface.d.ts → sqb.interface.d.ts} +0 -0
- package/dist/{interfaces/sqb-options.interface.js → sqb.interface.js} +0 -0
- package/dist/sqb.module.d.ts +1 -1
- package/dist/sqb.utils.d.ts +11 -0
- package/dist/sqb.utils.js +40 -0
- package/package.json +10 -10
- package/dist/common/sqb.decorators.d.ts +0 -2
- package/dist/common/sqb.decorators.js +0 -7
- package/dist/common/sqb.utils.d.ts +0 -13
- package/dist/common/sqb.utils.js +0 -44
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './interfaces/sqb-options.interface';
|
|
1
|
+
export * from './sqb.decorators';
|
|
2
|
+
export * from './sqb.interface';
|
|
4
3
|
export * from './sqb.module';
|
|
4
|
+
export * from './sqb.utils';
|
|
5
|
+
export { SqbClient } from '@sqb/connect';
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
|
|
14
|
-
__exportStar(require("./
|
|
15
|
-
__exportStar(require("./
|
|
13
|
+
exports.SqbClient = void 0;
|
|
14
|
+
__exportStar(require("./sqb.decorators"), exports);
|
|
15
|
+
__exportStar(require("./sqb.interface"), exports);
|
|
16
16
|
__exportStar(require("./sqb.module"), exports);
|
|
17
|
+
__exportStar(require("./sqb.utils"), exports);
|
|
18
|
+
var connect_1 = require("@sqb/connect");
|
|
19
|
+
Object.defineProperty(exports, "SqbClient", { enumerable: true, get: function () { return connect_1.SqbClient; } });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DynamicModule, OnApplicationShutdown } from '@nestjs/common';
|
|
2
2
|
import { ModuleRef } from '@nestjs/core';
|
|
3
|
-
import { SqbModuleAsyncOptions, SqbModuleOptions } from './
|
|
3
|
+
import { SqbModuleAsyncOptions, SqbModuleOptions } from './sqb.interface';
|
|
4
4
|
export declare class SqbCoreModule implements OnApplicationShutdown {
|
|
5
5
|
private readonly options;
|
|
6
6
|
private readonly moduleRef;
|
|
@@ -10,5 +10,5 @@ export declare class SqbCoreModule implements OnApplicationShutdown {
|
|
|
10
10
|
onApplicationShutdown(): Promise<void>;
|
|
11
11
|
private static createAsyncProviders;
|
|
12
12
|
private static createAsyncOptionsProvider;
|
|
13
|
-
private static
|
|
13
|
+
private static createConnection;
|
|
14
14
|
}
|
package/dist/sqb-core.module.js
CHANGED
|
@@ -33,12 +33,13 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
33
33
|
var SqbCoreModule_1;
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
35
|
exports.SqbCoreModule = void 0;
|
|
36
|
+
const crypto = __importStar(require("crypto"));
|
|
36
37
|
const common_1 = require("@nestjs/common");
|
|
37
38
|
const core_1 = require("@nestjs/core");
|
|
38
39
|
const rxjs_1 = require("rxjs");
|
|
39
40
|
const rxjs = __importStar(require("rxjs"));
|
|
40
41
|
const connect_1 = require("@sqb/connect");
|
|
41
|
-
const sqb_utils_1 = require("./
|
|
42
|
+
const sqb_utils_1 = require("./sqb.utils");
|
|
42
43
|
const sqb_constants_1 = require("./sqb.constants");
|
|
43
44
|
let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
44
45
|
constructor(options, moduleRef) {
|
|
@@ -51,8 +52,8 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
51
52
|
useValue: options,
|
|
52
53
|
};
|
|
53
54
|
const connectionProvider = {
|
|
54
|
-
provide: (0, sqb_utils_1.
|
|
55
|
-
useFactory: () => this.
|
|
55
|
+
provide: (0, sqb_utils_1.getSQBToken)(options.name),
|
|
56
|
+
useFactory: () => this.createConnection(options),
|
|
56
57
|
};
|
|
57
58
|
return {
|
|
58
59
|
module: SqbCoreModule_1,
|
|
@@ -62,11 +63,11 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
62
63
|
}
|
|
63
64
|
static forRootAsync(options) {
|
|
64
65
|
const connectionProvider = {
|
|
65
|
-
provide: (0, sqb_utils_1.
|
|
66
|
+
provide: (0, sqb_utils_1.getSQBToken)(options.name),
|
|
66
67
|
inject: [sqb_constants_1.SQB_MODULE_OPTIONS],
|
|
67
68
|
useFactory: async (sqbOptions) => {
|
|
68
69
|
const name = options.name || sqbOptions.name;
|
|
69
|
-
return
|
|
70
|
+
return this.createConnection({
|
|
70
71
|
...sqbOptions,
|
|
71
72
|
name
|
|
72
73
|
});
|
|
@@ -81,14 +82,14 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
81
82
|
connectionProvider,
|
|
82
83
|
{
|
|
83
84
|
provide: sqb_constants_1.SQB_MODULE_ID,
|
|
84
|
-
useValue:
|
|
85
|
+
useValue: crypto.randomUUID(),
|
|
85
86
|
},
|
|
86
87
|
],
|
|
87
88
|
exports: [connectionProvider],
|
|
88
89
|
};
|
|
89
90
|
}
|
|
90
91
|
async onApplicationShutdown() {
|
|
91
|
-
const client = this.moduleRef.get((0, sqb_utils_1.
|
|
92
|
+
const client = this.moduleRef.get((0, sqb_utils_1.getSQBToken)(this.options.name));
|
|
92
93
|
if (client)
|
|
93
94
|
await client.close(this.options.shutdownWaitMs);
|
|
94
95
|
}
|
|
@@ -117,14 +118,14 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
117
118
|
if (useClass) {
|
|
118
119
|
return {
|
|
119
120
|
provide: sqb_constants_1.SQB_MODULE_OPTIONS,
|
|
120
|
-
useFactory:
|
|
121
|
+
useFactory: (optionsFactory) => optionsFactory.createSqbOptions(options.name),
|
|
121
122
|
inject: [useClass],
|
|
122
123
|
};
|
|
123
124
|
}
|
|
124
125
|
throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting');
|
|
125
126
|
}
|
|
126
|
-
static async
|
|
127
|
-
const connectionToken = options.name
|
|
127
|
+
static async createConnection(options) {
|
|
128
|
+
const connectionToken = options.name;
|
|
128
129
|
// NestJS 8
|
|
129
130
|
// @ts-ignore
|
|
130
131
|
if (rxjs.lastValueFrom) {
|
|
@@ -133,7 +134,7 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
133
134
|
const client = new connect_1.SqbClient(options);
|
|
134
135
|
await client.test();
|
|
135
136
|
return client;
|
|
136
|
-
}).pipe((0, sqb_utils_1.handleRetry)(options.retryAttempts, options.retryDelay,
|
|
137
|
+
}).pipe((0, sqb_utils_1.handleRetry)(connectionToken, options.retryAttempts, options.retryDelay, options.verboseRetryLog, options.toRetry)));
|
|
137
138
|
}
|
|
138
139
|
else {
|
|
139
140
|
// NestJS 7
|
|
@@ -143,7 +144,7 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
143
144
|
await client.test();
|
|
144
145
|
return client;
|
|
145
146
|
})
|
|
146
|
-
.pipe((0, sqb_utils_1.handleRetry)(options.retryAttempts, options.retryDelay,
|
|
147
|
+
.pipe((0, sqb_utils_1.handleRetry)(connectionToken, options.retryAttempts, options.retryDelay, options.verboseRetryLog, options.toRetry))
|
|
147
148
|
.toPromise();
|
|
148
149
|
}
|
|
149
150
|
}
|
package/dist/sqb.constants.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export declare const SQB_MODULE_OPTIONS
|
|
2
|
-
export declare const SQB_MODULE_ID
|
|
3
|
-
export declare const DEFAULT_CONNECTION_NAME = "default";
|
|
1
|
+
export declare const SQB_MODULE_OPTIONS: unique symbol;
|
|
2
|
+
export declare const SQB_MODULE_ID: unique symbol;
|
package/dist/sqb.constants.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.SQB_MODULE_OPTIONS = '
|
|
5
|
-
exports.SQB_MODULE_ID = '
|
|
6
|
-
exports.DEFAULT_CONNECTION_NAME = 'default';
|
|
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');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const InjectSQB: (name?: string) => ParameterDecorator;
|
|
@@ -0,0 +1,7 @@
|
|
|
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_1 = require("./sqb.utils");
|
|
6
|
+
const InjectSQB = (name) => (0, common_1.Inject)((0, sqb_utils_1.getSQBToken)(name));
|
|
7
|
+
exports.InjectSQB = InjectSQB;
|
|
File without changes
|
|
File without changes
|
package/dist/sqb.module.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DynamicModule } from '@nestjs/common';
|
|
2
|
-
import { SqbModuleAsyncOptions, SqbModuleOptions } from './
|
|
2
|
+
import { SqbModuleAsyncOptions, SqbModuleOptions } from './sqb.interface';
|
|
3
3
|
export declare class SqbModule {
|
|
4
4
|
static forRoot(options?: SqbModuleOptions): DynamicModule;
|
|
5
5
|
static forRootAsync(options: SqbModuleAsyncOptions): DynamicModule;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Type } from '@nestjs/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { SqbClient } from '@sqb/connect';
|
|
4
|
+
/**
|
|
5
|
+
* This function returns a Connection injection token for the given connection name.
|
|
6
|
+
* @param {string | symbol} [name=SQB_DEFAULT_CONNECTION] This optional parameter is either
|
|
7
|
+
* a SqbClient, or a ConnectionOptions or a string.
|
|
8
|
+
* @returns {string | symbol} The Connection injection token.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getSQBToken(name?: string | symbol | Type<SqbClient>): string | symbol | Type<SqbClient>;
|
|
11
|
+
export declare function handleRetry(connectionName?: string | symbol | Type<SqbClient>, retryAttempts?: number, retryDelay?: number, verboseRetryLog?: boolean, toRetry?: (err: any) => boolean): <T>(source: Observable<T>) => Observable<T>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleRetry = exports.getSQBToken = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const connect_1 = require("@sqb/connect");
|
|
7
|
+
const logger = new common_1.Logger('SqbModule');
|
|
8
|
+
/**
|
|
9
|
+
* This function returns a Connection injection token for the given connection name.
|
|
10
|
+
* @param {string | symbol} [name=SQB_DEFAULT_CONNECTION] This optional parameter is either
|
|
11
|
+
* a SqbClient, or a ConnectionOptions or a string.
|
|
12
|
+
* @returns {string | symbol} The Connection injection token.
|
|
13
|
+
*/
|
|
14
|
+
function getSQBToken(name) {
|
|
15
|
+
if (!name)
|
|
16
|
+
return connect_1.SqbClient;
|
|
17
|
+
if (typeof name === 'symbol' || typeof name === 'function')
|
|
18
|
+
return name;
|
|
19
|
+
return `${name}_SqbConnection`;
|
|
20
|
+
}
|
|
21
|
+
exports.getSQBToken = getSQBToken;
|
|
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
|
+
}
|
|
40
|
+
exports.handleRetry = handleRetry;
|
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.
|
|
4
|
+
"version": "4.0.6",
|
|
5
5
|
"author": "Panates Ltd.",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Eray Hanoglu <e.hanoglu@panates.com>"
|
|
@@ -24,21 +24,21 @@
|
|
|
24
24
|
"reflect-metadata": "^0.1.13"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@nestjs/common": "
|
|
28
|
-
"@nestjs/core": "
|
|
29
|
-
"@nestjs/testing": "
|
|
30
|
-
"@nestjs/platform-express": "
|
|
27
|
+
"@nestjs/common": ">=7.4.0",
|
|
28
|
+
"@nestjs/core": ">=7.4.0",
|
|
29
|
+
"@nestjs/testing": ">=7.4.0",
|
|
30
|
+
"@nestjs/platform-express": ">=7.4.0",
|
|
31
31
|
"postgresql-client": "^1.16.7",
|
|
32
32
|
"reflect-metadata": "^0.1.13",
|
|
33
33
|
"rxjs": "^7.2.0",
|
|
34
34
|
"supertest": "^6.1.3"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@sqb/connect": "^4.0.
|
|
38
|
-
"@sqb/builder": "^4.0.
|
|
39
|
-
"@nestjs/common": "
|
|
40
|
-
"@nestjs/core": "
|
|
41
|
-
"rxjs": "
|
|
37
|
+
"@sqb/connect": "^4.0.6",
|
|
38
|
+
"@sqb/builder": "^4.0.6",
|
|
39
|
+
"@nestjs/common": ">=7.4.0",
|
|
40
|
+
"@nestjs/core": ">=7.4.0",
|
|
41
|
+
"rxjs": ">=6.6.0"
|
|
42
42
|
},
|
|
43
43
|
"main": "dist/index.js",
|
|
44
44
|
"types": "dist/index.d.ts",
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InjectConnection = void 0;
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
5
|
-
const sqb_utils_1 = require("./sqb.utils");
|
|
6
|
-
const InjectConnection = (connection) => (0, common_1.Inject)((0, sqb_utils_1.getConnectionToken)(connection));
|
|
7
|
-
exports.InjectConnection = InjectConnection;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Type } from '@nestjs/common';
|
|
2
|
-
import { Observable } from 'rxjs';
|
|
3
|
-
import { SqbClient } from '@sqb/connect';
|
|
4
|
-
import { SqbModuleOptions } from '../interfaces/sqb-options.interface';
|
|
5
|
-
/**
|
|
6
|
-
* This function returns a Connection injection token for the given Connection, ConnectionOptions or connection name.
|
|
7
|
-
* @param {SqbModuleOptions | string} [client='default'] This optional parameter is either
|
|
8
|
-
* a Connection, or a ConnectionOptions or a string.
|
|
9
|
-
* @returns {string | Function} The Connection injection token.
|
|
10
|
-
*/
|
|
11
|
-
export declare function getConnectionToken(client?: SqbModuleOptions | string): string | Type<SqbClient>;
|
|
12
|
-
export declare function handleRetry(retryAttempts?: number, retryDelay?: number, connectionName?: string, verboseRetryLog?: boolean, toRetry?: (err: any) => boolean): <T>(source: Observable<T>) => Observable<T>;
|
|
13
|
-
export declare const generateString: () => any;
|
package/dist/common/sqb.utils.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateString = exports.handleRetry = exports.getConnectionToken = void 0;
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
5
|
-
const operators_1 = require("rxjs/operators");
|
|
6
|
-
const connect_1 = require("@sqb/connect");
|
|
7
|
-
const uuid_1 = require("uuid");
|
|
8
|
-
const sqb_constants_1 = require("../sqb.constants");
|
|
9
|
-
const logger = new common_1.Logger('SqbModule');
|
|
10
|
-
/**
|
|
11
|
-
* This function returns a Connection injection token for the given Connection, ConnectionOptions or connection name.
|
|
12
|
-
* @param {SqbModuleOptions | string} [client='default'] This optional parameter is either
|
|
13
|
-
* a Connection, or a ConnectionOptions or a string.
|
|
14
|
-
* @returns {string | Function} The Connection injection token.
|
|
15
|
-
*/
|
|
16
|
-
function getConnectionToken(client = sqb_constants_1.DEFAULT_CONNECTION_NAME) {
|
|
17
|
-
return sqb_constants_1.DEFAULT_CONNECTION_NAME === client ? connect_1.SqbClient
|
|
18
|
-
: ('string' === typeof client ? `${client}Connection`
|
|
19
|
-
: (sqb_constants_1.DEFAULT_CONNECTION_NAME === client.name || !client.name ? connect_1.SqbClient
|
|
20
|
-
: `${client.name}Connection`));
|
|
21
|
-
}
|
|
22
|
-
exports.getConnectionToken = getConnectionToken;
|
|
23
|
-
function handleRetry(retryAttempts = 9, retryDelay = 3000, connectionName = sqb_constants_1.DEFAULT_CONNECTION_NAME, verboseRetryLog = false, toRetry) {
|
|
24
|
-
return (source) => source.pipe((0, operators_1.retryWhen)((e) => e.pipe((0, operators_1.scan)((errorCount, error) => {
|
|
25
|
-
if (toRetry && !toRetry(error)) {
|
|
26
|
-
throw error;
|
|
27
|
-
}
|
|
28
|
-
const connectionInfo = connectionName === sqb_constants_1.DEFAULT_CONNECTION_NAME
|
|
29
|
-
? ''
|
|
30
|
-
: ` (${connectionName})`;
|
|
31
|
-
const verboseMessage = verboseRetryLog
|
|
32
|
-
? ` Message: ${error.message}.`
|
|
33
|
-
: '';
|
|
34
|
-
logger.error(`Unable to connect to the database${connectionInfo}.${verboseMessage} Retrying (${errorCount +
|
|
35
|
-
1})...`, error.stack);
|
|
36
|
-
if (errorCount + 1 >= retryAttempts) {
|
|
37
|
-
throw error;
|
|
38
|
-
}
|
|
39
|
-
return errorCount + 1;
|
|
40
|
-
}, 0), (0, operators_1.delay)(retryDelay))));
|
|
41
|
-
}
|
|
42
|
-
exports.handleRetry = handleRetry;
|
|
43
|
-
const generateString = () => (0, uuid_1.v4)();
|
|
44
|
-
exports.generateString = generateString;
|