@sqb/nestjs 6.0.7 → 6.0.10

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/LICENSE CHANGED
@@ -1,191 +1,30 @@
1
-
2
- Apache License
3
- Version 2.0, January 2004
4
- https://www.apache.org/licenses/
5
-
6
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
-
8
- 1. Definitions.
9
-
10
- "License" shall mean the terms and conditions for use, reproduction,
11
- and distribution as defined by Sections 1 through 9 of this document.
12
-
13
- "Licensor" shall mean the copyright owner or entity authorized by
14
- the copyright owner that is granting the License.
15
-
16
- "Legal Entity" shall mean the union of the acting entity and all
17
- other entities that control, are controlled by, or are under common
18
- control with that entity. For the purposes of this definition,
19
- "control" means (i) the power, direct or indirect, to cause the
20
- direction or management of such entity, whether by contract or
21
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
- outstanding shares, or (iii) beneficial ownership of such entity.
23
-
24
- "You" (or "Your") shall mean an individual or Legal Entity
25
- exercising permissions granted by this License.
26
-
27
- "Source" form shall mean the preferred form for making modifications,
28
- including but not limited to software source code, documentation
29
- source, and configuration files.
30
-
31
- "Object" form shall mean any form resulting from mechanical
32
- transformation or translation of a Source form, including but
33
- not limited to compiled object code, generated documentation,
34
- and conversions to other media types.
35
-
36
- "Work" shall mean the work of authorship, whether in Source or
37
- Object form, made available under the License, as indicated by a
38
- copyright notice that is included in or attached to the work
39
- (an example is provided in the Appendix below).
40
-
41
- "Derivative Works" shall mean any work, whether in Source or Object
42
- form, that is based on (or derived from) the Work and for which the
43
- editorial revisions, annotations, elaborations, or other modifications
44
- represent, as a whole, an original work of authorship. For the purposes
45
- of this License, Derivative Works shall not include works that remain
46
- separable from, or merely link (or bind by name) to the interfaces of,
47
- the Work and Derivative Works thereof.
48
-
49
- "Contribution" shall mean any work of authorship, including
50
- the original version of the Work and any modifications or additions
51
- to that Work or Derivative Works thereof, that is intentionally
52
- submitted to Licensor for inclusion in the Work by the copyright owner
53
- or by an individual or Legal Entity authorized to submit on behalf of
54
- the copyright owner. For the purposes of this definition, "submitted"
55
- means any form of electronic, verbal, or written communication sent
56
- to the Licensor or its representatives, including but not limited to
57
- communication on electronic mailing lists, source code control systems,
58
- and issue tracking systems that are managed by, or on behalf of, the
59
- Licensor for the purpose of discussing and improving the Work, but
60
- excluding communication that is conspicuously marked or otherwise
61
- designated in writing by the copyright owner as "Not a Contribution."
62
-
63
- "Contributor" shall mean Licensor and any individual or Legal Entity
64
- on behalf of whom a Contribution has been received by Licensor and
65
- subsequently incorporated within the Work.
66
-
67
- 2. Grant of Copyright License. Subject to the terms and conditions of
68
- this License, each Contributor hereby grants to You a perpetual,
69
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
- copyright license to reproduce, prepare Derivative Works of,
71
- publicly display, publicly perform, sublicense, and distribute the
72
- Work and such Derivative Works in Source or Object form.
73
-
74
- 3. Grant of Patent License. Subject to the terms and conditions of
75
- this License, each Contributor hereby grants to You a perpetual,
76
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
- (except as stated in this section) patent license to make, have made,
78
- use, offer to sell, sell, import, and otherwise transfer the Work,
79
- where such license applies only to those patent claims licensable
80
- by such Contributor that are necessarily infringed by their
81
- Contribution(s) alone or by combination of their Contribution(s)
82
- with the Work to which such Contribution(s) was submitted. If You
83
- institute patent litigation against any entity (including a
84
- cross-claim or counterclaim in a lawsuit) alleging that the Work
85
- or a Contribution incorporated within the Work constitutes direct
86
- or contributory patent infringement, then any patent licenses
87
- granted to You under this License for that Work shall terminate
88
- as of the date such litigation is filed.
89
-
90
- 4. Redistribution. You may reproduce and distribute copies of the
91
- Work or Derivative Works thereof in any medium, with or without
92
- modifications, and in Source or Object form, provided that You
93
- meet the following conditions:
94
-
95
- (a) You must give any other recipients of the Work or
96
- Derivative Works a copy of this License; and
97
-
98
- (b) You must cause any modified files to carry prominent notices
99
- stating that You changed the files; and
100
-
101
- (c) You must retain, in the Source form of any Derivative Works
102
- that You distribute, all copyright, patent, trademark, and
103
- attribution notices from the Source form of the Work,
104
- excluding those notices that do not pertain to any part of
105
- the Derivative Works; and
106
-
107
- (d) If the Work includes a "NOTICE" text file as part of its
108
- distribution, then any Derivative Works that You distribute must
109
- include a readable copy of the attribution notices contained
110
- within such NOTICE file, excluding those notices that do not
111
- pertain to any part of the Derivative Works, in at least one
112
- of the following places: within a NOTICE text file distributed
113
- as part of the Derivative Works; within the Source form or
114
- documentation, if provided along with the Derivative Works; or,
115
- within a display generated by the Derivative Works, if and
116
- wherever such third-party notices normally appear. The contents
117
- of the NOTICE file are for informational purposes only and
118
- do not modify the License. You may add Your own attribution
119
- notices within Derivative Works that You distribute, alongside
120
- or as an addendum to the NOTICE text from the Work, provided
121
- that such additional attribution notices cannot be construed
122
- as modifying the License.
123
-
124
- You may add Your own copyright statement to Your modifications and
125
- may provide additional or different license terms and conditions
126
- for use, reproduction, or distribution of Your modifications, or
127
- for any such Derivative Works as a whole, provided Your use,
128
- reproduction, and distribution of the Work otherwise complies with
129
- the conditions stated in this License.
130
-
131
- 5. Submission of Contributions. Unless You explicitly state otherwise,
132
- any Contribution intentionally submitted for inclusion in the Work
133
- by You to the Licensor shall be under the terms and conditions of
134
- this License, without any additional terms or conditions.
135
- Notwithstanding the above, nothing herein shall supersede or modify
136
- the terms of any separate license agreement you may have executed
137
- with Licensor regarding such Contributions.
138
-
139
- 6. Trademarks. This License does not grant permission to use the trade
140
- names, trademarks, service marks, or product names of the Licensor,
141
- except as required for reasonable and customary use in describing the
142
- origin of the Work and reproducing the content of the NOTICE file.
143
-
144
- 7. Disclaimer of Warranty. Unless required by applicable law or
145
- agreed to in writing, Licensor provides the Work (and each
146
- Contributor provides its Contributions) on an "AS IS" BASIS,
147
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
- implied, including, without limitation, any warranties or conditions
149
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
- PARTICULAR PURPOSE. You are solely responsible for determining the
151
- appropriateness of using or redistributing the Work and assume any
152
- risks associated with Your exercise of permissions under this License.
153
-
154
- 8. Limitation of Liability. In no event and under no legal theory,
155
- whether in tort (including negligence), contract, or otherwise,
156
- unless required by applicable law (such as deliberate and grossly
157
- negligent acts) or agreed to in writing, shall any Contributor be
158
- liable to You for damages, including any direct, indirect, special,
159
- incidental, or consequential damages of any character arising as a
160
- result of this License or out of the use or inability to use the
161
- Work (including but not limited to damages for loss of goodwill,
162
- work stoppage, computer failure or malfunction, or any and all
163
- other commercial damages or losses), even if such Contributor
164
- has been advised of the possibility of such damages.
165
-
166
- 9. Accepting Warranty or Additional Liability. While redistributing
167
- the Work or Derivative Works thereof, You may choose to offer,
168
- and charge a fee for, acceptance of support, warranty, indemnity,
169
- or other liability obligations and/or rights consistent with this
170
- License. However, in accepting such obligations, You may act only
171
- on Your own behalf and on Your sole responsibility, not on behalf
172
- of any other Contributor, and only if You agree to indemnify,
173
- defend, and hold each Contributor harmless for any liability
174
- incurred by, or claims asserted against, such Contributor by reason
175
- of your accepting any such warranty or additional liability.
176
-
177
- END OF TERMS AND CONDITIONS
178
-
179
- Copyright 2013-2018 Docker, Inc.
180
-
181
- Licensed under the Apache License, Version 2.0 (the "License");
182
- you may not use this file except in compliance with the License.
183
- You may obtain a copy of the License at
184
-
185
- https://www.apache.org/licenses/LICENSE-2.0
186
-
187
- Unless required by applicable law or agreed to in writing, software
188
- distributed under the License is distributed on an "AS IS" BASIS,
189
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
- See the License for the specific language governing permissions and
191
- limitations under the License.
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2020 Panates
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice,
10
+ this list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright
13
+ notice, this list of conditions and the following disclaimer in the
14
+ documentation and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,5 +1,6 @@
1
- <p style="text-align:center">
2
- <img src="https://user-images.githubusercontent.com/3836517/32965280-1a2b63ce-cbe7-11e7-8ee1-ba47313503c5.png" width="500px" alt="SQB Logo"/>
1
+
2
+ <p style="text-align: center;">
3
+ <img src="https://sqb.panates.com/img/github-hero.webp" width="1280" alt="SQB" />
3
4
  </p>
