import is from "is" ; import objectPath from "object-path" ; const logged = { } ; const disabled = { } ; param { Book | Output } book param { string } key param { string } message function logNotice ( book , key , message ) { if ( logged [ key ] || disabled [ key ] ) return ; logged [ key ] = true ; const logger = book . getLogger ( ) ; logger . warn . ln ( message ) ; } param { Book | Output } book param { string } key param { Function } fn param { string } msg return { Function } function deprecateMethod ( book , key , fn , msg ) { return function ( ) { logNotice ( book , key , msg ) ; return fn . apply ( this , arguments ) ; } ; } param { Book | Output } book param { string } key param { Object } instance param { String | Function } property param { string } msg return { Function } function deprecateField ( book , key , instance , property , value , msg ) { let store = undefined ; const prepare = function ( ) { if ( ! is . undefined ( store ) ) return ; if ( is . fn ( value ) ) store = value ( ) ; else store = value ; } ; const getter = function ( ) { prepare ( ) ; logNotice ( book , key , msg ) ; return store ; } ; const setter = function ( v ) { prepare ( ) ; logNotice ( book , key , msg ) ; store = v ; return store ; } ; Object . defineProperty ( instance , property , { get : getter , set : setter , enumerable : true , configurable : true , } ) ; } param { string } key function enableDeprecation ( key ) { disabled [ key ] = false ; } param { string } key function disableDeprecation ( key ) { disabled [ key ] = true ; } param { Book } book param { string } key param { Object } instance param { string } oldName param { string } newName function deprecateRenamedMethod ( book , key , instance , oldName , newName , msg ) { msg = msg || `"${ oldName }" is deprecated, use "${ newName }()" instead` ; const fn = objectPath . get ( instance , newName ) ; instance [ oldName ] = deprecateMethod ( book , key , fn , msg ) ; } export default { method : deprecateMethod , renamedMethod : deprecateRenamedMethod , field : deprecateField , enable : enableDeprecation , disable : disableDeprecation , } ;