Skip to content

Commit

Permalink
Pass ServerApplicationState to server extensions (hapijs#4413)
Browse files Browse the repository at this point in the history
  • Loading branch information
radoslavirha committed Mar 20, 2023
1 parent c6d881f commit a365c30
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/types/server/ext.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Server } from './server';
import { Server, ServerApplicationState } from './server';
import { ReqRef, ReqRefDefaults } from '../request';
import { Lifecycle } from '../utils';

Expand Down Expand Up @@ -46,7 +46,7 @@ export type ServerRequestExtType =
* when adding server extensions. Defaults to 'server' which applies to any route added to the server the extension is added to.
* @return void
*/
export interface ServerExtEventsObject {
export interface ServerExtEventsObject<A = ServerApplicationState> {
/**
* (required) the extension point event name. The available extension points include the request extension points as well as the following server extension points:
* * 'onPreStart' - called before the connection listeners are started.
Expand All @@ -61,7 +61,7 @@ export interface ServerExtEventsObject {
* * * this - the object provided via options.bind or the current active context set with server.bind().
* * request extension points: a lifecycle method.
*/
method: ServerExtPointFunction | ServerExtPointFunction[];
method: ServerExtPointFunction<A> | ServerExtPointFunction<A>[];
options?: ServerExtOptions | undefined;
}

Expand Down Expand Up @@ -120,7 +120,7 @@ export interface ServerExtEventsRequestObject {
options?: ServerExtOptions | undefined;
}

export type ServerExtPointFunction = (server: Server) => void;
export type ServerExtPointFunction<A = ServerApplicationState> = (server: Server<A>) => void;

/**
* An object with the following:
Expand Down
4 changes: 2 additions & 2 deletions lib/types/server/server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,14 @@ export class Server<A = ServerApplicationState> {
* @return void
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverextevents)
*/
ext(events: ServerExtEventsObject | ServerExtEventsObject[] | ServerExtEventsRequestObject | ServerExtEventsRequestObject[]): void;
ext(events: ServerExtEventsObject<A> | ServerExtEventsObject<A>[] | ServerExtEventsRequestObject | ServerExtEventsRequestObject[]): void;

/**
* Registers a single extension event using the same properties as used in server.ext(events), but passed as arguments.
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverextevent-method-options)
*/
ext(event: ServerExtType, method: ServerExtPointFunction, options?: ServerExtOptions | undefined): void;
ext(event: ServerExtType, method: ServerExtPointFunction<A>, options?: ServerExtOptions | undefined): void;
ext(event: ServerRequestExtType, method: Lifecycle.Method, options?: ServerExtOptions | undefined): void;

/**
Expand Down

0 comments on commit a365c30

Please sign in to comment.