4
5
 
5
6
  <br>
@@ -122,5 +123,5 @@ SQB is available under [MIT](LICENSE) license.
122
123
  [downloads-url]: https://npmjs.org/package/@sqb/nestjs
123
124
  [ci-test-image]: https://github.com/panates/sqb/actions/workflows/test.yml/badge.svg
124
125
  [ci-test-url]: https://github.com/panates/sqb/actions/workflows/test.yml
125
- [coveralls-image]: https://coveralls.io/repos/github/sqbjs/sqb/badge.svg?branch=master
126
+ [coveralls-image]: https://coveralls.io/repos/github/panates/sqb/badge.svg?branch=dev
126
127
  [coveralls-url]: https://coveralls.io/github/sqbjs/sqb?branch=master
package/constants.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ /** This package's own version, kept in step with its `package.json` by `rman version`
2
+ * (see `.rmanrc` `version.stamp`) - never edit it by hand. */
3
+ export declare const version = "6.0.10";
package/constants.js ADDED
@@ -0,0 +1,3 @@
1
+ /** This package's own version, kept in step with its `package.json` by `rman version`
2
+ * (see `.rmanrc` `version.stamp`) - never edit it by hand. */
3
+ export const version = '6.0.10';
@@ -1,2 +1,14 @@
1
1
  import type { SqbClientConnectionOptions } from './sqb.interface.js';
