@nestjs/core 10.4.6 → 10.4.8

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 CHANGED
@@ -94,7 +94,7 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
94
94
  <td><a href="https://www.mercedes-benz.com/" target="_blank"><img src="https://nestjs.com/img/logos/mercedes-logo.png" width="100" valign="middle" /></a></td>
95
95
  <td><a href="https://www.dinii.jp/" target="_blank"><img src="https://nestjs.com/img/logos/dinii-logo.png" width="65" valign="middle" /></a></td>
96
96
  <td><a href="https://bloodycase.com/?promocode=NEST" target="_blank"><img src="https://nestjs.com/img/logos/bloodycase-logo.png" width="65" valign="middle" /></a></td>
97
- <td><a href="https://handsontable.com/docs/react-data-grid/?utm_source=NestJS_GH&utm_medium=sponsorship&utm_campaign=library_sponsorship_2024" target="_blank"><img src="https://nestjs.com/img/logos/handsontable-logo.svg" width="150" valign="middle" /></a></td>
97
+ <td><a href="https://handsontable.com/docs/react-data-grid/?utm_source=NestJS_GH&utm_medium=sponsorship&utm_campaign=library_sponsorship_2024" target="_blank"><img src="https://nestjs.com/img/logos/handsontable-dark-logo.svg#2" width="150" valign="middle" /></a></td>
98
98
  <td align="center" valign="middle"><a href="https://www.itflashcards.com/" target="_blank"><img src="https://nestjs.com/img/logos/it_flashcards-logo.png" width="170" valign="middle" /></a></td>
99
99
  <td align="center" valign="middle"><a href="https://arcjet.com/?ref=nestjs" target="_blank"><img src="https://nestjs.com/img/logos/arcjet-logo.svg" width="170" valign="middle" /></a></td>
100
100
  </tr>
@@ -1,3 +1,4 @@
1
+ import { Observable } from 'rxjs';
1
2
  import { AbstractHttpAdapter } from '../adapters/http-adapter';
2
3
  /**
3
4
  * Defines the `HttpAdapterHost` object.
@@ -13,6 +14,8 @@ import { AbstractHttpAdapter } from '../adapters/http-adapter';
13
14
  */
