@whatwg-node/server 0.9.63 → 0.9.64-alpha-20241217102918-0325896dc8d5dcea60bb717d44cccfdb5bd69677
Sign up to get free protection for your applications and to get access to all the features.
@@ -31,7 +31,9 @@ function createServerAdapter(serverAdapterBaseObject, options) {
|
|
31
31
|
function ensureDisposableStack() {
|
32
32
|
if (!_disposableStack) {
|
33
33
|
_disposableStack = new disposablestack_1.AsyncDisposableStack();
|
34
|
-
|
34
|
+
if (options?.disposeOnProcessTerminate) {
|
35
|
+
(0, utils_js_1.ensureDisposableStackRegisteredForTerminateEvents)(_disposableStack);
|
36
|
+
}
|
35
37
|
_disposableStack.defer(() => {
|
36
38
|
if (waitUntilPromises.size > 0) {
|
37
39
|
return Promise.allSettled(waitUntilPromises).then(() => {
|
@@ -63,10 +65,17 @@ function createServerAdapter(serverAdapterBaseObject, options) {
|
|
63
65
|
if (plugin.onResponse) {
|
64
66
|
onResponseHooks.push(plugin.onResponse);
|
65
67
|
}
|
66
|
-
const disposeFn = plugin[disposablestack_1.DisposableSymbols.
|
67
|
-
if (disposeFn
|
68
|
+
const disposeFn = plugin[disposablestack_1.DisposableSymbols.dispose];
|
69
|
+
if (disposeFn) {
|
68
70
|
ensureDisposableStack().defer(disposeFn);
|
69
71
|
}
|
72
|
+
const asyncDisposeFn = plugin[disposablestack_1.DisposableSymbols.asyncDispose];
|
73
|
+
if (asyncDisposeFn) {
|
74
|
+
ensureDisposableStack().defer(asyncDisposeFn);
|
75
|
+
}
|
76
|
+
if (plugin.onDispose) {
|
77
|
+
ensureDisposableStack().defer(plugin.onDispose);
|
78
|
+
}
|
70
79
|
}
|
71
80
|
}
|
72
81
|
const handleRequest = onRequestHooks.length > 0 || onResponseHooks.length > 0
|
@@ -27,7 +27,9 @@ function createServerAdapter(serverAdapterBaseObject, options) {
|
|
27
27
|
function ensureDisposableStack() {
|
28
28
|
if (!_disposableStack) {
|
29
29
|
_disposableStack = new AsyncDisposableStack();
|
30
|
-
|
30
|
+
if (options?.disposeOnProcessTerminate) {
|
31
|
+
ensureDisposableStackRegisteredForTerminateEvents(_disposableStack);
|
32
|
+
}
|
31
33
|
_disposableStack.defer(() => {
|
32
34
|
if (waitUntilPromises.size > 0) {
|
33
35
|
return Promise.allSettled(waitUntilPromises).then(() => {
|
@@ -59,10 +61,17 @@ function createServerAdapter(serverAdapterBaseObject, options) {
|
|
59
61
|
if (plugin.onResponse) {
|
60
62
|
onResponseHooks.push(plugin.onResponse);
|
61
63
|
}
|
62
|
-
const disposeFn = plugin[DisposableSymbols.
|
63
|
-
if (disposeFn
|
64
|
+
const disposeFn = plugin[DisposableSymbols.dispose];
|
65
|
+
if (disposeFn) {
|
64
66
|
ensureDisposableStack().defer(disposeFn);
|
65
67
|
}
|
68
|
+
const asyncDisposeFn = plugin[DisposableSymbols.asyncDispose];
|
69
|
+
if (asyncDisposeFn) {
|
70
|
+
ensureDisposableStack().defer(asyncDisposeFn);
|
71
|
+
}
|
72
|
+
if (plugin.onDispose) {
|
73
|
+
ensureDisposableStack().defer(plugin.onDispose);
|
74
|
+
}
|
66
75
|
}
|
67
76
|
}
|
68
77
|
const handleRequest = onRequestHooks.length > 0 || onResponseHooks.length > 0
|
package/package.json
CHANGED
@@ -3,6 +3,14 @@ import { FetchAPI, ServerAdapter, ServerAdapterBaseObject, ServerAdapterRequestH
|
|
3
3
|
export interface ServerAdapterOptions<TServerContext> {
|
4
4
|
plugins?: ServerAdapterPlugin<TServerContext>[];
|
5
5
|
fetchAPI?: Partial<FetchAPI>;
|
6
|
+
/**
|
7
|
+
* Node.js only!
|
8
|
+
*
|
9
|
+
* If true, the server adapter will dispose itself when the process is terminated.
|
10
|
+
* If false, you have to dispose the server adapter by using the `dispose` method,
|
11
|
+
* or [Explicit Resource Management](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html)
|
12
|
+
*/
|
13
|
+
disposeOnProcessTerminate?: boolean;
|
6
14
|
}
|
7
15
|
declare function createServerAdapter<TServerContext = {}, THandleRequest extends ServerAdapterRequestHandler<TServerContext> = ServerAdapterRequestHandler<TServerContext>>(serverAdapterRequestHandler: THandleRequest, options?: ServerAdapterOptions<TServerContext>): ServerAdapter<TServerContext, ServerAdapterBaseObject<TServerContext, THandleRequest>>;
|
8
16
|
declare function createServerAdapter<TServerContext, TBaseObject extends ServerAdapterBaseObject<TServerContext>>(serverAdapterBaseObject: TBaseObject, options?: ServerAdapterOptions<TServerContext>): ServerAdapter<TServerContext, TBaseObject>;
|
@@ -3,6 +3,14 @@ import { FetchAPI, ServerAdapter, ServerAdapterBaseObject, ServerAdapterRequestH
|
|
3
3
|
export interface ServerAdapterOptions<TServerContext> {
|
4
4
|
plugins?: ServerAdapterPlugin<TServerContext>[];
|
5
5
|
fetchAPI?: Partial<FetchAPI>;
|
6
|
+
/**
|
7
|
+
* Node.js only!
|
8
|
+
*
|
9
|
+
* If true, the server adapter will dispose itself when the process is terminated.
|
10
|
+
* If false, you have to dispose the server adapter by using the `dispose` method,
|
11
|
+
* or [Explicit Resource Management](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html)
|
12
|
+
*/
|
13
|
+
disposeOnProcessTerminate?: boolean;
|
6
14
|
}
|
7
15
|
declare function createServerAdapter<TServerContext = {}, THandleRequest extends ServerAdapterRequestHandler<TServerContext> = ServerAdapterRequestHandler<TServerContext>>(serverAdapterRequestHandler: THandleRequest, options?: ServerAdapterOptions<TServerContext>): ServerAdapter<TServerContext, ServerAdapterBaseObject<TServerContext, THandleRequest>>;
|
8
16
|
declare function createServerAdapter<TServerContext, TBaseObject extends ServerAdapterBaseObject<TServerContext>>(serverAdapterBaseObject: TBaseObject, options?: ServerAdapterOptions<TServerContext>): ServerAdapter<TServerContext, TBaseObject>;
|
@@ -21,16 +21,22 @@ export interface ServerAdapterPlugin<TServerContext = {}> {
|
|
21
21
|
onResponse?: OnResponseHook<TServerContext & ServerAdapterInitialContext>;
|
22
22
|
/**
|
23
23
|
* This hook is invoked when the server is being disposed.
|
24
|
-
* The server disposal is triggered either by the
|
24
|
+
* The server disposal is triggered either by the process termination or the explicit server disposal.
|
25
25
|
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html
|
26
26
|
*/
|
27
27
|
[Symbol.dispose]?: () => void;
|
28
28
|
/**
|
29
29
|
* This hook is invoked when the server is being disposed.
|
30
|
-
* The server disposal is triggered either by the
|
30
|
+
* The server disposal is triggered either by the process termination or the explicit server disposal.
|
31
31
|
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html
|
32
32
|
*/
|
33
33
|
[Symbol.asyncDispose]?: () => PromiseLike<void> | void;
|
34
|
+
/**
|
35
|
+
* This hook is invoked when the server is being disposed.
|
36
|
+
* The server disposal is triggered either by the process termination or the explicit server disposal.
|
37
|
+
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html
|
38
|
+
*/
|
39
|
+
onDispose?: () => PromiseLike<void> | void;
|
34
40
|
}
|
35
41
|
export type OnRequestHook<TServerContext> = (payload: OnRequestEventPayload<TServerContext>) => Promise<void> | void;
|
36
42
|
export interface OnRequestEventPayload<TServerContext> {
|
@@ -21,16 +21,22 @@ export interface ServerAdapterPlugin<TServerContext = {}> {
|
|
21
21
|
onResponse?: OnResponseHook<TServerContext & ServerAdapterInitialContext>;
|
22
22
|
/**
|
23
23
|
* This hook is invoked when the server is being disposed.
|
24
|
-
* The server disposal is triggered either by the
|
24
|
+
* The server disposal is triggered either by the process termination or the explicit server disposal.
|
25
25
|
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html
|
26
26
|
*/
|
27
27
|
[Symbol.dispose]?: () => void;
|
28
28
|
/**
|
29
29
|
* This hook is invoked when the server is being disposed.
|
30
|
-
* The server disposal is triggered either by the
|
30
|
+
* The server disposal is triggered either by the process termination or the explicit server disposal.
|
31
31
|
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html
|
32
32
|
*/
|
33
33
|
[Symbol.asyncDispose]?: () => PromiseLike<void> | void;
|
34
|
+
/**
|
35
|
+
* This hook is invoked when the server is being disposed.
|
36
|
+
* The server disposal is triggered either by the process termination or the explicit server disposal.
|
37
|
+
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html
|
38
|
+
*/
|
39
|
+
onDispose?: () => PromiseLike<void> | void;
|
34
40
|
}
|
35
41
|
export type OnRequestHook<TServerContext> = (payload: OnRequestEventPayload<TServerContext>) => Promise<void> | void;
|
36
42
|
export interface OnRequestEventPayload<TServerContext> {
|