2
+ /**
3
+ * Fills in any connection option not already set on `moduleOptions` from
4
+ * the corresponding `<prefix><NAME>` environment variable (e.g.
5
+ * `SQB_HOST`, `SQB_POOL_MAX`), returning a new, cloned options object -
6
+ * `moduleOptions` itself is left untouched. Explicitly-given options
7
+ * always take precedence over the environment.
8
+ *
9
+ * @param moduleOptions - the options given to `SqbModule.forRoot()`/
10
+ * `forRootAsync()` (or resolved from its `useFactory`)
11
+ * @param prefix - environment variable prefix, e.g. `'SQB_'` for `SQB_HOST`
12
+ * @returns a new options object with environment-sourced defaults applied
13
+ */
2
14
  export declare function getSqbConfig(moduleOptions: SqbClientConnectionOptions, prefix?: string): SqbClientConnectionOptions;
package/get-sqb-config.js CHANGED
@@ -1,6 +1,18 @@
1
1
  import process from 'node:process';
2
2
  import { clone } from '@jsopen/objects';
3
3
  import { toBoolean, toInt } from 'putil-varhelpers';
4
+ /**
5
+ * Fills in any connection option not already set on `moduleOptions` from
6
+ * the corresponding `<prefix><NAME>` environment variable (e.g.
7
+ * `SQB_HOST`, `SQB_POOL_MAX`), returning a new, cloned options object -
8
+ * `moduleOptions` itself is left untouched. Explicitly-given options
9
+ * always take precedence over the environment.
10
+ *
11
+ * @param moduleOptions - the options given to `SqbModule.forRoot()`/
12
+ * `forRootAsync()` (or resolved from its `useFactory`)
13
+ * @param prefix - environment variable prefix, e.g. `'SQB_'` for `SQB_HOST`
14
+ * @returns a new options object with environment-sourced defaults applied
15
+ */
4
16
  export function getSqbConfig(moduleOptions, prefix = 'SQB_') {
5
17
  const options = clone(moduleOptions);
6
18
  const env = process.env;
package/index.d.ts CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @sqb/nestjs - NestJS integration module for `@sqb/connect`, exposing a
3
+ * `SqbClient` (or a custom injection token) as an injectable NestJS
4
+ * provider via {@link SqbModule}.
5
+ */
6
+ export * from './constants.js';
1
7
  export * from './sqb.interface.js';
2
8
  export * from './sqb.module.js';
3
9
  export { SqbClient } from '@sqb/connect';
package/index.js CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @sqb/nestjs - NestJS integration module for `@sqb/connect`, exposing a
3
+ * `SqbClient` (or a custom injection token) as an injectable NestJS
4
+ * provider via {@link SqbModule}.
5
+ */
6
+ export * from './constants.js';
1
7
  export * from './sqb.interface.js';
2
8
  export * from './sqb.module.js';
3
9
  export { SqbClient } from '@sqb/connect';
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@sqb/nestjs",
3
3
  "description": "Nestjs module for data connection using SQB",
4
- "version": "6.0.7",
4
+ "version": "6.0.10",
5
5
  "author": "Panates",
6
- "license": "Apache-2.0",
6
+ "license": "BSD-3-Clause",
7
+ "homepage": "https://www.sqbjs.org",
7
8
  "dependencies": {
8
- "@jsopen/objects": "^2.3.0",
9
+ "@jsopen/objects": "^2.3.3",
9
10
  "ansi-colors": "^4.1.3",
10
11
  "putil-varhelpers": "^1.7.0",
11
12
  "tslib": "^2.8.1"
@@ -13,8 +14,8 @@
13
14
  "peerDependencies": {
14
15
  "@nestjs/common": ">=7.4.0",
15
16
  "@nestjs/core": ">=7.4.0",
16
- "@sqb/builder": "^6.0.7",
17
- "@sqb/connect": "^6.0.7",
17
+ "@sqb/builder": "^6.0.10",
18
+ "@sqb/connect": "^6.0.10",
18
19
  "reflect-metadata": "^0.2.2",
19
20
  "rxjs": ">=6.6.0"
20
21
  },
@@ -33,7 +34,9 @@
33
34
  },
34
35
  "contributors": [
35
36
  "Eray Hanoglu <e.hanoglu@panates.com>",
36
- "Ilker Gurelli <i.gurelli@panates.com>"
37
+ "Ilker Gurelli <i.gurelli@panates.com>",
38
+ "Onur Tokel <o.tokel@panates.com>",
39
+ "Bircan Yuruk <b.yuruk@panates.com>"
37
40
  ],
38
41
  "repository": {
39
42
  "type": "git",
@@ -48,4 +51,4 @@
48
51
  "publishConfig": {
49
52
  "access": "public"
50
53
  }
51
- }
54
+ }
@@ -1,14 +1,44 @@
1
1
  import { type DynamicModule, Logger, type OnApplicationBootstrap, type OnApplicationShutdown } from '@nestjs/common';
