@sqb/nestjs 4.15.0 → 4.16.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 CHANGED
@@ -1,10 +1,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; } });
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';
@@ -1,16 +1,13 @@
1
- "use strict";
2
1
  var SqbCoreModule_1;
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");
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: sqb_constants_js_1.SQB_MODULE_OPTIONS,
18
+ provide: SQB_MODULE_OPTIONS,
22
19
  useValue: options,
23
20
  };
24
21
  const connectionProvider = {
25
- provide: (0, sqb_utils_js_1.getSQBToken)(options.name),
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: (0, sqb_utils_js_1.getSQBToken)(options.name),
37
- inject: [sqb_constants_js_1.SQB_MODULE_OPTIONS],
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: sqb_constants_js_1.SQB_MODULE_ID,
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((0, sqb_utils_js_1.getSQBToken)(this.options.name));
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: sqb_constants_js_1.SQB_MODULE_OPTIONS,
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: sqb_constants_js_1.SQB_MODULE_OPTIONS,
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((0, rxjs_1.defer)(async () => {
99
- const client = new connect_1.SqbClient(options);
95
+ return await rxjs.lastValueFrom(defer(async () => {
96
+ const client = new SqbClient(options);
100
97
  await client.test();
101
98
  return client;
102
- }).pipe((0, sqb_utils_js_1.handleRetry)(connectionToken, options.retryAttempts, options.retryDelay, options.verboseRetryLog, options.toRetry)));
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 (0, rxjs_1.defer)(async () => {
107
- const client = new connect_1.SqbClient(options);
103
+ return await defer(async () => {
104
+ const client = new SqbClient(options);
108
105
  await client.test();
109
106
  return client;
110
107
  })
111
- .pipe((0, sqb_utils_js_1.handleRetry)(connectionToken, options.retryAttempts, options.retryDelay, options.verboseRetryLog, options.toRetry))
108
+ .pipe(handleRetry(connectionToken, options.retryAttempts, options.retryDelay, options.verboseRetryLog, options.toRetry))
112
109
  .toPromise();
113
110
  }
114
111
  };
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])
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 };
@@ -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');
1
+ export const SQB_MODULE_OPTIONS = Symbol('SQB_MODULE_OPTIONS');
2
+ export const SQB_MODULE_ID = Symbol('SQB_MODULE_ID');
@@ -1,7 +1,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;
1
+ import { Inject } from '@nestjs/common';
2
+ import { getSQBToken } from './sqb.utils.js';
3
+ export const InjectSQB = (name) => Inject(getSQBToken(name));
@@ -1,2 +1 @@
1
- "use strict";
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
- 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");
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: [sqb_core_module_js_1.SqbCoreModule.forRoot(options)],
9
+ imports: [SqbCoreModule.forRoot(options)],
13
10
  };
14
11
  }
15
12
  static forRootAsync(options) {
16
13
  return {
17
14
  module: SqbModule_1,
18
- imports: [sqb_core_module_js_1.SqbCoreModule.forRootAsync(options)],
15
+ imports: [SqbCoreModule.forRootAsync(options)],
19
16
  };
20
17
  }
21
18
  };
22
- exports.SqbModule = SqbModule;
23
- exports.SqbModule = SqbModule = SqbModule_1 = tslib_1.__decorate([
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
- "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');
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 connect_1.SqbClient;
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((0, operators_1.retryWhen)(e => e.pipe((0, operators_1.scan)((errorCount, error) => {
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 === connect_1.SqbClient ? 'default' : ` (${String(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), (0, operators_1.delay)(retryDelay))));
30
+ }, 0), delay(retryDelay))));
35
31
  }
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.15.0",
4
+ "version": "4.16.0",
5
5
  "author": "Panates",
6
6
  "license": "Apache-2.0",
7
7
  "scripts": {
@@ -26,15 +26,15 @@
26
26
  "@nestjs/core": "^10.3.10",
27
27
  "@nestjs/platform-express": "^10.3.10",
28
28
  "@nestjs/testing": "^10.3.10",
29
- "postgrejs": "^2.16.0",
29
+ "postgrejs": "^2.17.0",
30
30
  "rxjs": "^7.8.1",
31
31
  "supertest": "^7.0.0"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "@nestjs/common": ">=7.4.0",
35
35
  "@nestjs/core": ">=7.4.0",
36
- "@sqb/builder": "^4.15.0",
37
- "@sqb/connect": "^4.15.0",
36
+ "@sqb/builder": "^4.16.0",
37
+ "@sqb/connect": "^4.16.0",
38
38
  "reflect-metadata": "^0.2.2",
39
39
  "rxjs": ">=6.6.0"
40
40
  },