import { CallSite } from 'callsites'; import { TypeGuard as TypeGuard$1 } from 'inferred-types'; type TypeSubtype = `${T}/${S}`; /** * Defines the structure of a [Brilliant Error](https://github.com/inocan-group/brilliant-errors). */ interface IBrilliantError extends Error { /** a static identifier to ensure that this is a brilliant error */ kind: "BrilliantError"; /** the **Name** of the error given when error was configured */ name: N; /** * specifies the API which the error constructor will provide */ constructorType: C; /** * The configured **App**'s name (this can be left undefined); alternatively * a library author may indicate the library name as being the "app". */ app: A; /** * The **code** is the first segment of the "classification" string and * therefore the higher-level scope description of the error. */ code: T; subType: S; /** * The representative HTTP status code associated with this error */ httpStatus: C extends "network" ? H : H | undefined; /** * The classification of an error into a type/sub-type. * * Note: the "type" can also be found as an independant prop `code` for the * error. Likewise, the subType is defined as prop on the error as well. */ classification: TypeSubtype; /** * An array of stack elements instead of stringified version typically * returned. */ structuredStack: CallSite[]; /** the function (or class method) which the error occurred in */ fn: string | null; filename: string | null; /** the line number where the error occurred */ line: number | null; toJSON(): { app: A; name: string; message: string; classification: TypeSubtype; httpStatus: H; code: T; subType: S; fn: string | null; line: number | null; }; } declare abstract class BaseBrilliance< /** type */ T extends string = string, /** sub-type */ S extends string = string, /** http status codes */ H extends number = number, /** name */ N extends string = string, /** origin */ O extends string = string> extends Error { readonly kind = "BrilliantError"; /** The error's name */ readonly name: N; /** the originating application or service */ readonly origin: O; /** * The classification of an error into a type/sub-type */ readonly classification: TypeSubtype; /** * The major type from the error's classification */ readonly type: T; /** * The minor type/subtype from the error's classification */ readonly subType: S; /** * An HTTP numeric error code */ readonly httpStatus?: H; readonly structuredStack: CallSite[]; /** the function (or class method) which the error occurred in */ readonly fn: string | null; readonly filename: string | null; /** the line number where the error occurred */ readonly line: number | null; } /** * The constructor when using a "network" error from Brilliant Errors */ type NetworkConstructor = (code: H, message: string, options?: { classification?: TypeSubtype; }) => R; type WrapperConstructor = (underlying: Error, classification: TypeSubtype, options?: { message?: string; httpErrorCode?: H; }) => R; type StandardConstructor = (message: string, classification: TypeSubtype, options?: IErrorRuntimeOptions | undefined) => R; type ErrorConstructorType = "standard" | "network" | "wrapper"; /** configuration options when setting up an Error class */ type IErrorConfigOptions = { constructorType?: C; defaultHttpStatus?: number; requireHttpStatus?: boolean; defaultType?: T; defaultSubType?: S; }; type IErrorRuntimeOptions = { httpStatusCode?: H; }; type BrilliantErrorTuple = [ ConstructorFor, TypeGuard$1>, BrilliantErrorTypeGuard ]; /** * Add any additional _options_ for the error type */ type ErrorOptions = (options?: IErrorConfigOptions) => BrilliantErrorTuple; /** enter the numeric error codes that this error can throw; leaving it empty will allow all numeric codes */ type ErrorHttpCodes = (...httpCodes: H[]) => ErrorOptions; type ErrorSubTypes = (...subTypes: S[]) => ErrorHttpCodes; type ErrorTypes = (...types: T[]) => ErrorSubTypes; type IConstructorProps = { name: N; app: A; types: T[]; subTypes: S[]; httpCodes: H[]; configOptions: IErrorConfigOptions; }; type ConstructorFor = C extends "standard" ? Constructor>, IBrilliantError> : C extends "network" ? Constructor>, IBrilliantError> : C extends "wrapper" ? Constructor>, IBrilliantError> : never; /** * Provides a default type if `T` is undefined */ type IfUndefined = undefined extends T ? D : T; /** if `I` extends `T` then return as `T`, otherwise change type to `D` */ type IfNotThen = I extends T ? I : D; /** * Define a class constructor; allowing strong typing for constructor's parameters * and the returned class structure. */ type Constructor = new (...props: Ctor) => Klass; type TypeGuard = TypeGuard$1; declare function isBrilliantError(error: unknown): error is IBrilliantError; type BrilliantErrorTypeGuard = typeof isBrilliantError; /** * Create an error type and type guard using brilliant errors. */ declare const createError: (name: N, app: A) => ErrorTypes; declare function prettyStack(s: CallSite[]): string; export { BaseBrilliance, BrilliantErrorTuple, BrilliantErrorTypeGuard, Constructor, ConstructorFor, ErrorConstructorType, ErrorHttpCodes, ErrorOptions, ErrorSubTypes, ErrorTypes, IBrilliantError, IConstructorProps, IErrorConfigOptions, IErrorRuntimeOptions, IfNotThen, IfUndefined, NetworkConstructor, StandardConstructor, TypeGuard, TypeSubtype, WrapperConstructor, createError, isBrilliantError, prettyStack };