2
2
  import { SqbClient } from '@sqb/connect';
3
3
  import type { SqbClientConnectionOptions, SqbModuleAsyncOptions, SqbModuleOptions } from './sqb.interface.js';
4
+ /**
5
+ * The NestJS dynamic module that actually registers `@sqb/nestjs`'s
6
+ * providers - {@link SqbModule} is a thin public wrapper around this one.
7
+ * Registered `@Global()` so the `SqbClient` provider need not be
8
+ * re-imported into every feature module that injects it.
9
+ */
4
10
  export declare class SqbCoreModule implements OnApplicationBootstrap, OnApplicationShutdown {
5
11
  protected readonly client: SqbClient;
6
12
  private readonly connectionOptions;
7
13
  private logger;
14
+ /** Registers `@sqb/nestjs` with connection options given directly (merged with environment-variable defaults via `getSqbConfig`). */
8
15
  static forRoot(moduleOptions?: SqbModuleOptions): DynamicModule;
16
+ /**
17
+ * Registers `@sqb/nestjs` with connection options produced by an
18
+ * injected factory (`asyncOptions.useFactory`), merged with
19
+ * environment-variable defaults via `getSqbConfig`.
20
+ *
21
+ * @throws {Error} if `asyncOptions.useFactory` is not given
22
+ */
9
23
  static forRootAsync(asyncOptions: SqbModuleAsyncOptions): DynamicModule;
24
+ /**
25
+ * Builds the {@link DynamicModule} shared by `forRoot`/`forRootAsync`:
26
+ * registers the `SqbClient` provider (under the caller-chosen `token`,
27
+ * defaulting to the `SqbClient` class) built from whatever provider
28
+ * `metadata` resolves `SQB_CONNECTION_OPTIONS`, plus the fixed
29
+ * {@link CLIENT_TOKEN} alias, a per-registration `SQB_MODULE_ID`, and a
30
+ * `Logger` provider (the caller's, or a new one scoped `'SQB'`).
31
+ */
10
32
  private static _createDynamicModule;
11
33
  constructor(client: SqbClient, connectionOptions: SqbClientConnectionOptions, logger: Logger);
34
+ /**
35
+ * Connects to the database (unless `lazyConnect` is set) as soon as the
36
+ * NestJS application finishes bootstrapping, logging a "waiting to
37
+ * connect" notice if it takes more than a second, and rethrowing (after
38
+ * logging) any connection failure so application startup fails loudly
39
+ * rather than serving traffic against a database that isn't reachable.
40
+ */
12
41
  onApplicationBootstrap(): Promise<void> | undefined;
42
+ /** Closes the `SqbClient` connection as the NestJS application shuts down, waiting up to `connectionOptions.shutdownWaitMs` for it. */
13
43
  onApplicationShutdown(): Promise<void>;
14
44
  }
