@@ -21,6 +21,8 @@ export const defaultEventMap = {
2121 remove : 'removed'
2222}
2323
24+ export const defaultServiceEvents = Object . values ( defaultEventMap )
25+
2426export const protectedMethods = Object . keys ( Object . prototype )
2527 . concat ( Object . keys ( EventEmitter . prototype ) )
2628 . concat ( [ 'all' , 'around' , 'before' , 'after' , 'error' , 'hooks' , 'setup' , 'teardown' , 'publish' ] )
@@ -33,18 +35,16 @@ export function getHookMethods(service: any, options: ServiceOptions) {
3335 . concat ( methods )
3436}
3537
36- export function getServiceOptions ( service : any , options : ServiceOptions = { } ) : ServiceOptions {
37- const existingOptions = service [ SERVICE ]
38-
39- if ( existingOptions ) {
40- return existingOptions
41- }
38+ export function getServiceOptions ( service : any ) : ServiceOptions {
39+ return service [ SERVICE ]
40+ }
4241
42+ export const normalizeServiceOptions = ( service : any , options : ServiceOptions = { } ) : ServiceOptions => {
4343 const {
4444 methods = defaultServiceMethods . filter ( ( method ) => typeof service [ method ] === 'function' ) ,
4545 events = service . events || [ ]
4646 } = options
47- const { serviceEvents = Object . values ( defaultEventMap ) . concat ( events ) } = options
47+ const serviceEvents = options . serviceEvents || defaultServiceEvents . concat ( events )
4848
4949 return {
5050 ...options ,
@@ -61,7 +61,7 @@ export function wrapService(location: string, service: any, options: ServiceOpti
6161 }
6262
6363 const protoService = Object . create ( service )
64- const serviceOptions = getServiceOptions ( service , options )
64+ const serviceOptions = normalizeServiceOptions ( service , options )
6565
6666 if ( Object . keys ( serviceOptions . methods ) . length === 0 && typeof service . setup !== 'function' ) {
6767 throw new Error ( `Invalid service object passed for path \`${ location } \`` )
0 commit comments