UNPKG

@aws-lambda-powertools/jmespath

Version:

A type safe and modern jmespath module to parse and extract data from JSON documents using JMESPath

177 lines 6.25 kB
import type { Token } from './types.js'; /** * Base class for errors thrown during expression parsing and evaluation. */ declare class JMESPathError extends Error { /** * Expression that was being parsed when the error occurred. * Can be set by whatever catches the error. */ expression?: string; constructor(message: string); /** * Set the expression that was being parsed when the error occurred. * * The separate method allows the expression to be set after the error is * thrown. In some instances the expression is not known until after the * error is thrown (i.e. the error is thrown down the call stack). * * @param expression The expression that was being parsed when the error occurred. */ setExpression(expression: string): void; } /** * Error thrown when an unknown token is encountered during the AST construction. */ declare class LexerError extends JMESPathError { /** * Position in the expression where the error occurred. */ lexerPosition: number; /** * Token value where the error occurred. */ lexerValue: string; constructor(lexerPosition: number, lexerValue: string); } /** * Error thrown when an invalid or unexpected token type or value is encountered during parsing. */ declare class ParseError extends JMESPathError { /** * Position in the expression where the error occurred. */ lexPosition: number; /** * Additional information about the error. */ reason?: string; /** * Token type where the error occurred. */ tokenType: Token['type']; /** * Token value where the error occurred. */ tokenValue: Token['value']; constructor(options: { lexPosition: number; tokenValue: Token['value']; tokenType: Token['type']; reason?: string; }); } /** * Error thrown when an incomplete expression is encountered during parsing. */ declare class IncompleteExpressionError extends ParseError { constructor(options: { lexPosition: number; tokenValue: Token['value']; tokenType: Token['type']; reason?: string; }); } /** * Error thrown when an empty expression is encountered during parsing. */ declare class EmptyExpressionError extends JMESPathError { constructor(); } /** * Base class for errors thrown during function execution. * * When writing a JMESPath expression, you can use functions to transform the * data. For example, the `abs()` function returns the absolute value of a number. * * If an error occurs during function execution, the error is thrown as a * subclass of `FunctionError`. The subclass is determined by the type of error * that occurred. * * Errors can be thrown while validating the arguments passed to a function, or * while executing the function itself. */ declare class FunctionError extends JMESPathError { /** * Function that was being executed when the error occurred. * Can be set by whatever catches the error. */ functionName?: string; constructor(message: string); /** * Set the function that was being validated or executed when the error occurred. * * The separate method allows the name to be set after the error is * thrown. In most cases the error is thrown down the call stack, but we want * to show the actual function name used in the expression rather than an internal * alias. To avoid passing the function name down the call stack, we set it * after the error is thrown. * * @param functionName The function that was being validated or executed when the error occurred. */ setEvaluatedFunctionName(functionName: string): void; } /** * Error thrown when an unexpected argument is passed to a function. * * Function arguments are validated before the function is executed. If an * invalid argument is passed, the error is thrown. For example, the `abs()` * function expects exactly one argument. If more than one argument is passed, * an `ArityError` is thrown. */ declare class ArityError extends FunctionError { actualArity: number; expectedArity: number; constructor(options: { expectedArity: number; actualArity: number; }); protected pluralize(word: string, count: number): string; } /** * Error thrown when an unexpected number of arguments is passed to a variadic function. * * Variadic functions are functions that accept a variable number of arguments. * For example, the `max()` function accepts any number of arguments and returns * the largest one. If no arguments are passed, it returns `null`. * * If the number of arguments passed to a variadic function is not within the * expected range, this error is thrown. */ declare class VariadicArityError extends ArityError { constructor(options: { expectedArity: number; actualArity: number; }); } /** * Error thrown when an invalid argument type is passed to a built-in function. * * Function arguments are validated before the function is executed. If an * invalid argument type is found, this error is thrown. For example, the * `abs()` function expects a number as its argument. If a string is passed * instead, this error is thrown. */ declare class JMESPathTypeError extends FunctionError { actualType: string; currentValue: unknown; expectedTypes: string[]; constructor(options: { currentValue: unknown; actualType: string; expectedTypes: string[]; }); protected serializeExpectedTypes(): string; } /** * Error thrown when an unknown function is used in an expression. * * When evaluating a JMESPath expression, the interpreter looks up the function * name in a table of built-in functions, as well as any custom functions * provided by the user. If the function name is not found, this error is thrown. */ declare class UnknownFunctionError extends FunctionError { constructor(funcName: string); } export { ArityError, EmptyExpressionError, IncompleteExpressionError, JMESPathError, JMESPathTypeError, LexerError, ParseError, UnknownFunctionError, VariadicArityError, }; //# sourceMappingURL=errors.d.ts.map