@@ -7,11 +7,25 @@ import colors from 'ansi-colors';
7
7
  import * as crypto from 'crypto';
8
8
  import { getSqbConfig } from './get-sqb-config.js';
9
9
  import { SQB_CONNECTION_OPTIONS, SQB_MODULE_ID, SQB_MODULE_OPTIONS, } from './sqb.constants.js';
10
+ /**
11
+ * Fixed injection token the `SqbClient` provider is always additionally
12
+ * registered under (via `useExisting`), regardless of the caller-chosen
13
+ * `token` option - lets this module's own lifecycle hooks
14
+ * (`onApplicationBootstrap`/`onApplicationShutdown`) resolve the client
15
+ * without needing to know what token the caller picked.
16
+ */
10
17
  const CLIENT_TOKEN = Symbol('CLIENT_TOKEN');
18
+ /**
19
+ * The NestJS dynamic module that actually registers `@sqb/nestjs`'s
20
+ * providers - {@link SqbModule} is a thin public wrapper around this one.
21
+ * Registered `@Global()` so the `SqbClient` provider need not be
22
+ * re-imported into every feature module that injects it.
23
+ */
11
24
  let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
12
25
  client;
13
26
  connectionOptions;
14
27
  logger;
28
+ /** Registers `@sqb/nestjs` with connection options given directly (merged with environment-variable defaults via `getSqbConfig`). */
15
29
  static forRoot(moduleOptions = {}) {
16
30
  const connectionOptions = getSqbConfig(moduleOptions.useValue || {}, moduleOptions.envPrefix);
17
31
  return this._createDynamicModule(moduleOptions, {
@@ -24,6 +38,13 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
24
38
  ],
25
39
  });
26
40
  }
41
+ /**
42
+ * Registers `@sqb/nestjs` with connection options produced by an
43
+ * injected factory (`asyncOptions.useFactory`), merged with
44
+ * environment-variable defaults via `getSqbConfig`.
45
+ *
46
+ * @throws {Error} if `asyncOptions.useFactory` is not given
47
+ */
27
48
  static forRootAsync(asyncOptions) {
28
49
  assert.ok(asyncOptions.useFactory, 'useFactory is required');
29
50
  return this._createDynamicModule(asyncOptions, {
@@ -40,6 +61,14 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
40
61
  ],
41
62
  });
42
63
  }
