const genericMessage = "Invariant Violation" ; const { setPrototypeOf = function ( obj , proto ) { obj . __proto__ = proto ; return obj ; } , } = Object as any ; export class InvariantError extends Error { framesToPop = 1 ; name = genericMessage ; constructor ( message = genericMessage ) { super ( typeof message === "number" ? `${ genericMessage }: ${ message } (see https://github.com/apollographql/invariant-packages)` : message ) ; setPrototypeOf ( this , InvariantError . prototype ) ; } } export function invariant ( condition , message ? ) { if ( ! condition ) { throw new InvariantError ( message ) ; } } const verbosityLevels = [ "debug" , "log" , "warn" , "error" , "silent" ] as const ; export type VerbosityLevel = ( typeof verbosityLevels ) [ number ] ; export type ConsoleMethodName = Exclude < VerbosityLevel , "silent" > ; let verbosityLevel = verbosityLevels . indexOf ( "log" ) ; function wrapConsoleMethod < M extends ConsoleMethodName > ( name ) { return function ( ) { if ( verbosityLevels . indexOf ( name ) >= verbosityLevel ) { const method = console [ name ] || console . log ; return method . apply ( console , arguments as any ) ; } } as ( typeof console ) [ M ] ; } export namespace invariant { export const debug = wrapConsoleMethod ( "debug" ) ; export const log = wrapConsoleMethod ( "log" ) ; export const warn = wrapConsoleMethod ( "warn" ) ; export const error = wrapConsoleMethod ( "error" ) ; } export function setVerbosity ( level ) { const old = verbosityLevels [ verbosityLevel ] ; verbosityLevel = Math . max ( 0 , verbosityLevels . indexOf ( level ) ) ; return old ; } export default invariant ;