UNPKG

@nerdware/ddb-single-table

Version:

A schema-based DynamoDB modeling tool, high-level API, and type-generator built to supercharge single-table designs!⚡

90 lines 3.68 kB
import type { ModelSchemaNestedAttributes, ModelSchemaAttributeConfig } from "../Schema/types/index.js"; import type { SetNonNullable } from "type-fest"; /** * This is the base `error` class for custom errors defined in this package. If the * `message` arg is anything other than a truthy string, then the resultant Error's * `message` property will be set to a default value. A second `fallbackMsg` arg can * be provided to override the default message. */ export declare class DdbSingleTableError extends Error { static readonly DEFAULT_MSG: string; readonly name: string; constructor(message?: unknown, fallbackMsg?: string); } /** * This error is used for network/connection errors. */ export declare class DdbConnectionError extends DdbSingleTableError implements SetNonNullable<NodeJS.ErrnoException, "code"> { static readonly DEFAULT_MSG: string; /** Dictionary of relevant, connection-related NodeJS `err.code` values. */ static readonly NODE_ERROR_CODES: { readonly ECONNREFUSED: "ECONNREFUSED"; }; /** The {@link NodeJS.ErrnoException|NodeJS error code}. */ readonly code: NonNullable<NodeJS.ErrnoException["code"]>; constructor(arg?: unknown); } /** * This error is thrown by schema-validation functions when a `TableKeysSchema` * or `ModelSchema` is invalid. * * The provided {@link SchemaValidationErrorPayload} is used to create an error * message formatted as follows: * * > `{schemaName} is invalid: {problem}.` */ export declare class SchemaValidationError extends DdbSingleTableError { static readonly DEFAULT_MSG: string; constructor(message: SchemaValidationErrorPayload); } /** * An object that may be passed to a `SchemaValidationError` for a standardized error message format. */ export type SchemaValidationErrorPayload = { schemaName: string; problem: string; }; /** * This error is thrown by Model `IOAction` functions when run-time input * data is invalid. */ export declare class ItemInputError extends DdbSingleTableError { static readonly DEFAULT_MSG: string; constructor(message?: unknown); } /** * This error is thrown by expression-generator utils when a run-time arg is invalid * (e.g., more than two K-V pairs for a `KeyConditionExpression`). * * To provide a consistent error message format, provide an [`InvalidExpressionErrorPayload`][err] * to the constructor. * * [err]: {@link InvalidExpressionErrorPayload} */ export declare class InvalidExpressionError extends DdbSingleTableError { static readonly DEFAULT_MSG: string; constructor(arg?: unknown); } /** * An object that may be passed to the `InvalidExpressionError` constructor for a * standardized error message format. */ export interface InvalidExpressionErrorPayload { /** The name of the expression being generated. */ expressionName: "ConditionExpression" | "KeyConditionExpression" | "UpdateExpression" | "FilterExpression" | "ProjectionExpression"; /** A short explanation as to why the `invalidValue` is invalid. */ problem: string; /** The invalid value. */ invalidValue: unknown; /** A short description/name of the invalid value. */ invalidValueDescription: string; } /** * Helper function which provides a consistent attribute identifier for error messages. */ export declare const getAttrErrID: (modelName: string, attrName: string, { alias }: Pick<ModelSchemaAttributeConfig, "alias">) => string; /** * Helper function which stringifies a nested schema for error messages. */ export declare const stringifyNestedSchema: (nestedSchema: ModelSchemaNestedAttributes, spaces?: number) => string; //# sourceMappingURL=errors.d.ts.map