64
+ /**
65
+ * Builds the {@link DynamicModule} shared by `forRoot`/`forRootAsync`:
66
+ * registers the `SqbClient` provider (under the caller-chosen `token`,
67
+ * defaulting to the `SqbClient` class) built from whatever provider
68
+ * `metadata` resolves `SQB_CONNECTION_OPTIONS`, plus the fixed
69
+ * {@link CLIENT_TOKEN} alias, a per-registration `SQB_MODULE_ID`, and a
70
+ * `Logger` provider (the caller's, or a new one scoped `'SQB'`).
71
+ */
43
72
  static _createDynamicModule(opts, metadata) {
44
73
  const token = opts.token || SqbClient;
45
74
  const providers = [
@@ -78,6 +107,13 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
78
107
  this.connectionOptions = connectionOptions;
79
108
  this.logger = logger;
80
109
  }
110
+ /**
111
+ * Connects to the database (unless `lazyConnect` is set) as soon as the
112
+ * NestJS application finishes bootstrapping, logging a "waiting to
113
+ * connect" notice if it takes more than a second, and rethrowing (after
114
+ * logging) any connection failure so application startup fails loudly
115
+ * rather than serving traffic against a database that isn't reachable.
116
+ */
81
117
  onApplicationBootstrap() {
82
118
  if (this.connectionOptions.lazyConnect)
83
119
  return;
@@ -97,6 +133,7 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
97
133
  this.logger?.log(`Database connection established`);
98
134
  });
99
135
  }
136
+ /** Closes the `SqbClient` connection as the NestJS application shuts down, waiting up to `connectionOptions.shutdownWaitMs` for it. */
100
137
  async onApplicationShutdown() {
101
138
  await this.client.close(this.connectionOptions.shutdownWaitMs);
102
139
  }
@@ -1,3 +1,6 @@
1
+ /** Injection token for the raw {@link SqbModuleOptions}/`SqbModuleAsyncOptions` object `SqbModule.forRoot()`/`forRootAsync()` was called with. */
1
2
  export declare const SQB_MODULE_OPTIONS: unique symbol;
3
+ /** Injection token for the resolved {@link SqbClientConnectionOptions} (env-defaults applied by `getSqbConfig`), used to construct the `SqbClient` provider. */
2
4
  export declare const SQB_CONNECTION_OPTIONS: unique symbol;
5
+ /** Injection token for a random id unique to each `SqbCoreModule.forRoot()`/`forRootAsync()` call, letting multiple registrations of the module coexist. */
3
6
  export declare const SQB_MODULE_ID: unique symbol;
package/sqb.constants.js CHANGED
@@ -1,3 +1,6 @@
1
+ /** Injection token for the raw {@link SqbModuleOptions}/`SqbModuleAsyncOptions` object `SqbModule.forRoot()`/`forRootAsync()` was called with. */
1
2
  export const SQB_MODULE_OPTIONS = Symbol('SQB_MODULE_OPTIONS');
3
+ /** Injection token for the resolved {@link SqbClientConnectionOptions} (env-defaults applied by `getSqbConfig`), used to construct the `SqbClient` provider. */
2
4
  export const SQB_CONNECTION_OPTIONS = Symbol('SQB_CONNECTION_OPTIONS');
5
+ /** Injection token for a random id unique to each `SqbCoreModule.forRoot()`/`forRootAsync()` call, letting multiple registrations of the module coexist. */
3
6
  export const SQB_MODULE_ID = Symbol('SQB_MODULE_ID');
@@ -1,6 +1,10 @@
1
1
  import type { InjectionToken, LoggerService } from '@nestjs/common';
2
2
  import type { ModuleMetadata } from '@nestjs/common/interfaces/index.js';
3
3
  import type { ClientConfiguration } from '@sqb/connect';
4
+ /**
5
+ * `@sqb/connect` {@link ClientConfiguration} plus the NestJS-specific
6
+ * options `@sqb/nestjs` reads on top of it.
7
+ */
4
8
  export interface SqbClientConnectionOptions extends ClientConfiguration {
5
9
  /**
6
10
  * Number of ms to wait closing connection on shutdown
@@ -13,17 +17,25 @@ export interface SqbClientConnectionOptions extends ClientConfiguration {
13
17
  */
14
18
  lazyConnect?: boolean;
15
19
  }