14
15
  export declare class HttpAdapterHost<T extends AbstractHttpAdapter = AbstractHttpAdapter> {
15
16
  private _httpAdapter?;
17
+ private _listen$;
18
+ private isListening;
16
19
  /**
17
20
  * Accessor for the underlying `HttpAdapter`
18
21
  *
@@ -26,4 +29,17 @@ export declare class HttpAdapterHost<T extends AbstractHttpAdapter = AbstractHtt
26
29
  * `const httpAdapter = adapterHost.httpAdapter;`
27
30
  */
28
31
  get httpAdapter(): T;
32
+ /**
33
+ * Observable that allows to subscribe to the `listen` event.
34
+ * This event is emitted when the HTTP application is listening for incoming requests.
35
+ */
36
+ get listen$(): Observable<void>;
37
+ /**
38
+ * Sets the listening state of the application.
39
+ */
40
+ set listening(listening: boolean);
41
+ /**
42
+ * Returns a boolean indicating whether the application is listening for incoming requests.
43
+ */
44
+ get listening(): boolean;
29
45
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HttpAdapterHost = void 0;
4
+ const rxjs_1 = require("rxjs");
4
5
  /**
5
6
  * Defines the `HttpAdapterHost` object.
6
7
  *
@@ -14,6 +15,10 @@ exports.HttpAdapterHost = void 0;
14
15
  * @publicApi
15
16
  */
16
17
  class HttpAdapterHost {
18
+ constructor() {
19
+ this._listen$ = new rxjs_1.Subject();
20
+ this.isListening = false;
21
+ }
17
22
  /**
18
23
  * Accessor for the underlying `HttpAdapter`
19
24
  *
@@ -31,5 +36,28 @@ class HttpAdapterHost {
31
36
  get httpAdapter() {
32
37
  return this._httpAdapter;
33
38
  }
39
+ /**
40
+ * Observable that allows to subscribe to the `listen` event.
41
+ * This event is emitted when the HTTP application is listening for incoming requests.
42
+ */
43
+ get listen$() {
44
+ return this._listen$.asObservable();
45
+ }
46
+ /**
47
+ * Sets the listening state of the application.
48
+ */
49
+ set listening(listening) {
50
+ this.isListening = listening;
51
+ if (listening) {
52
+ this._listen$.next();
53
+ this._listen$.complete();
54
+ }
55
+ }
56
+ /**
57
+ * Returns a boolean indicating whether the application is listening for incoming requests.
58
+ */
59
+ get listening() {
60
+ return this.isListening;
61
+ }
34
62
  }
35
63
  exports.HttpAdapterHost = HttpAdapterHost;
@@ -70,6 +70,7 @@ class Injector {
70
70
  await this.resolveConstructorParams(wrapper, moduleRef, inject, callback, contextId, wrapper, inquirer);
71
71
  }
72
72
  catch (err) {
73
+ wrapper.removeInstanceByContextId(this.getContextId(contextId, wrapper), inquirerId);
73
74
  settlementSignal.error(err);
74
75
  throw err;
75
76
  }
@@ -62,6 +62,8 @@ export declare class InstanceWrapper<T = any> {
62
62
  getInstanceByInquirerId(contextId: ContextId, inquirerId: string): InstancePerContext<T>;
63
63
  setInstanceByContextId(contextId: ContextId, value: InstancePerContext<T>, inquirerId?: string): void;
64
64
  setInstanceByInquirerId(contextId: ContextId, inquirerId: string, value: InstancePerContext<T>): void;
65
+ removeInstanceByContextId(contextId: ContextId, inquirerId?: string): void;
66
+ removeInstanceByInquirerId(contextId: ContextId, inquirerId: string): void;
65
67
  addCtorMetadata(index: number, wrapper: InstanceWrapper): void;
66
68
  getCtorMetadata(): InstanceWrapper[];
67
69
  addPropertiesMetadata(key: symbol | string, wrapper: InstanceWrapper): void;
@@ -75,6 +75,19 @@ class InstanceWrapper {
75
75
  }
76
76
  collection.set(contextId, value);
77
77
  }
78
+ removeInstanceByContextId(contextId, inquirerId) {
79
+ if (this.scope === common_1.Scope.TRANSIENT && inquirerId) {
80
+ return this.removeInstanceByInquirerId(contextId, inquirerId);
81
+ }
82
+ this.values.delete(contextId);
83
+ }
84
+ removeInstanceByInquirerId(contextId, inquirerId) {
85
+ const collection = this.transientMap.get(inquirerId);
86
+ if (!collection) {
87
+ return;
88
+ }
89
+ collection.delete(contextId);
90
+ }
78
91
  addCtorMetadata(index, wrapper) {
79
92
  if (!this[exports.INSTANCE_METADATA_SYMBOL].dependencies) {
80
93
  this[exports.INSTANCE_METADATA_SYMBOL].dependencies = [];
@@ -24,6 +24,7 @@ export declare class NestApplicationContext<TOptions extends NestApplicationCont
24
24
  private shutdownCleanupRef?;
25
25
  private _instanceLinksHost;
26
26
  private _moduleRefsForHooksByDistance?;
27
+ private initializationPromise?;
27
28
  protected get instanceLinksHost(): InstanceLinksHost;
28
29
  constructor(container: NestContainer, appOptions?: TOptions, contextModule?: Module, scope?: Type<any>[]);
29
30
  selectContextModule(): void;
@@ -97,8 +97,17 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
97
97
  if (this.isInitialized) {
98
98
  return this;
99
99
  }
100
- await this.callInitHook();
101
- await this.callBootstrapHook();
100
+ this.initializationPromise = new Promise(async (resolve, reject) => {
101
+ try {
102
+ await this.callInitHook();
103
+ await this.callBootstrapHook();
104
+ resolve();
105
+ }
106
+ catch (err) {
107
+ reject(err);
108
+ }
109
+ });
110
+ await this.initializationPromise;
102
111
  this.isInitialized = true;
103
112
  return this;
104
113
  }
@@ -107,6 +116,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
107
116
  * @returns {Promise<void>}
108
117
  */
109
118
  async close(signal) {
119
+ await this.initializationPromise;
110
120
  await this.callDestroyHook();
111
121
  await this.callBeforeShutdownHook(signal);
112
122
  await this.dispose();
@@ -184,6 +194,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
184
194
  return;
185
195
  }
186
196
  receivedSignal = true;
197
+ await this.initializationPromise;
187
198
  await this.callDestroyHook();
188
199
  await this.callBeforeShutdownHook(signal);
189
200
  await this.dispose();
@@ -166,7 +166,10 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
166
166
  }
167
167
  async listen(port, ...args) {
168
168
  this.assertNotInPreviewMode('listen');
169
- !this.isInitialized && (await this.init());
169
+ if (!this.isInitialized) {
170
+ await this.init();
171
+ }
172
+ const httpAdapterHost = this.container.getHttpAdapterHostRef();
170
173
  return new Promise((resolve, reject) => {
171
174
  const errorHandler = (e) => {
172
175
  this.logger.error(e?.toString?.());
@@ -188,6 +191,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
188
191
  if (address) {
189
192
  this.httpServer.removeListener('error', errorHandler);
190
193
  this.isListening = true;
194
+ httpAdapterHost.listening = true;
191
195
  resolve(this.httpServer);
192
196
  }
193
197
  if (isCallbackInOriginalArgs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/core",
3
- "version": "10.4.6",
3
+ "version": "10.4.8",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@core)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -36,7 +36,7 @@
36
36
  "uid": "2.0.2"
37
37
  },
38
38
  "devDependencies": {
39
- "@nestjs/common": "10.4.6"
39
+ "@nestjs/common": "10.4.8"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@nestjs/common": "^10.0.0",
@@ -1,10 +1,10 @@
1
1
  import { ArgumentMetadata, PipeTransform } from '@nestjs/common/interfaces';
2
2
  export declare class PipesConsumer {
3
3
  private readonly paramsTokenFactory;
4
- apply<TInput = unknown>(value: TInput, { metatype, type, data }: ArgumentMetadata, pipes: PipeTransform[]): Promise<TInput>;
4
+ apply<TInput = unknown>(value: TInput, { metatype, type, data }: ArgumentMetadata, pipes: PipeTransform[]): Promise<any>;
5
5
  applyPipes<TInput = unknown>(value: TInput, { metatype, type, data }: {
6
6
  metatype: any;
7
7
  type?: any;
8
8
  data?: any;
9
- }, transforms: PipeTransform[]): Promise<TInput>;
9
+ }, transforms: PipeTransform[]): Promise<any>;
10
10
  }