UNPKG

@nova-odm/expressions

Version:

Composable expression objects for Amazon DynamoDB

176 lines (175 loc) 7.23 kB
import { AttributePath } from "./AttributePath"; import { AttributeValue } from "./AttributeValue"; import { ExpressionAttributes } from "./ExpressionAttributes"; import { FunctionExpression } from "./FunctionExpression"; export type ComparisonOperand = AttributePath | AttributeValue | FunctionExpression | any; export interface BinaryComparisonPredicate { /** * The value against which the comparison subject will be compared. */ object: ComparisonOperand; } /** * A comparison predicate asserting that the subject and object are equal. */ export interface EqualityExpressionPredicate extends BinaryComparisonPredicate { type: 'Equals'; } /** * Create an expression predicate asserting that the subject is equal to the * predicate. */ export declare function equals(operand: ComparisonOperand): EqualityExpressionPredicate; /** * A comparison predicate asserting that the subject and object are not equal. */ export interface InequalityExpressionPredicate extends BinaryComparisonPredicate { type: 'NotEquals'; } export declare function notEquals(operand: ComparisonOperand): InequalityExpressionPredicate; /** * A comparison predicate asserting that the subject is less than the object. */ export interface LessThanExpressionPredicate extends BinaryComparisonPredicate { type: 'LessThan'; } export declare function lessThan(operand: ComparisonOperand): LessThanExpressionPredicate; /** * A comparison predicate asserting that the subject is less than or equal to * the object. */ export interface LessThanOrEqualToExpressionPredicate extends BinaryComparisonPredicate { type: 'LessThanOrEqualTo'; } export declare function lessThanOrEqualTo(operand: ComparisonOperand): LessThanOrEqualToExpressionPredicate; /** * A comparison predicate asserting that the subject is greater than the object. */ export interface GreaterThanExpressionPredicate extends BinaryComparisonPredicate { type: 'GreaterThan'; } export declare function greaterThan(operand: ComparisonOperand): GreaterThanExpressionPredicate; /** * A comparison predicate asserting that the subject is greater than or equal * to the object. */ export interface GreaterThanOrEqualToExpressionPredicate extends BinaryComparisonPredicate { type: 'GreaterThanOrEqualTo'; } export declare function greaterThanOrEqualTo(operand: ComparisonOperand): GreaterThanOrEqualToExpressionPredicate; /** * A comparison predicate asserting that the subject is between two bounds. */ export interface BetweenExpressionPredicate { type: 'Between'; lowerBound: ComparisonOperand; upperBound: ComparisonOperand; } export declare function between(lowerBound: ComparisonOperand, upperBound: ComparisonOperand): BetweenExpressionPredicate; /** * A comparison predicate asserting that the subject is equal to any member of * the provided list of values. */ export interface MembershipExpressionPredicate { type: 'Membership'; values: Array<ComparisonOperand>; } export declare function inList(...operands: Array<ComparisonOperand>): MembershipExpressionPredicate; /** * An object structure used as the base of all function expression predicates. */ export interface BaseFunctionExpressionPredicate { type: 'Function'; name: string; } /** * A comparison predicate asserting that the subject is contained in a given * record. */ export interface AttributeExistsPredicate extends BaseFunctionExpressionPredicate { name: 'attribute_exists'; } export declare function attributeExists(): AttributeExistsPredicate; /** * A comparison predicate asserting that the subject is **not** contained in a * given record. */ export interface AttributeNotExistsPredicate extends BaseFunctionExpressionPredicate { name: 'attribute_not_exists'; } export declare function attributeNotExists(): AttributeNotExistsPredicate; export type AttributeType = 'S' | 'SS' | 'N' | 'NS' | 'B' | 'BS' | 'BOOL' | 'NULL' | 'L' | 'M'; /** * A comparison predicate asserting that the subject is of the specified type. */ export interface AttributeTypePredicate extends BaseFunctionExpressionPredicate { name: 'attribute_type'; expected: AttributeType; } export declare function attributeType(expected: AttributeType): AttributeTypePredicate; /** * A comparison predicate asserting that the value of the subject in a given * record begins with the specified string. */ export interface BeginsWithPredicate extends BaseFunctionExpressionPredicate { name: 'begins_with'; expected: string; } export declare function beginsWith(expected: string): BeginsWithPredicate; /** * A comparison predicate asserting that the value of the subject in a given * record contains the specified string. */ export interface ContainsPredicate extends BaseFunctionExpressionPredicate { name: 'contains'; expected: string; } export declare function contains(expected: string): ContainsPredicate; export type FunctionExpressionPredicate = AttributeExistsPredicate | AttributeNotExistsPredicate | AttributeTypePredicate | BeginsWithPredicate | ContainsPredicate; export type ConditionExpressionPredicate = EqualityExpressionPredicate | InequalityExpressionPredicate | LessThanExpressionPredicate | LessThanOrEqualToExpressionPredicate | GreaterThanExpressionPredicate | GreaterThanExpressionPredicate | GreaterThanOrEqualToExpressionPredicate | BetweenExpressionPredicate | MembershipExpressionPredicate | FunctionExpressionPredicate; /** * Evaluate whether the provided value is a condition expression predicate. */ export declare function isConditionExpressionPredicate(arg: any): arg is ConditionExpressionPredicate; export interface ConditionExpressionSubject { /** * The path to the item attribute containing the subject of the comparison. */ subject: AttributePath | string; } export declare function isConditionExpressionSubject(arg: any): arg is ConditionExpressionSubject; export type SimpleConditionExpression = ConditionExpressionSubject & ConditionExpressionPredicate; export type ConditionExpression = SimpleConditionExpression | AndExpression | OrExpression | NotExpression | FunctionExpression; /** * A comparison expression asserting that all conditions in the provided list * are true. */ export interface AndExpression { type: 'And'; conditions: Array<ConditionExpression>; } /** * A comparison expression asserting that one or more conditions in the provided * list are true. */ export interface OrExpression { type: 'Or'; conditions: Array<ConditionExpression>; } /** * A comparison expression asserting that the provided condition is not true. */ export interface NotExpression { type: 'Not'; condition: ConditionExpression; } /** * Evaluates whether the provided value is a condition expression. */ export declare function isConditionExpression(arg: any): arg is ConditionExpression; /** * Convert the provided condition expression object to a string, escaping any * values and attributes to expression-safe placeholders whose expansion value * will be managed by the provided ExpressionAttributes object. */ export declare function serializeConditionExpression(condition: ConditionExpression, attributes: ExpressionAttributes): string;