Skip to content

Commit

Permalink
fix(server): types
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Nov 25, 2024
1 parent cc625d7 commit 5a9098c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-spiders-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@whatwg-node/server': patch
---

Fix on plugin types
21 changes: 9 additions & 12 deletions packages/server/src/createServerAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,15 @@ function createServerAdapter<

if (options?.plugins != null) {
for (const plugin of options.plugins) {
if (plugin != null) {
if (plugin.onRequest) {
onRequestHooks.push(plugin.onRequest);
}
if (plugin.onResponse) {
onResponseHooks.push(plugin.onResponse);
}
const disposeFn =
plugin[DisposableSymbols.asyncDispose] || plugin[DisposableSymbols.dispose];
if (disposeFn != null) {
disposableStack.defer(disposeFn);
}
if (plugin.onRequest) {
onRequestHooks.push(plugin.onRequest);
}
if (plugin.onResponse) {
onResponseHooks.push(plugin.onResponse);
}
const disposeFn = plugin[DisposableSymbols.asyncDispose] || plugin[DisposableSymbols.dispose];
if (disposeFn != null) {
disposableStack.defer(disposeFn);
}
}
}
Expand Down
15 changes: 6 additions & 9 deletions packages/server/src/plugins/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ import {
type ServerAdapterInitialContext,
} from '../types.js';

export type ServerAdapterPlugin<TServerContext = {}> =
| {
onRequest?: OnRequestHook<TServerContext & ServerAdapterInitialContext>;
onResponse?: OnResponseHook<TServerContext & ServerAdapterInitialContext>;
[Symbol.dispose]?: () => void;
[Symbol.asyncDispose]?: () => PromiseLike<void> | void;
}
| undefined;

export interface ServerAdapterPlugin<TServerContext = {}> {
onRequest?: OnRequestHook<TServerContext & ServerAdapterInitialContext>;
onResponse?: OnResponseHook<TServerContext & ServerAdapterInitialContext>;
[Symbol.dispose]?: () => void;
[Symbol.asyncDispose]?: () => PromiseLike<void> | void;
}
export type OnRequestHook<TServerContext> = (
payload: OnRequestEventPayload<TServerContext>,
) => Promise<void> | void;
Expand Down

0 comments on commit 5a9098c

Please sign in to comment.