@abw/badger-database
Version:
Javascript database abstraction layer
156 lines • 5.65 kB
TypeScript
/**
* Function to throw a generic error used to report a missing configration item.
* The error message will be of the form `No "XXX" specified`.
* @example
* ```ts
* missing('badger'); // throws error: No "badger" specified
* ```
*/
export declare const missing: (item: string) => never;
/**
* Function to throw a generic error used to report an invalid configuration
* item. The error message will be of the form `Invalid "XXX" specified: YYY`.
* @example
* ```ts
* invalid('badger', 99); // throws error: Invalid "badger" specified: 99
* ```
*/
export declare const invalid: (item: string, value: any) => never;
/**
* Function to throw a generic error reporting that a method is not implemented.
* This is used in base classes (e.g. {@link Engine}) where subclasses are
* required to implement the method. The error message will be of the form
* `METHOD is not implemented in MODULE`.
* @example
* ```ts
* notImplemented('wibble', 'FrussetPouch'); // throws error: wibble is not implemented in FrussetPouch
* ```
*/
export declare const notImplemented: (method: string, module: string) => never;
/**
* Currying function used to generate a function that calls {@link notImplemented}
* with the module name pre-defined.
* @param {!String} module - the name of the module
* @example
* ```ts
* const thrower = notImplementedInModule('FrussetPouch');
* thrower('wibble'); // throws error: wibble is not implemented in FrussetPouch
* ```
*/
export declare const notImplementedInModule: (module: string) => (method: string) => never;
/**
* Wrapper around {@link notImplementedInModule} which provides a
* more explicit error message for base classes.
* @param {!String} module - the name of the module
* @example
* ```ts
* const thrower = notImplementedInBaseClass('FrussetPouch');
* thrower('wibble'); // throws error: wibble is not implemented in the FrussetPouch base class
* ```
*/
export declare const notImplementedInBaseClass: (module: string) => (method: string) => never;
/**
* Error class for generating custom errors.
*/
export declare class CustomError extends Error {
constructor(message: string);
}
interface SQLParseErrorArgs {
message: string;
type?: string | number;
code?: string | number;
position?: string | number;
stack?: typeof Error.prototype.stack;
}
export declare class SQLParseError extends Error {
query?: string;
type?: string | number;
code?: string | number;
position?: string | number;
stack?: typeof Error.prototype.stack;
constructor(query: string, args: SQLParseErrorArgs);
}
/**
* Error class for reporting failure to load engine driver
*/
export declare class EngineDriverError extends CustomError {
}
export declare const throwEngineDriver: (module: string, error: Error) => never;
/**
* Error class for reporting unexpected number of rows returned by a
* database query.
*/
export declare class UnexpectedRowCount extends CustomError {
}
/**
* Error class for reporting columns validation errors, e.g. when
* attempting to update a `readonly` column.
*/
export declare class ColumnValidationError extends CustomError {
}
/**
* Error class for reporting validation errors when inserting a row.
*/
export declare class InsertValidationError extends CustomError {
}
/**
* Error class for reporting attempts to update a deleted record.
*/
export declare class DeletedRecordError extends CustomError {
}
/**
* Error class for reporting query builder errors
*/
export declare class QueryBuilderError extends CustomError {
}
/**
* Error class for reporting transaction errors
*/
export declare class TransactionError extends CustomError {
}
/**
* Function for throwing a {@link UnexpectedRowCount} error when multiple
* rows were returned or updated when only one was expected.
* @example
* ```ts
* // throw UnexpectedRowCount error with message "10 rows were returned when one was expected"
* unexpectedRowCount(10);
* ```
* @example
* ```ts
* // throw UnexpectedRowCount error with message "10 rows were updated when one was expected"
* unexpectedRowCount(10, 'updated');
* ```
*/
export declare function unexpectedRowCount(n: number, action?: string): void;
/**
* Function to construct a function for throwing errors of a particular type
* using message formats. The function returned expects a format name and
* an optional object containing values to insert into the message format.
* @example
* ```ts
* const hurl = thrower({ oops => 'Unexpected <animal> encountered });
* hurl('oops', 'badger'); // throws error: Unexpected badger encountered
* ```
*/
export declare const thrower: <T extends Record<string, string>>(formats: T, error?: new (message: string) => Error) => (fmt: keyof T, data: object) => never;
/**
* Error throwing function for column validation errors.
* @example
* ```ts
* throwColumnValidationError('readonly', { table: 'users', column: 'id' });
* // throws ColumnValidationError: The "id" column is readonly in the users table
* ```
*/
export declare const throwColumnValidationError: (fmt: "unknown" | "fixed" | "readonly" | "required" | "multipleIds" | "noColumns" | "invalidKey" | "invalidColumns" | "invalidColumn" | "invalidColumnSpec", data: object) => never;
/**
* Error throwing function for deleted record errors.
* @example
* ```ts
* throwDeletedRecordError('action', { action: 'update', table: 'users', id: 99 });
* // throws DeletedRecordError: Cannot update deleted users record #99
* ```
*/
export declare const throwDeletedRecordError: (fmt: "action", data: object) => never;
export {};
//# sourceMappingURL=Error.d.ts.map