import { NativeAttributeValue } from '@aws-sdk/lib-dynamodb'; import { $comparison, $size, $logical, $between, $in, $not, $exists, $type, $beginsWith, $contains } from './condition-symbols.js'; export { ConditionParserResult, parseCondition } from './condition-parser.js'; export { and } from './and.js'; export { beginsWith } from './begins-with.js'; export { between } from './between.js'; export { contains } from './contains.js'; export { equals } from './equals.js'; export { exists } from './exists.js'; export { greaterThan } from './greater-than.js'; export { greaterThanOrEqual } from './greater-than-or-equal.js'; export { isIn } from './is-in.js'; export { lessThan } from './less-than.js'; export { lessThanOrEqual } from './less-than-or-equal.js'; export { not } from './not.js'; export { notEquals } from './not-equals.js'; export { notExists } from './not-exists.js'; export { or } from './or.js'; export { size } from './size.js'; export { typeIs } from './type-is.js'; /** * These are the basic building block types for constructing DynamoDB condition expressions. * * See: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html */ /** * Represends a top-level attribute in a Dynamo item OR a nested attribute using dot notation. * * {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Syntax} */ type Operand = string; /** * Type for representing comparison operators in DynamoDB condition expressions. */ type ComparisonOperator = '=' | '<>' | '<' | '<=' | '>' | '>='; /** * Type for representing logical operators for combining two or more conditions in DynamoDB condition expressions. */ type LogicalOperator = 'AND' | 'OR'; /** * Type for representing DynamoDB attribute type descriptors used to check attribute types in condition expressions. */ type DynamoAttributeType = 'B' | 'BOOL' | 'BS' | 'L' | 'M' | 'N' | 'NS' | 'NULL' | 'S' | 'SS'; /** * Value expressions can be either native attribute values or size expressions in the context of a condition expression. */ type ValueExpression = NativeAttributeValue | SizeExpression; /** * Represents a comparison between an operand and a value using a comparison operator. */ type ComparisonExpression = { type: typeof $comparison; operand: Operand; operator: ComparisonOperator; value: ValueExpression; }; /** * Same as ComparisonExpression but without the operand (for use in templates) */ type ComparisonExpressionTemplate = Omit; /** * Represents a logical combination of multiple condition expressions using a logical operator. */ type LogicalExpression = { type: typeof $logical; operator: LogicalOperator; subConditions: ConditionExpressionTemplate[]; }; /** * Represents a BETWEEN expression: `` BETWEEN `` AND `` */ type BetweenExpression = { type: typeof $between; operand: Operand; lowerValue: ValueExpression; upperValue: ValueExpression; }; /** * Same as BetweenExpression but without the operand (for use in templates) */ type BetweenExpressionTemplate = Omit; /** * Represents an IN expression: `` IN (``, ``, ...) */ type InExpression = { type: typeof $in; operand: Operand; values: ValueExpression[]; }; /** * Same as InExpression but without the operand (for use in templates) */ type InExpressionTemplate = Omit; /** * Represents a NOT expression that negates a condition expression. */ type NotExpression = { type: typeof $not; condition: ConditionExpressionTemplate; }; /** * Represents an EXISTS expression: attribute_exists(``) or attribute_not_exists(``) */ type ExistsExpression = { type: typeof $exists; operand: Operand; not?: true; }; /** * Same as ExistsExpression but without the operand (for use in templates) */ type ExistsExpressionTemplate = Omit; /** * Represents a TYPE check expression: attribute_type(``, ``) */ type TypeCheckExpression = { type: typeof $type; operand: Operand; attributeType: DynamoAttributeType; }; /** * Same as TypeCheckExpression but without the operand (for use in templates) */ type TypeCheckExpressionTemplate = Omit; /** * Represents a BEGINS WITH expression: begins_with(``, ``) */ type BeginsWithExpression = { type: typeof $beginsWith; operand: Operand; prefix: string; }; /** * Same as BeginsWithExpression but without the operand (for use in templates) */ type BeginsWithExpressionTemplate = Omit; /** * Represents a CONTAINS expression: contains(``, ``) */ type ContainsExpression = { type: typeof $contains; operand: Operand; substringOrElement: NativeAttributeValue; }; /** * Same as ContainsExpression but without the operand (for use in templates) */ type ContainsExpressionTemplate = Omit; /** * Represents a SIZE expression: size(``) */ type SizeExpression = { type: typeof $size; attribute: Operand; }; /** * Represents a SIZE condition expression: size(``) `` `` */ type SizeConditionExpression = { type: typeof $size; operand: Operand; operator: ComparisonOperator; value: NativeAttributeValue; }; /** * Same as SizeConditionExpression but without the operand (for use in templates) */ type SizeConditionExpressionTemplate = Omit; /** * All functions that evaluate to a boolean value in condition expressions */ type BooleanExpression = ExistsExpression | TypeCheckExpression | BeginsWithExpression | ContainsExpression; /** * All function expressions that return a value */ type FunctionExpression = BooleanExpression | SizeExpression; /** * All expressions that can be used within a condition template */ type TemplateExpression = Omit; /** * Implicit AND between all attributes in the template * This is an object where keys are operands and values are either values or template expressions */ type ConditionTemplate = Record; /** * All expressions that result in a boolean */ type ConditionExpression = ComparisonExpression | LogicalExpression | BetweenExpression | InExpression | NotExpression | BooleanExpression | SizeConditionExpression; /** * A condition template or a condition expression. * - A template is an object where keys are operands and values are either values or template expressions. * - An expression is a structured representation of a condition using the defined expression types. */ type ConditionExpressionTemplate = ConditionExpression | ConditionTemplate; /** * A condition can be a single condition expression/template or an array of them (implicitly ANDed) */ type Condition = ConditionExpressionTemplate | ConditionExpressionTemplate[]; export type { BeginsWithExpression, BeginsWithExpressionTemplate, BetweenExpression, BetweenExpressionTemplate, BooleanExpression, ComparisonExpression, ComparisonExpressionTemplate, ComparisonOperator, Condition, ConditionExpression, ConditionExpressionTemplate, ConditionTemplate, ContainsExpression, ContainsExpressionTemplate, DynamoAttributeType, ExistsExpression, ExistsExpressionTemplate, FunctionExpression, InExpression, InExpressionTemplate, LogicalExpression, LogicalOperator, NotExpression, Operand, SizeConditionExpression, SizeConditionExpressionTemplate, SizeExpression, TemplateExpression, TypeCheckExpression, TypeCheckExpressionTemplate, ValueExpression };