@@ -12,8 +12,6 @@ import {
1212 ServerRegisterOptions ,
1313 ServerRegisterPluginObject ,
1414 ServerRegisterPluginObjectArray ,
15- DecorateName ,
16- DecorationMethod ,
1715 HandlerDecorationMethod ,
1816 PluginProperties
1917} from '../plugin' ;
@@ -53,6 +51,57 @@ import {
5351import { ServerOptions } from './options' ;
5452import { ServerState , ServerStateCookieOptions } from './state' ;
5553
54+ /**
55+ * The general case for decorators added via server.decorate.
56+ */
57+ export type DecorationMethod < T > = ( this : T , ...args : any [ ] ) => any ;
58+
59+ export type DecorateName = string | symbol ;
60+
61+ export type DecorationValue = object | any [ ] | boolean | number | string | symbol | Map < any , any > | Set < any > ;
62+
63+ type ReservedRequestKeys = (
64+ 'server' | 'url' | 'query' | 'path' | 'method' |
65+ 'mime' | 'setUrl' | 'setMethod' | 'headers' | 'id' |
66+ 'app' | 'plugins' | 'route' | 'auth' | 'pre' |
67+ 'preResponses' | 'info' | 'isInjected' | 'orig' |
68+ 'params' | 'paramsArray' | 'payload' | 'state' |
69+ 'response' | 'raw' | 'domain' | 'log' | 'logs' |
70+ 'generateResponse' |
71+
72+ // Private functions
73+ '_allowInternals' | '_closed' | '_core' |
74+ '_entity' | '_eventContext' | '_events' | '_expectContinue' |
75+ '_isInjected' | '_isPayloadPending' | '_isReplied' |
76+ '_route' | '_serverTimeoutId' | '_states' | '_url' |
77+ '_urlError' | '_initializeUrl' | '_setUrl' | '_parseUrl' |
78+ '_parseQuery'
79+
80+ ) ;
81+
82+ type ReservedToolkitKeys = (
83+ 'abandon' | 'authenticated' | 'close' | 'context' | 'continue' |
84+ 'entity' | 'redirect' | 'realm' | 'request' | 'response' |
85+ 'state' | 'unauthenticated' | 'unstate'
86+ ) ;
87+
88+ type ReservedServerKeys = (
89+ // Public functions
90+ 'app' | 'auth' | 'cache' | 'decorations' | 'events' | 'info' |
91+ 'listener' | 'load' | 'methods' | 'mime' | 'plugins' | 'registrations' |
92+ 'settings' | 'states' | 'type' | 'version' | 'realm' | 'control' | 'decoder' |
93+ 'bind' | 'control' | 'decoder' | 'decorate' | 'dependency' | 'encoder' |
94+ 'event' | 'expose' | 'ext' | 'inject' | 'log' | 'lookup' | 'match' | 'method' |
95+ 'path' | 'register' | 'route' | 'rules' | 'state' | 'table' | 'validator' |
96+ 'start' | 'initialize' | 'stop' |
97+
98+ // Private functions
99+ '_core' | '_initialize' | '_start' | '_stop' | '_cachePolicy' | '_createCache' |
100+ '_clone' | '_ext' | '_addRoute'
101+ ) ;
102+
103+ type ExceptName < Property , ReservedKeys > = Property extends ReservedKeys ? never : Property ;
104+
56105/**
57106 * User-extensible type for application specific state (`server.app`).
58107 */
@@ -309,14 +358,24 @@ export class Server<A = ServerApplicationState> {
309358 * @return void;
310359 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverdecoratetype-property-method-options)
311360 */
312- decorate ( type : 'handler' , property : DecorateName , method : HandlerDecorationMethod , options ?: { apply ?: boolean | undefined , extend ?: boolean | undefined } ) : void ;
313- decorate ( type : 'request' , property : DecorateName , method : ( existing : ( ( ...args : any [ ] ) => any ) ) => ( request : Request ) => DecorationMethod < Request > , options : { apply : true , extend : true } ) : void ;
314- decorate ( type : 'request' , property : DecorateName , method : ( request : Request ) => DecorationMethod < Request > , options : { apply : true , extend ?: boolean | undefined } ) : void ;
315- decorate ( type : 'request' , property : DecorateName , method : DecorationMethod < Request > , options ?: { apply ?: boolean | undefined , extend ?: boolean | undefined } ) : void ;
316- decorate ( type : 'toolkit' , property : DecorateName , method : ( existing : ( ( ...args : any [ ] ) => any ) ) => DecorationMethod < ResponseToolkit > , options : { apply ?: boolean | undefined , extend : true } ) : void ;
317- decorate ( type : 'toolkit' , property : DecorateName , method : DecorationMethod < ResponseToolkit > , options ?: { apply ?: boolean | undefined , extend ?: boolean | undefined } ) : void ;
318- decorate ( type : 'server' , property : DecorateName , method : ( existing : ( ( ...args : any [ ] ) => any ) ) => DecorationMethod < Server > , options : { apply ?: boolean | undefined , extend : true } ) : void ;
319- decorate ( type : 'server' , property : DecorateName , method : DecorationMethod < Server > , options ?: { apply ?: boolean | undefined , extend ?: boolean | undefined } ) : void ;
361+ decorate < P extends DecorateName > ( type : 'handler' , property : P , method : HandlerDecorationMethod , options ?: { apply ?: boolean | undefined , extend ?: never } ) : void ;
362+
363+ decorate < P extends DecorateName > ( type : 'request' , property : ExceptName < P , ReservedRequestKeys > , method : ( existing : ( ( ...args : any [ ] ) => any ) ) => ( request : Request ) => DecorationMethod < Request > , options : { apply : true , extend : true } ) : void ;
364+ decorate < P extends DecorateName > ( type : 'request' , property : ExceptName < P , ReservedRequestKeys > , method : ( request : Request ) => DecorationMethod < Request > , options : { apply : true , extend ?: boolean | undefined } ) : void ;
365+ decorate < P extends DecorateName > ( type : 'request' , property : ExceptName < P , ReservedRequestKeys > , method : DecorationMethod < Request > , options ?: { apply ?: boolean | undefined , extend ?: boolean | undefined } ) : void ;
366+ decorate < P extends DecorateName > ( type : 'request' , property : ExceptName < P , ReservedRequestKeys > , value : ( existing : ( ( ...args : any [ ] ) => any ) ) => ( request : Request ) => any , options : { apply : true , extend : true } ) : void ;
367+ decorate < P extends DecorateName > ( type : 'request' , property : ExceptName < P , ReservedRequestKeys > , value : ( request : Request ) => any , options : { apply : true , extend ?: boolean | undefined } ) : void ;
368+ decorate < P extends DecorateName > ( type : 'request' , property : ExceptName < P , ReservedRequestKeys > , value : DecorationValue , options ?: never ) : void ;
369+
370+ decorate < P extends DecorateName > ( type : 'toolkit' , property : ExceptName < P , ReservedToolkitKeys > , method : ( existing : ( ( ...args : any [ ] ) => any ) ) => DecorationMethod < ResponseToolkit > , options : { apply ?: boolean | undefined , extend : true } ) : void ;
371+ decorate < P extends DecorateName > ( type : 'toolkit' , property : ExceptName < P , ReservedToolkitKeys > , method : DecorationMethod < ResponseToolkit > , options ?: { apply ?: boolean | undefined , extend ?: boolean | undefined } ) : void ;
372+ decorate < P extends DecorateName > ( type : 'toolkit' , property : ExceptName < P , ReservedToolkitKeys > , value : ( existing : ( ( ...args : any [ ] ) => any ) ) => any , options : { apply ?: boolean | undefined , extend : true } ) : void ;
373+ decorate < P extends DecorateName > ( type : 'toolkit' , property : ExceptName < P , ReservedToolkitKeys > , value : DecorationValue , options ?: never ) : void ;
374+
375+ decorate < P extends DecorateName > ( type : 'server' , property : ExceptName < P , ReservedServerKeys > , method : ( existing : ( ( ...args : any [ ] ) => any ) ) => DecorationMethod < Server > , options : { apply ?: boolean | undefined , extend : true } ) : void ;
376+ decorate < P extends DecorateName > ( type : 'server' , property : ExceptName < P , ReservedServerKeys > , method : DecorationMethod < Server > , options ?: { apply ?: boolean | undefined , extend ?: boolean | undefined } ) : void ;
377+ decorate < P extends DecorateName > ( type : 'server' , property : ExceptName < P , ReservedServerKeys > , value : ( existing : ( ( ...args : any [ ] ) => any ) ) => any , options : { apply ?: boolean | undefined , extend : true } ) : void ;
378+ decorate < P extends DecorateName > ( type : 'server' , property : ExceptName < P , ReservedServerKeys > , value : DecorationValue , options ?: never ) : void ;
320379
321380 /**
322381 * Used within a plugin to declare a required dependency on other plugins where:
0 commit comments