20
+ /** Options common to both the synchronous and factory-based module registration forms. */
16
21
  interface BaseModuleOptions {
22
+ /** Injection token the `SqbClient` provider is registered under. Defaults to the `SqbClient` class itself. */
17
23
  token?: InjectionToken;
24
+ /** Prefix used to read connection options from environment variables (e.g. `SQB_HOST`) for any option not given explicitly. Defaults to `'SQB_'`. */
18
25
  envPrefix?: string;
19
26
  logger?: LoggerService | string;
27
+ /** Registers the module as a NestJS global module (available everywhere without re-importing). */
20
28
  global?: boolean;
21
29
  }
30
+ /** Options for {@link SqbModule.forRoot}: connection options are given directly as `useValue`. */
22
31
  export interface SqbModuleOptions extends BaseModuleOptions {
23
32
  useValue?: SqbClientConnectionOptions;
24
33
  }
34
+ /** Options for {@link SqbModule.forRootAsync}: connection options are produced by an injected factory function, e.g. to read them from a NestJS `ConfigService`. */
25
35
  export interface SqbModuleAsyncOptions extends BaseModuleOptions, Partial<Pick<ModuleMetadata, 'imports'>> {
36
+ /** Providers to inject as arguments into `useFactory`. */
26
37
  inject?: any[];
38
+ /** Produces the connection options, optionally asynchronously, from the providers listed in `inject`. */
27
39
  useFactory?: (...args: any[]) => Promise<SqbClientConnectionOptions> | SqbClientConnectionOptions;
28
40
  }
29
41
  export {};
package/sqb.module.d.ts CHANGED
@@ -1,6 +1,20 @@
1
1
  import { type DynamicModule } from '@nestjs/common';
2
2
  import type { SqbModuleAsyncOptions, SqbModuleOptions } from './sqb.interface.js';
3
+ /**
4
+ * NestJS module registering an `@sqb/connect` `SqbClient` (or a custom
5
+ * injection token) as an injectable provider, connecting it on application
6
+ * bootstrap and closing it on shutdown. A thin public wrapper delegating
7
+ * to {@link SqbCoreModule} for the actual provider setup.
8
+ */
3
9
  export declare class SqbModule {
10
+ /**
11
+ * Registers `@sqb/nestjs` with connection options given directly, e.g.
12
+ * `SqbModule.forRoot({ useValue: { dialect: 'postgres', host: '...' } })`.
13
+ */
4
14
  static forRoot(options?: SqbModuleOptions): DynamicModule;
15
+ /**
16
+ * Registers `@sqb/nestjs` with connection options produced by an
17
+ * injected factory, e.g. to read them from a NestJS `ConfigService`.
18
+ */
5
19
  static forRootAsync(options: SqbModuleAsyncOptions): DynamicModule;
6
20
  }
package/sqb.module.js CHANGED
@@ -2,13 +2,27 @@ var SqbModule_1;
2
2
  import { __decorate } from "tslib";
3
3
  import { Module } from '@nestjs/common';
4
4
  import { SqbCoreModule } from './sqb-core.module.js';
5
+ /**
6
+ * NestJS module registering an `@sqb/connect` `SqbClient` (or a custom
7
+ * injection token) as an injectable provider, connecting it on application
8
+ * bootstrap and closing it on shutdown. A thin public wrapper delegating
9
+ * to {@link SqbCoreModule} for the actual provider setup.
10
+ */
5
11
  let SqbModule = SqbModule_1 = class SqbModule {
12
+ /**
13
+ * Registers `@sqb/nestjs` with connection options given directly, e.g.
14
+ * `SqbModule.forRoot({ useValue: { dialect: 'postgres', host: '...' } })`.
15
+ */
6
16
  static forRoot(options) {
7
17
  return {
8
18
  module: SqbModule_1,
9
19
  imports: [SqbCoreModule.forRoot(options)],
10
20
  };
11
21
  }
22
+ /**
23
+ * Registers `@sqb/nestjs` with connection options produced by an
24
+ * injected factory, e.g. to read them from a NestJS `ConfigService`.
25
+ */
12
26
  static forRootAsync(options) {
13
27
  return {
14
28
  module: SqbModule_1,