dyno-table 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/builders/condition-check-builder.cjs.map +1 -1
- package/dist/builders/condition-check-builder.js.map +1 -1
- package/dist/builders/delete-builder.cjs.map +1 -1
- package/dist/builders/delete-builder.d.cts +1 -1
- package/dist/builders/delete-builder.d.ts +1 -1
- package/dist/builders/delete-builder.js.map +1 -1
- package/dist/builders/paginator.cjs.map +1 -1
- package/dist/builders/paginator.js.map +1 -1
- package/dist/builders/put-builder.cjs.map +1 -1
- package/dist/builders/put-builder.d.cts +1 -1
- package/dist/builders/put-builder.d.ts +1 -1
- package/dist/builders/put-builder.js.map +1 -1
- package/dist/builders/query-builder.cjs.map +1 -1
- package/dist/builders/query-builder.js.map +1 -1
- package/dist/builders/transaction-builder.cjs +33 -9
- package/dist/builders/transaction-builder.cjs.map +1 -1
- package/dist/builders/transaction-builder.js +33 -9
- package/dist/builders/transaction-builder.js.map +1 -1
- package/dist/builders/update-builder.cjs.map +1 -1
- package/dist/builders/update-builder.d.cts +1 -1
- package/dist/builders/update-builder.d.ts +1 -1
- package/dist/builders/update-builder.js.map +1 -1
- package/dist/entity.cjs +152 -84
- package/dist/entity.cjs.map +1 -1
- package/dist/entity.d.cts +1 -1
- package/dist/entity.d.ts +1 -1
- package/dist/entity.js +152 -84
- package/dist/entity.js.map +1 -1
- package/dist/{table-BW3cmUqr.d.ts → table-BelHPTvr.d.ts} +1 -1
- package/dist/{table-BEhBPy2G.d.cts → table-DIfupG_s.d.cts} +1 -1
- package/dist/table.cjs +34 -13
- package/dist/table.cjs.map +1 -1
- package/dist/table.d.cts +1 -1
- package/dist/table.d.ts +1 -1
- package/dist/table.js +34 -13
- package/dist/table.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/expression.ts","../../src/utils/debug-expression.ts","../../src/utils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AAED,IAAA,MAAM,MAAoC,GAAA;AAAA,MACxC,aAAe,EAAA,aAAA;AAAA,MACf,kBAAA,EAAoB,KAAK,OAAQ,CAAA,kBAAA;AAAA,MACjC,sBAAA,EAAwB,KAAK,OAAQ,CAAA,sBAAA;AAAA,MACrC,2BAAA,EAA6B,KAAK,OAAQ,CAAA;AAAA,KAC5C;AAEA,IAAI,IAAA;AACF,MAAM,MAAA,IAAA,CAAK,SAAS,MAAM,CAAA;AAAA,aACnB,KAAO,EAAA;AACd,MAAQ,OAAA,CAAA,GAAA,CAAI,IAAK,CAAA,KAAA,EAAO,CAAA;AACxB,MAAQ,OAAA,CAAA,KAAA,CAAM,gCAAgC,KAAK,CAAA;AACnD,MAAM,MAAA,KAAA;AAAA;AACR;AAEJ","file":"transaction-builder.js","sourcesContent":["import type { ComparisonOperator, Condition, ExpressionParams, LogicalOperator } from \"./conditions\";\n\nexport const generateAttributeName = (params: ExpressionParams, attr: string): string => {\n // Check if the attribute already exists in the expressionAttributeNames\n for (const [existingName, existingAttr] of Object.entries(params.expressionAttributeNames)) {\n if (existingAttr === attr) {\n return existingName;\n }\n }\n\n // If not found, create a new attribute name\n const attrName = `#${Object.keys(params.expressionAttributeNames).length}`;\n params.expressionAttributeNames[attrName] = attr;\n return attrName;\n};\n\nexport const generateValueName = (params: ExpressionParams, value: unknown): string => {\n const valueName = `:${params.valueCounter.count++}`;\n params.expressionAttributeValues[valueName] = value;\n return valueName;\n};\n\nconst validateCondition = (condition: Condition, requiresAttr = true, requiresValue = true): void => {\n if (requiresAttr && !condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n if (requiresValue && condition.value === undefined) {\n throw new Error(`Value is required for ${condition.type} condition`);\n }\n};\n\nconst buildComparisonExpression = (condition: Condition, operator: string, params: ExpressionParams): string => {\n validateCondition(condition);\n\n if (!condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n const attrName = generateAttributeName(params, condition.attr);\n const valueName = generateValueName(params, condition.value);\n\n return `${attrName} ${operator} ${valueName}`;\n};\n\nconst buildBetweenExpression = (condition: Condition, params: ExpressionParams): string => {\n validateCondition(condition);\n\n if (!condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n if (!Array.isArray(condition.value) || condition.value.length !== 2) {\n throw new Error(\"Between condition requires an array of two values\");\n }\n\n const attrName = generateAttributeName(params, condition.attr);\n const lowerName = generateValueName(params, condition.value[0]);\n const upperName = generateValueName(params, condition.value[1]);\n\n return `${attrName} BETWEEN ${lowerName} AND ${upperName}`;\n};\n\nconst buildFunctionExpression = (functionName: string, condition: Condition, params: ExpressionParams): string => {\n validateCondition(condition);\n\n if (!condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n const attrName = generateAttributeName(params, condition.attr);\n const valueName = generateValueName(params, condition.value);\n\n return `${functionName}(${attrName}, ${valueName})`;\n};\n\nconst buildAttributeFunction = (functionName: string, condition: Condition, params: ExpressionParams): string => {\n validateCondition(condition, true, false);\n\n if (!condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n const attrName = generateAttributeName(params, condition.attr);\n return `${functionName}(${attrName})`;\n};\n\nconst buildLogicalExpression = (operator: string, conditions: Condition[], params: ExpressionParams): string => {\n if (!conditions || conditions.length === 0) {\n throw new Error(`At least one condition is required for ${operator} expression`);\n }\n\n const expressions = conditions.map((c) => buildExpression(c, params));\n return `(${expressions.join(` ${operator} `)})`;\n};\n\nexport const buildExpression = (condition: Condition, params: ExpressionParams): string => {\n if (!condition) return \"\";\n\n try {\n // Map of condition types to their expression builders\n const expressionBuilders: Record<ComparisonOperator | LogicalOperator, () => string> = {\n eq: () => buildComparisonExpression(condition, \"=\", params),\n ne: () => buildComparisonExpression(condition, \"<>\", params),\n lt: () => buildComparisonExpression(condition, \"<\", params),\n lte: () => buildComparisonExpression(condition, \"<=\", params),\n gt: () => buildComparisonExpression(condition, \">\", params),\n gte: () => buildComparisonExpression(condition, \">=\", params),\n between: () => buildBetweenExpression(condition, params),\n beginsWith: () => buildFunctionExpression(\"begins_with\", condition, params),\n contains: () => buildFunctionExpression(\"contains\", condition, params),\n attributeExists: () => buildAttributeFunction(\"attribute_exists\", condition, params),\n attributeNotExists: () => buildAttributeFunction(\"attribute_not_exists\", condition, params),\n and: () => {\n if (!condition.conditions) {\n throw new Error(\"Conditions array is required for AND operator\");\n }\n return buildLogicalExpression(\"AND\", condition.conditions, params);\n },\n or: () => {\n if (!condition.conditions) {\n throw new Error(\"Conditions array is required for OR operator\");\n }\n return buildLogicalExpression(\"OR\", condition.conditions, params);\n },\n not: () => {\n if (!condition.condition) {\n throw new Error(\"Condition is required for NOT operator\");\n }\n return `NOT (${buildExpression(condition.condition, params)})`;\n },\n };\n\n const builder = expressionBuilders[condition.type];\n if (!builder) {\n throw new Error(`Unknown condition type: ${condition.type}`);\n }\n\n return builder();\n } catch (error: unknown) {\n if (error instanceof Error) {\n console.error(`Error building expression for condition type ${condition.type}:`, error.message);\n } else {\n console.error(`Error building expression for condition type ${condition.type}:`, error);\n }\n throw error;\n }\n};\n\nexport const prepareExpressionParams = (\n condition?: Condition,\n): {\n expression?: string;\n names?: Record<string, string>;\n values?: Record<string, unknown>;\n} => {\n if (!condition) return {};\n\n const params: ExpressionParams = {\n expressionAttributeNames: {},\n expressionAttributeValues: {},\n valueCounter: { count: 0 },\n };\n\n const expression = buildExpression(condition, params);\n\n return {\n expression,\n names: Object.keys(params.expressionAttributeNames).length > 0 ? params.expressionAttributeNames : undefined,\n values: Object.keys(params.expressionAttributeValues).length > 0 ? params.expressionAttributeValues : undefined,\n };\n};\n","/**\n * Interface for DynamoDB command objects that can contain expressions\n */\nexport interface DynamoCommandWithExpressions {\n conditionExpression?: string;\n updateExpression?: string;\n filterExpression?: string;\n keyConditionExpression?: string;\n projectionExpression?: string;\n expressionAttributeNames?: Record<string, string>;\n expressionAttributeValues?: Record<string, unknown>;\n [key: string]: unknown;\n}\n\ntype ReadableDynamoCommand = {\n conditionExpression?: string;\n updateExpression?: string;\n filterExpression?: string;\n keyConditionExpression?: string;\n projectionExpression?: string;\n};\n\n/**\n * Utility function to debug a DynamoDB command by replacing all placeholders\n * in expressions with their actual values.\n *\n * @param command Any DynamoDB command with expressions and attribute maps\n * @returns An object with the same structure but with readable expressions\n */\nexport function debugCommand<T extends DynamoCommandWithExpressions>(\n command: T,\n): {\n raw: T;\n readable: ReadableDynamoCommand;\n} {\n // Create a copy of the command\n const result: ReadableDynamoCommand = {};\n\n function replaceAliases(expressionString: string) {\n if (!expressionString) {\n return expressionString;\n }\n\n let replacedString = expressionString;\n for (const alias in command.expressionAttributeNames) {\n const attributeName = command.expressionAttributeNames[alias];\n const regex = new RegExp(alias, \"g\");\n\n replacedString = replacedString.replace(regex, attributeName as string);\n }\n\n for (const alias in command.expressionAttributeValues) {\n let attributeValue = command.expressionAttributeValues[alias];\n\n // Handle Set objects for better readability\n if (attributeValue instanceof Set) {\n const array = Array.from(attributeValue);\n attributeValue = `Set(${array.length}){${array.map((v) => JSON.stringify(v)).join(\", \")}}`;\n } else {\n // Stringify other values for display\n attributeValue = JSON.stringify(attributeValue);\n }\n\n const regex = new RegExp(alias, \"g\");\n replacedString = replacedString.replace(regex, attributeValue as string);\n }\n\n return replacedString;\n }\n\n if (command.updateExpression) {\n result.updateExpression = replaceAliases(command.updateExpression);\n }\n if (command.conditionExpression) {\n result.conditionExpression = replaceAliases(command.conditionExpression);\n }\n if (command.filterExpression) {\n result.filterExpression = replaceAliases(command.filterExpression);\n }\n if (command.keyConditionExpression) {\n result.keyConditionExpression = replaceAliases(command.keyConditionExpression);\n }\n if (command.projectionExpression) {\n result.projectionExpression = replaceAliases(command.projectionExpression);\n }\n\n return {\n raw: command,\n readable: result,\n };\n}\n","import type { TransactionItem } from \"../builders/builder-types\";\nimport { debugCommand } from \"./debug-expression\";\n\n/**\n * Utility function to create a human-readable representation of a transaction item\n * by replacing all expression placeholders with their actual values.\n *\n * @param item The transaction item to debug\n * @returns A readable representation of the transaction item\n */\nexport function debugTransactionItem(item: TransactionItem): Record<string, unknown> {\n const result: Record<string, unknown> = {\n type: item.type,\n tableName: item.params.tableName,\n };\n\n // Add key if present\n if (\"key\" in item.params) {\n result.key = item.params.key;\n }\n\n // Add item if present (for Put operations)\n if (item.type === \"Put\") {\n result.item = item.params.item;\n }\n\n // Add readable expressions based on operation type\n switch (item.type) {\n case \"Put\":\n case \"Delete\":\n case \"ConditionCheck\":\n result.readable = debugCommand(item.params).readable;\n break;\n case \"Update\":\n result.readable = debugCommand(item.params).readable;\n break;\n }\n\n return result;\n}\n\n/**\n * Utility function to create a human-readable representation of all transaction items\n * in a transaction by replacing all expression placeholders with their actual values.\n *\n * @param items Array of transaction items to debug\n * @returns An array of readable representations of the transaction items\n */\nexport function debugTransaction(items: TransactionItem[]): Record<string, unknown>[] {\n return items.map((item) => debugTransactionItem(item));\n}\n","import type { TransactWriteCommandInput } from \"@aws-sdk/lib-dynamodb\";\nimport type { Condition, PrimaryKeyWithoutExpression } from \"../conditions\";\nimport { prepareExpressionParams } from \"../expression\";\nimport { debugTransaction } from \"../utils/debug-transaction\";\nimport type {\n ConditionCheckCommandParams,\n DeleteCommandParams,\n PutCommandParams,\n TransactionItem,\n UpdateCommandParams,\n} from \"./builder-types\";\nimport type { DynamoItem } from \"../types\";\n\n/**\n * Configuration options for DynamoDB transactions.\n */\nexport interface TransactionOptions {\n /** Unique identifier for the transaction request (idempotency token) */\n clientRequestToken?: string;\n /** Level of consumed capacity details to return */\n returnConsumedCapacity?: \"INDEXES\" | \"TOTAL\" | \"NONE\";\n /** Whether to return item collection metrics */\n returnItemCollectionMetrics?: \"SIZE\" | \"NONE\";\n}\n\n/**\n * Configuration for table indexes used in duplicate detection.\n * Defines the key structure for checking uniqueness constraints.\n */\ninterface IndexConfig {\n /** The partition key attribute name */\n partitionKey: string;\n /** Optional sort key attribute name */\n sortKey?: string;\n}\n\n/**\n * Function type for executing DynamoDB transaction operations.\n * @param params - The complete transaction command input\n * @returns A promise that resolves when the transaction completes\n */\nexport type TransactionExecutor = (params: TransactWriteCommandInput) => Promise<void>;\n\n/**\n * Builder for creating and executing DynamoDB transactions.\n * Use this builder when you need to:\n * - Perform multiple operations atomically\n * - Ensure data consistency across operations\n * - Implement complex business logic that requires atomic updates\n * - Prevent duplicate items across tables\n *\n * The builder supports:\n * - Put operations (insert/replace items)\n * - Delete operations\n * - Update operations\n * - Condition checks\n * - Duplicate detection\n * - Transaction-wide options\n *\n * @example\n * ```typescript\n * // Create a transaction with multiple operations\n * const transaction = new TransactionBuilder(executor, {\n * partitionKey: 'id',\n * sortKey: 'type'\n * });\n *\n * // Add a new order\n * transaction.put('orders', {\n * orderId: '123',\n * status: 'PENDING'\n * });\n *\n * // Update inventory with condition\n * transaction.update(\n * 'inventory',\n * { productId: 'ABC' },\n * 'set quantity = quantity - :amount',\n * { ':amount': 1 },\n * op => op.gte('quantity', 1)\n * );\n *\n * // Execute the transaction atomically\n * await transaction.execute();\n * ```\n *\n * Note: DynamoDB transactions have some limitations:\n * - Maximum 25 operations per transaction\n * - All operations must be in the same AWS region\n * - Cannot include table scans or queries\n */\nexport class TransactionBuilder {\n private items: TransactionItem[] = [];\n private options: TransactionOptions = {};\n private indexConfig: IndexConfig;\n private readonly executor: TransactionExecutor;\n\n constructor(executor: TransactionExecutor, indexConfig: IndexConfig) {\n this.executor = executor;\n this.indexConfig = indexConfig;\n }\n\n /**\n * Checks if an item with the same primary key already exists in the transaction\n * @private\n */\n private checkForDuplicateItem(tableName: string, newItem: DynamoItem): void {\n const pkName = this.indexConfig.partitionKey;\n const skName = this.indexConfig.sortKey ?? \"\";\n\n // Extract the primary key values from the provided key\n const pkValue = newItem[pkName];\n const skValue = skName ? newItem[skName] : undefined;\n\n if (!pkValue) {\n throw new Error(`Primary key value for '${pkName}' is missing`);\n }\n\n const duplicateItem = this.items.find((item) => {\n // Get the key from the item based on its type\n let itemKey: Record<string, unknown> | undefined;\n let itemTableName: string | undefined;\n\n switch (item.type) {\n case \"Put\":\n itemTableName = item.params.tableName;\n // For Put operations, the key is part of the item\n itemKey = item.params.item;\n break;\n case \"Update\":\n case \"Delete\":\n case \"ConditionCheck\":\n itemTableName = item.params.tableName;\n itemKey = item.params.key;\n break;\n }\n\n // Check if the table name and keys match\n if (itemTableName === tableName && itemKey) {\n const itemPkValue = itemKey[pkName];\n const itemSkValue = skName ? itemKey[skName] : undefined;\n\n // Match if partition keys match and either both sort keys match or both are undefined\n if (itemPkValue === pkValue) {\n if (skValue === undefined && itemSkValue === undefined) {\n return true;\n }\n if (skValue !== undefined && itemSkValue !== undefined && skValue === itemSkValue) {\n return true;\n }\n }\n }\n\n return false;\n });\n\n if (duplicateItem) {\n throw new Error(\n `Duplicate item detected in transaction: Table=${tableName}, ${pkName}=${String(pkValue)}, ${skName}=${skValue !== undefined ? String(skValue) : \"undefined\"}. DynamoDB transactions do not allow multiple operations on the same item.`,\n );\n }\n }\n\n createKeyForPrimaryIndex(key: PrimaryKeyWithoutExpression) {\n // Turn the pk/sk into the key object\n const keyCondition = {\n [this.indexConfig.partitionKey]: key.pk,\n };\n\n if (this.indexConfig.sortKey) {\n if (key.sk === undefined) {\n throw new Error(\"Sort key is required for delete operation\");\n }\n keyCondition[this.indexConfig.sortKey] = key.sk;\n }\n\n return keyCondition;\n }\n\n /**\n * Adds a put operation to the transaction.\n * Use this method when you need to:\n * - Insert new items as part of a transaction\n * - Replace existing items atomically\n * - Ensure items meet certain conditions before insertion\n *\n * The method automatically checks for duplicate items within the transaction\n * to prevent multiple operations on the same item.\n *\n * @example\n * ```typescript\n * // Simple put operation\n * transaction.put('orders', {\n * orderId: '123',\n * status: 'PENDING',\n * amount: 100\n * });\n *\n * // Conditional put operation\n * transaction.put(\n * 'inventory',\n * { productId: 'ABC', quantity: 50 },\n * op => op.attributeNotExists('productId')\n * );\n *\n * // Put with complex condition\n * transaction.put(\n * 'users',\n * { userId: '123', status: 'ACTIVE' },\n * op => op.and([\n * op.attributeNotExists('userId'),\n * op.beginsWith('status', 'ACTIVE')\n * ])\n * );\n * ```\n *\n * @param tableName - The name of the DynamoDB table\n * @param item - The item to put into the table\n * @param condition - Optional condition that must be satisfied\n * @returns The transaction builder for method chaining\n * @throws {Error} If a duplicate item is detected in the transaction\n */\n put<T extends DynamoItem>(tableName: string, item: T, condition?: Condition): this {\n // Check for duplicate item\n this.checkForDuplicateItem(tableName, item);\n\n const transactionItem: TransactionItem = {\n type: \"Put\",\n params: {\n tableName,\n item,\n },\n };\n\n if (condition) {\n const { expression, names, values } = prepareExpressionParams(condition);\n transactionItem.params.conditionExpression = expression;\n transactionItem.params.expressionAttributeNames = names;\n transactionItem.params.expressionAttributeValues = values;\n }\n\n this.items.push(transactionItem);\n return this;\n }\n\n /**\n * Adds a pre-configured put operation to the transaction.\n * Use this method when you need to:\n * - Reuse put commands from PutBuilder\n * - Add complex put operations with pre-configured parameters\n * - Integrate with existing put command configurations\n *\n * This method is particularly useful when working with PutBuilder\n * to maintain consistency in put operations across your application.\n *\n * @example\n * ```typescript\n * // Create a put command with PutBuilder\n * const putCommand = new PutBuilder(executor, newItem, 'users')\n * .condition(op => op.attributeNotExists('userId'))\n * .toDynamoCommand();\n *\n * // Add the command to the transaction\n * transaction.putWithCommand(putCommand);\n * ```\n *\n * @param command - The complete put command configuration\n * @returns The transaction builder for method chaining\n * @throws {Error} If a duplicate item is detected in the transaction\n * @see PutBuilder for creating put commands\n */\n putWithCommand(command: PutCommandParams): TransactionBuilder {\n // Check for duplicate item\n this.checkForDuplicateItem(command.tableName, command.item);\n\n const transactionItem: TransactionItem = {\n type: \"Put\",\n params: command,\n };\n\n this.items.push(transactionItem);\n return this;\n }\n\n /**\n * Adds a delete operation to the transaction.\n * Use this method when you need to:\n * - Remove items as part of a transaction\n * - Conditionally delete items\n * - Ensure items exist before deletion\n *\n * The method automatically checks for duplicate items within the transaction\n * to prevent multiple operations on the same item.\n *\n * @example\n * ```typescript\n * // Simple delete operation\n * transaction.delete('orders', {\n * pk: 'ORDER#123',\n * sk: 'METADATA'\n * });\n *\n * // Conditional delete operation\n * transaction.delete(\n * 'users',\n * { pk: 'USER#123' },\n * op => op.eq('status', 'INACTIVE')\n * );\n *\n * // Delete with complex condition\n * transaction.delete(\n * 'products',\n * { pk: 'PROD#ABC' },\n * op => op.and([\n * op.eq('status', 'DRAFT'),\n * op.lt('version', 5)\n * ])\n * );\n * ```\n *\n * @param tableName - The name of the DynamoDB table\n * @param key - The primary key of the item to delete\n * @param condition - Optional condition that must be satisfied\n * @returns The transaction builder for method chaining\n * @throws {Error} If a duplicate item is detected in the transaction\n */\n delete(tableName: string, key: PrimaryKeyWithoutExpression, condition?: Condition): TransactionBuilder {\n const keyCondition = this.createKeyForPrimaryIndex(key);\n\n // Check for duplicate item\n this.checkForDuplicateItem(tableName, keyCondition);\n\n const transactionItem: TransactionItem = {\n type: \"Delete\",\n params: {\n tableName,\n key: keyCondition,\n },\n };\n\n if (condition) {\n const { expression, names, values } = prepareExpressionParams(condition);\n transactionItem.params.conditionExpression = expression;\n transactionItem.params.expressionAttributeNames = names;\n transactionItem.params.expressionAttributeValues = values;\n }\n\n this.items.push(transactionItem);\n return this;\n }\n\n /**\n * Adds a pre-configured delete operation to the transaction.\n * Use this method when you need to:\n * - Reuse delete commands from DeleteBuilder\n * - Add complex delete operations with pre-configured parameters\n * - Integrate with existing delete command configurations\n *\n * This method is particularly useful when working with DeleteBuilder\n * to maintain consistency in delete operations across your application.\n *\n * @example\n * ```typescript\n * // Create a delete command with DeleteBuilder\n * const deleteCommand = new DeleteBuilder(executor, 'users', { pk: 'USER#123' })\n * .condition(op => op.and([\n * op.attributeExists('pk'),\n * op.eq('status', 'INACTIVE')\n * ]))\n * .toDynamoCommand();\n *\n * // Add the command to the transaction\n * transaction.deleteWithCommand(deleteCommand);\n * ```\n *\n * @param command - The complete delete command configuration\n * @returns The transaction builder for method chaining\n * @throws {Error} If a duplicate item is detected in the transaction\n * @see DeleteBuilder for creating delete commands\n */\n deleteWithCommand(command: DeleteCommandParams): this {\n const keyCondition = this.createKeyForPrimaryIndex(command.key as PrimaryKeyWithoutExpression);\n // Check for duplicate item\n this.checkForDuplicateItem(command.tableName, keyCondition);\n\n const transactionItem: TransactionItem = {\n type: \"Delete\",\n params: {\n ...command,\n key: keyCondition,\n },\n };\n this.items.push(transactionItem);\n return this;\n }\n\n /**\n * Adds an update operation to the transaction.\n * Use this method when you need to:\n * - Modify existing items as part of a transaction\n * - Update multiple attributes atomically\n * - Apply conditional updates\n * - Perform complex attribute manipulations\n *\n * The method supports all DynamoDB update expressions:\n * - SET: Modify or add attributes\n * - REMOVE: Delete attributes\n * - ADD: Update numbers and sets\n * - DELETE: Remove elements from a set\n *\n * @example\n * ```typescript\n * // Simple update\n * transaction.update(\n * 'orders',\n * { pk: 'ORDER#123' },\n * 'SET #status = :status',\n * { '#status': 'status' },\n * { ':status': 'PROCESSING' }\n * );\n *\n * // Complex update with multiple operations\n * transaction.update(\n * 'products',\n * { pk: 'PROD#ABC' },\n * 'SET #qty = #qty - :amount, #status = :status REMOVE #oldAttr',\n * { '#qty': 'quantity', '#status': 'status', '#oldAttr': 'deprecated_field' },\n * { ':amount': 1, ':status': 'LOW_STOCK' }\n * );\n *\n * // Conditional update\n * transaction.update(\n * 'users',\n * { pk: 'USER#123' },\n * 'SET #lastLogin = :now',\n * { '#lastLogin': 'lastLoginDate' },\n * { ':now': new Date().toISOString() },\n * op => op.attributeExists('pk')\n * );\n * ```\n *\n * @param tableName - The name of the DynamoDB table\n * @param key - The primary key of the item to update\n * @param updateExpression - The update expression (SET, REMOVE, ADD, DELETE)\n * @param expressionAttributeNames - Map of attribute name placeholders to actual names\n * @param expressionAttributeValues - Map of value placeholders to actual values\n * @param condition - Optional condition that must be satisfied\n * @returns The transaction builder for method chaining\n * @throws {Error} If a duplicate item is detected in the transaction\n */\n update<T extends DynamoItem>(\n tableName: string,\n key: PrimaryKeyWithoutExpression,\n updateExpression: string,\n expressionAttributeNames?: Record<string, string>,\n expressionAttributeValues?: Record<string, unknown>,\n condition?: Condition,\n ): this {\n const keyCondition = this.createKeyForPrimaryIndex(key);\n\n // Check for duplicate item\n this.checkForDuplicateItem(tableName, keyCondition);\n\n const transactionItem: TransactionItem = {\n type: \"Update\",\n params: {\n tableName,\n key: keyCondition,\n updateExpression,\n expressionAttributeNames,\n expressionAttributeValues,\n },\n };\n\n if (condition) {\n const { expression, names, values } = prepareExpressionParams(condition);\n transactionItem.params.conditionExpression = expression;\n\n // Merge the condition expression attribute names and values with the update ones\n transactionItem.params.expressionAttributeNames = {\n ...transactionItem.params.expressionAttributeNames,\n ...names,\n };\n\n transactionItem.params.expressionAttributeValues = {\n ...transactionItem.params.expressionAttributeValues,\n ...values,\n };\n }\n\n this.items.push(transactionItem);\n return this;\n }\n\n /**\n * Adds a pre-configured update operation to the transaction.\n * Use this method when you need to:\n * - Reuse update commands from UpdateBuilder\n * - Add complex update operations with pre-configured parameters\n * - Integrate with existing update command configurations\n *\n * This method is particularly useful when working with UpdateBuilder\n * to maintain consistency in update operations across your application.\n *\n * @example\n * ```typescript\n * // Create an update command with UpdateBuilder\n * const updateCommand = new UpdateBuilder(executor, 'inventory', { pk: 'PROD#ABC' })\n * .set('quantity', ':qty')\n * .set('lastUpdated', ':now')\n * .values({\n * ':qty': 100,\n * ':now': new Date().toISOString()\n * })\n * .condition(op => op.gt('quantity', 0))\n * .toDynamoCommand();\n *\n * // Add the command to the transaction\n * transaction.updateWithCommand(updateCommand);\n * ```\n *\n * @param command - The complete update command configuration\n * @returns The transaction builder for method chaining\n * @throws {Error} If a duplicate item is detected in the transaction\n * @see UpdateBuilder for creating update commands\n */\n updateWithCommand(command: UpdateCommandParams): TransactionBuilder {\n const keyCondition = this.createKeyForPrimaryIndex(command.key as PrimaryKeyWithoutExpression);\n\n // Check for duplicate item\n this.checkForDuplicateItem(command.tableName, keyCondition);\n\n const transactionItem: TransactionItem = {\n type: \"Update\",\n params: {\n ...command,\n key: keyCondition,\n },\n };\n\n this.items.push(transactionItem);\n return this;\n }\n\n /**\n * Adds a condition check operation to the transaction.\n * Use this method when you need to:\n * - Validate item state without modifying it\n * - Ensure data consistency across tables\n * - Implement complex business rules\n * - Verify preconditions for other operations\n *\n * Condition checks are particularly useful for:\n * - Implementing optimistic locking\n * - Ensuring referential integrity\n * - Validating business rules atomically\n *\n * @example\n * ```typescript\n * // Check if order is in correct state\n * transaction.conditionCheck(\n * 'orders',\n * { pk: 'ORDER#123' },\n * op => op.eq('status', 'PENDING')\n * );\n *\n * // Complex condition check\n * transaction.conditionCheck(\n * 'inventory',\n * { pk: 'PROD#ABC' },\n * op => op.and([\n * op.gt('quantity', 0),\n * op.eq('status', 'ACTIVE'),\n * op.attributeExists('lastRestockDate')\n * ])\n * );\n *\n * // Check with multiple attributes\n * transaction.conditionCheck(\n * 'users',\n * { pk: 'USER#123' },\n * op => op.or([\n * op.eq('status', 'PREMIUM'),\n * op.gte('credits', 100)\n * ])\n * );\n * ```\n *\n * @param tableName - The name of the DynamoDB table\n * @param key - The primary key of the item to check\n * @param condition - The condition that must be satisfied\n * @returns The transaction builder for method chaining\n * @throws {Error} If a duplicate item is detected in the transaction\n * @throws {Error} If condition expression generation fails\n */\n conditionCheck(tableName: string, key: PrimaryKeyWithoutExpression, condition: Condition): TransactionBuilder {\n const keyCondition = this.createKeyForPrimaryIndex(key);\n\n // Check for duplicate item\n this.checkForDuplicateItem(tableName, keyCondition);\n\n const { expression, names, values } = prepareExpressionParams(condition);\n\n if (!expression) {\n throw new Error(\"Failed to generate condition expression\");\n }\n\n const transactionItem: TransactionItem = {\n type: \"ConditionCheck\",\n params: {\n tableName,\n key: keyCondition,\n conditionExpression: expression,\n expressionAttributeNames: names,\n expressionAttributeValues: values,\n },\n };\n\n this.items.push(transactionItem);\n return this;\n }\n\n /**\n * Adds a pre-configured condition check operation to the transaction.\n * Use this method when you need to:\n * - Reuse condition checks from ConditionCheckBuilder\n * - Add complex condition checks with pre-configured parameters\n * - Integrate with existing condition check configurations\n *\n * This method is particularly useful when working with ConditionCheckBuilder\n * to maintain consistency in condition checks across your application.\n *\n * @example\n * ```typescript\n * // Create a condition check with ConditionCheckBuilder\n * const checkCommand = new ConditionCheckBuilder('inventory', { pk: 'PROD#ABC' })\n * .condition(op => op.and([\n * op.between('quantity', 10, 100),\n * op.beginsWith('category', 'ELECTRONICS'),\n * op.attributeExists('lastAuditDate')\n * ]))\n * .toDynamoCommand();\n *\n * // Add the command to the transaction\n * transaction.conditionCheckWithCommand(checkCommand);\n * ```\n *\n * @param command - The complete condition check command configuration\n * @returns The transaction builder for method chaining\n * @throws {Error} If a duplicate item is detected in the transaction\n * @see ConditionCheckBuilder for creating condition check commands\n */\n conditionCheckWithCommand(command: ConditionCheckCommandParams): TransactionBuilder {\n const keyCondition = this.createKeyForPrimaryIndex(command.key as PrimaryKeyWithoutExpression);\n\n // Check for duplicate item\n this.checkForDuplicateItem(command.tableName, keyCondition);\n\n const transactionItem: TransactionItem = {\n type: \"ConditionCheck\",\n params: {\n ...command,\n key: keyCondition,\n },\n };\n this.items.push(transactionItem);\n return this;\n }\n\n /**\n * Sets options for the transaction execution.\n * Use this method when you need to:\n * - Enable idempotent transactions\n * - Track consumed capacity\n * - Monitor item collection metrics\n *\n * @example\n * ```typescript\n * // Enable idempotency and capacity tracking\n * transaction.withOptions({\n * clientRequestToken: 'unique-request-id-123',\n * returnConsumedCapacity: 'TOTAL'\n * });\n *\n * // Track item collection metrics\n * transaction.withOptions({\n * returnItemCollectionMetrics: 'SIZE'\n * });\n * ```\n *\n * Note: ClientRequestToken can be used to make transactions idempotent,\n * ensuring the same transaction is not executed multiple times.\n *\n * @param options - Configuration options for the transaction\n * @returns The transaction builder for method chaining\n */\n withOptions(options: TransactionOptions): TransactionBuilder {\n this.options = { ...this.options, ...options };\n return this;\n }\n\n /**\n * Gets a human-readable representation of the transaction items.\n * Use this method when you need to:\n * - Debug complex transactions\n * - Verify operation parameters\n * - Log transaction details\n * - Troubleshoot condition expressions\n *\n * The method resolves all expression placeholders with their actual values,\n * making it easier to understand the transaction's operations.\n *\n * @example\n * ```typescript\n * // Add multiple operations\n * transaction\n * .put('orders', { orderId: '123', status: 'PENDING' })\n * .update('inventory',\n * { productId: 'ABC' },\n * 'SET quantity = quantity - :amount',\n * undefined,\n * { ':amount': 1 }\n * );\n *\n * // Debug the transaction\n * const debugInfo = transaction.debug();\n * console.log('Transaction operations:', debugInfo);\n * ```\n *\n * @returns An array of readable representations of the transaction items\n */\n debug(): DynamoItem[] {\n return debugTransaction(this.items);\n }\n\n /**\n * Executes all operations in the transaction atomically.\n * Use this method when you need to:\n * - Perform multiple operations atomically\n * - Ensure all-or-nothing execution\n * - Maintain data consistency across operations\n *\n * The transaction will only succeed if all operations succeed.\n * If any operation fails, the entire transaction is rolled back.\n *\n * @example\n * ```typescript\n * try {\n * // Build and execute transaction\n * await transaction\n * .put('orders', newOrder)\n * .update('inventory',\n * { productId: 'ABC' },\n * 'SET quantity = quantity - :qty',\n * undefined,\n * { ':qty': 1 }\n * )\n * .conditionCheck('products',\n * { productId: 'ABC' },\n * op => op.eq('status', 'ACTIVE')\n * )\n * .execute();\n *\n * console.log('Transaction completed successfully');\n * } catch (error) {\n * // Handle transaction failure\n * console.error('Transaction failed:', error);\n * }\n * ```\n *\n * @throws {Error} If no transaction items are specified\n * @throws {Error} If any operation in the transaction fails\n * @returns A promise that resolves when the transaction completes\n */\n async execute(): Promise<void> {\n if (this.items.length === 0) {\n throw new Error(\"No transaction items specified\");\n }\n\n const transactItems = this.items.map((item) => {\n switch (item.type) {\n case \"Put\":\n return {\n Put: {\n TableName: item.params.tableName,\n Item: item.params.item,\n ConditionExpression: item.params.conditionExpression,\n ExpressionAttributeNames: item.params.expressionAttributeNames,\n ExpressionAttributeValues: item.params.expressionAttributeValues,\n },\n };\n case \"Delete\":\n return {\n Delete: {\n TableName: item.params.tableName,\n Key: item.params.key,\n ConditionExpression: item.params.conditionExpression,\n ExpressionAttributeNames: item.params.expressionAttributeNames,\n ExpressionAttributeValues: item.params.expressionAttributeValues,\n },\n };\n case \"Update\":\n return {\n Update: {\n TableName: item.params.tableName,\n Key: item.params.key,\n UpdateExpression: item.params.updateExpression,\n ConditionExpression: item.params.conditionExpression,\n ExpressionAttributeNames: item.params.expressionAttributeNames,\n ExpressionAttributeValues: item.params.expressionAttributeValues,\n },\n };\n case \"ConditionCheck\":\n return {\n ConditionCheck: {\n TableName: item.params.tableName,\n Key: item.params.key,\n ConditionExpression: item.params.conditionExpression,\n ExpressionAttributeNames: item.params.expressionAttributeNames,\n ExpressionAttributeValues: item.params.expressionAttributeValues,\n },\n };\n default: {\n // This should never happen as we've covered all cases in the union type\n const exhaustiveCheck: never = item;\n throw new Error(`Unsupported transaction item type: ${String(exhaustiveCheck)}`);\n }\n }\n });\n\n const params: TransactWriteCommandInput = {\n TransactItems: transactItems,\n ClientRequestToken: this.options.clientRequestToken,\n ReturnConsumedCapacity: this.options.returnConsumedCapacity,\n ReturnItemCollectionMetrics: this.options.returnItemCollectionMetrics,\n };\n\n try {\n await this.executor(params);\n } catch (error) {\n console.log(this.debug());\n console.error(\"Error executing transaction:\", error);\n throw error;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/expression.ts","../../src/utils/debug-expression.ts","../../src/utils/debug-transaction.ts","../../src/builders/transaction-builder.ts"],"names":[],"mappings":";AAEO,IAAM,qBAAA,GAAwB,CAAC,MAAA,EAA0B,IAAyB,KAAA;AAEvF,EAAW,KAAA,MAAA,CAAC,cAAc,YAAY,CAAA,IAAK,OAAO,OAAQ,CAAA,MAAA,CAAO,wBAAwB,CAAG,EAAA;AAC1F,IAAA,IAAI,iBAAiB,IAAM,EAAA;AACzB,MAAO,OAAA,YAAA;AAAA;AACT;AAIF,EAAA,MAAM,WAAW,CAAI,CAAA,EAAA,MAAA,CAAO,KAAK,MAAO,CAAA,wBAAwB,EAAE,MAAM,CAAA,CAAA;AACxE,EAAO,MAAA,CAAA,wBAAA,CAAyB,QAAQ,CAAI,GAAA,IAAA;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AA;AAAA,YACL,cAAgB,EAAA;AAAA,cACd,SAAA,EAAW,KAAK,MAAO,CAAA,SAAA;AAAA,cACvB,GAAA,EAAK,KAAK,MAAO,CAAA,GAAA;AAAA,cACjB,mBAAA,EAAqB,KAAK,MAAO,CAAA,mBAAA;AAAA,cACjC,wBAAA,EAA0B,KAAK,MAAO,CAAA,wBAAA;AAAA,cACtC,yBAAA,EAA2B,KAAK,MAAO,CAAA;AAAA;AACzC,WACF;AAAA,QACF,SAAS;AAEP,UAAA,MAAM,eAAyB,GAAA,IAAA;AAC/B,UAAA,MAAM,IAAI,KAAM,CAAA,CAAA,mCAAA,EAAsC,MAAO,CAAA,eAAe,CAAC,CAAE,CAAA,CAAA;AAAA;AACjF;AACF,KACD,CAAA;AAED,IAAA,MAAM,MAAoC,GAAA;AAAA,MACxC,aAAe,EAAA,aAAA;AAAA,MACf,kBAAA,EAAoB,KAAK,OAAQ,CAAA,kBAAA;AAAA,MACjC,sBAAA,EAAwB,KAAK,OAAQ,CAAA,sBAAA;AAAA,MACrC,2BAAA,EAA6B,KAAK,OAAQ,CAAA;AAAA,KAC5C;AAEA,IAAI,IAAA;AACF,MAAM,MAAA,IAAA,CAAK,SAAS,MAAM,CAAA;AAAA,aACnB,KAAO,EAAA;AACd,MAAQ,OAAA,CAAA,GAAA,CAAI,IAAK,CAAA,KAAA,EAAO,CAAA;AACxB,MAAQ,OAAA,CAAA,KAAA,CAAM,gCAAgC,KAAK,CAAA;AACnD,MAAM,MAAA,KAAA;AAAA;AACR;AAEJ","file":"transaction-builder.js","sourcesContent":["import type { ComparisonOperator, Condition, ExpressionParams, LogicalOperator } from \"./conditions\";\n\nexport const generateAttributeName = (params: ExpressionParams, attr: string): string => {\n // Check if the attribute already exists in the expressionAttributeNames\n for (const [existingName, existingAttr] of Object.entries(params.expressionAttributeNames)) {\n if (existingAttr === attr) {\n return existingName;\n }\n }\n\n // If not found, create a new attribute name\n const attrName = `#${Object.keys(params.expressionAttributeNames).length}`;\n params.expressionAttributeNames[attrName] = attr;\n return attrName;\n};\n\nexport const generateValueName = (params: ExpressionParams, value: unknown): string => {\n const valueName = `:${params.valueCounter.count++}`;\n params.expressionAttributeValues[valueName] = value;\n return valueName;\n};\n\nconst validateCondition = (condition: Condition, requiresAttr = true, requiresValue = true): void => {\n if (requiresAttr && !condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n if (requiresValue && condition.value === undefined) {\n throw new Error(`Value is required for ${condition.type} condition`);\n }\n};\n\nconst buildComparisonExpression = (condition: Condition, operator: string, params: ExpressionParams): string => {\n validateCondition(condition);\n\n if (!condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n const attrName = generateAttributeName(params, condition.attr);\n const valueName = generateValueName(params, condition.value);\n\n return `${attrName} ${operator} ${valueName}`;\n};\n\nconst buildBetweenExpression = (condition: Condition, params: ExpressionParams): string => {\n validateCondition(condition);\n\n if (!condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n if (!Array.isArray(condition.value) || condition.value.length !== 2) {\n throw new Error(\"Between condition requires an array of two values\");\n }\n\n const attrName = generateAttributeName(params, condition.attr);\n const lowerName = generateValueName(params, condition.value[0]);\n const upperName = generateValueName(params, condition.value[1]);\n\n return `${attrName} BETWEEN ${lowerName} AND ${upperName}`;\n};\n\nconst buildFunctionExpression = (functionName: string, condition: Condition, params: ExpressionParams): string => {\n validateCondition(condition);\n\n if (!condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n const attrName = generateAttributeName(params, condition.attr);\n const valueName = generateValueName(params, condition.value);\n\n return `${functionName}(${attrName}, ${valueName})`;\n};\n\nconst buildAttributeFunction = (functionName: string, condition: Condition, params: ExpressionParams): string => {\n validateCondition(condition, true, false);\n\n if (!condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n const attrName = generateAttributeName(params, condition.attr);\n return `${functionName}(${attrName})`;\n};\n\nconst buildLogicalExpression = (operator: string, conditions: Condition[], params: ExpressionParams): string => {\n if (!conditions || conditions.length === 0) {\n throw new Error(`At least one condition is required for ${operator} expression`);\n }\n\n const expressions = conditions.map((c) => buildExpression(c, params));\n return `(${expressions.join(` ${operator} `)})`;\n};\n\nexport const buildExpression = (condition: Condition, params: ExpressionParams): string => {\n if (!condition) return \"\";\n\n try {\n // Map of condition types to their expression builders\n const expressionBuilders: Record<ComparisonOperator | LogicalOperator, () => string> = {\n eq: () => buildComparisonExpression(condition, \"=\", params),\n ne: () => buildComparisonExpression(condition, \"<>\", params),\n lt: () => buildComparisonExpression(condition, \"<\", params),\n lte: () => buildComparisonExpression(condition, \"<=\", params),\n gt: () => buildComparisonExpression(condition, \">\", params),\n gte: () => buildComparisonExpression(condition, \">=\", params),\n between: () => buildBetweenExpression(condition, params),\n beginsWith: () => buildFunctionExpression(\"begins_with\", condition, params),\n contains: () => buildFunctionExpression(\"contains\", condition, params),\n attributeExists: () => buildAttributeFunction(\"attribute_exists\", condition, params),\n attributeNotExists: () => buildAttributeFunction(\"attribute_not_exists\", condition, params),\n and: () => {\n if (!condition.conditions) {\n throw new Error(\"Conditions array is required for AND operator\");\n }\n return buildLogicalExpression(\"AND\", condition.conditions, params);\n },\n or: () => {\n if (!condition.conditions) {\n throw new Error(\"Conditions array is required for OR operator\");\n }\n return buildLogicalExpression(\"OR\", condition.conditions, params);\n },\n not: () => {\n if (!condition.condition) {\n throw new Error(\"Condition is required for NOT operator\");\n }\n return `NOT (${buildExpression(condition.condition, params)})`;\n },\n };\n\n const builder = expressionBuilders[condition.type];\n if (!builder) {\n throw new Error(`Unknown condition type: ${condition.type}`);\n }\n\n return builder();\n } catch (error: unknown) {\n if (error instanceof Error) {\n console.error(`Error building expression for condition type ${condition.type}:`, error.message);\n } else {\n console.error(`Error building expression for condition type ${condition.type}:`, error);\n }\n throw error;\n }\n};\n\nexport const prepareExpressionParams = (\n condition?: Condition,\n): {\n expression?: string;\n names?: Record<string, string>;\n values?: Record<string, unknown>;\n} => {\n if (!condition) return {};\n\n const params: ExpressionParams = {\n expressionAttributeNames: {},\n expressionAttributeValues: {},\n valueCounter: { count: 0 },\n };\n\n const expression = buildExpression(condition, params);\n\n return {\n expression,\n names: Object.keys(params.expressionAttributeNames).length > 0 ? params.expressionAttributeNames : undefined,\n values: Object.keys(params.expressionAttributeValues).length > 0 ? params.expressionAttributeValues : undefined,\n };\n};\n","/**\n * Interface for DynamoDB command objects that can contain expressions\n */\nexport interface DynamoCommandWithExpressions {\n conditionExpression?: string;\n updateExpression?: string;\n filterExpression?: string;\n keyConditionExpression?: string;\n projectionExpression?: string;\n expressionAttributeNames?: Record<string, string>;\n expressionAttributeValues?: Record<string, unknown>;\n [key: string]: unknown;\n}\n\ntype ReadableDynamoCommand = {\n conditionExpression?: string;\n updateExpression?: string;\n filterExpression?: string;\n keyConditionExpression?: string;\n projectionExpression?: string;\n};\n\n/**\n * Utility function to debug a DynamoDB command by replacing all placeholders\n * in expressions with their actual values.\n *\n * @param command Any DynamoDB command with expressions and attribute maps\n * @returns An object with the same structure but with readable expressions\n */\nexport function debugCommand<T extends DynamoCommandWithExpressions>(\n command: T,\n): {\n raw: T;\n readable: ReadableDynamoCommand;\n} {\n // Create a copy of the command\n const result: ReadableDynamoCommand = {};\n\n function replaceAliases(expressionString: string) {\n if (!expressionString) {\n return expressionString;\n }\n\n let replacedString = expressionString;\n for (const alias in command.expressionAttributeNames) {\n const attributeName = command.expressionAttributeNames[alias];\n const regex = new RegExp(alias, \"g\");\n\n replacedString = replacedString.replace(regex, attributeName as string);\n }\n\n for (const alias in command.expressionAttributeValues) {\n let attributeValue = command.expressionAttributeValues[alias];\n\n // Handle Set objects for better readability\n if (attributeValue instanceof Set) {\n const array = Array.from(attributeValue);\n attributeValue = `Set(${array.length}){${array.map((v) => JSON.stringify(v)).join(\", \")}}`;\n } else {\n // Stringify other values for display\n attributeValue = JSON.stringify(attributeValue);\n }\n\n const regex = new RegExp(alias, \"g\");\n replacedString = replacedString.replace(regex, attributeValue as string);\n }\n\n return replacedString;\n }\n\n if (command.updateExpression) {\n result.updateExpression = replaceAliases(command.updateExpression);\n }\n if (command.conditionExpression) {\n result.conditionExpression = replaceAliases(command.conditionExpression);\n }\n if (command.filterExpression) {\n result.filterExpression = replaceAliases(command.filterExpression);\n }\n if (command.keyConditionExpression) {\n result.keyConditionExpression = replaceAliases(command.keyConditionExpression);\n }\n if (command.projectionExpression) {\n result.projectionExpression = replaceAliases(command.projectionExpression);\n }\n\n return {\n raw: command,\n readable: result,\n };\n}\n","import type { TransactionItem } from \"../builders/builder-types\";\nimport { debugCommand } from \"./debug-expression\";\n\n/**\n * Utility function to create a human-readable representation of a transaction item\n * by replacing all expression placeholders with their actual values.\n *\n * @param item The transaction item to debug\n * @returns A readable representation of the transaction item\n */\nexport function debugTransactionItem(item: TransactionItem): Record<string, unknown> {\n const result: Record<string, unknown> = {\n type: item.type,\n tableName: item.params.tableName,\n };\n\n // Add key if present\n if (\"key\" in item.params) {\n result.key = item.params.key;\n }\n\n // Add item if present (for Put operations)\n if (item.type === \"Put\") {\n result.item = item.params.item;\n }\n\n // Add readable expressions based on operation type\n switch (item.type) {\n case \"Put\":\n case \"Delete\":\n case \"ConditionCheck\":\n result.readable = debugCommand(item.params).readable;\n break;\n case \"Update\":\n result.readable = debugCommand(item.params).readable;\n break;\n }\n\n return result;\n}\n\n/**\n * Utility function to create a human-readable representation of all transaction items\n * in a transaction by replacing all expression placeholders with their actual values.\n *\n * @param items Array of transaction items to debug\n * @returns An array of readable representations of the transaction items\n */\nexport function debugTransaction(items: TransactionItem[]): Record<string, unknown>[] {\n return items.map((item) => debugTransactionItem(item));\n}\n","import type { TransactWriteCommandInput } from \"@aws-sdk/lib-dynamodb\";\nimport type { Condition, PrimaryKeyWithoutExpression } from \"../conditions\";\nimport { prepareExpressionParams } from \"../expression\";\nimport { debugTransaction } from \"../utils/debug-transaction\";\nimport type {\n ConditionCheckCommandParams,\n DeleteCommandParams,\n PutCommandParams,\n TransactionItem,\n UpdateCommandParams,\n} from \"./builder-types\";\nimport type { DynamoItem } from \"../types\";\n\n/**\n * Configuration options for DynamoDB transactions.\n */\nexport interface TransactionOptions {\n /** Unique identifier for the transaction request (idempotency token) */\n clientRequestToken?: string;\n /** Level of consumed capacity details to return */\n returnConsumedCapacity?: \"INDEXES\" | \"TOTAL\" | \"NONE\";\n /** Whether to return item collection metrics */\n returnItemCollectionMetrics?: \"SIZE\" | \"NONE\";\n}\n\n/**\n * Configuration for table indexes used in duplicate detection.\n * Defines the key structure for checking uniqueness constraints.\n */\ninterface IndexConfig {\n /** The partition key attribute name */\n partitionKey: string;\n /** Optional sort key attribute name */\n sortKey?: string;\n}\n\n/**\n * Function type for executing DynamoDB transaction operations.\n * @param params - The complete transaction command input\n * @returns A promise that resolves when the transaction completes\n */\nexport type TransactionExecutor = (params: TransactWriteCommandInput) => Promise<void>;\n\n/**\n * Builder for creating and executing DynamoDB transactions.\n * Use this builder when you need to:\n * - Perform multiple operations atomically\n * - Ensure data consistency across operations\n * - Implement complex business logic that requires atomic updates\n * - Prevent duplicate items across tables\n *\n * The builder supports:\n * - Put operations (insert/replace items)\n * - Delete operations\n * - Update operations\n * - Condition checks\n * - Duplicate detection\n * - Transaction-wide options\n *\n * @example\n * ```typescript\n * // Create a transaction with multiple operations\n * const transaction = new TransactionBuilder(executor, {\n * partitionKey: 'id',\n * sortKey: 'type'\n * });\n *\n * // Add a new order\n * transaction.put('orders', {\n * orderId: '123',\n * status: 'PENDING'\n * });\n *\n * // Update inventory with condition\n * transaction.update(\n * 'inventory',\n * { productId: 'ABC' },\n * 'set quantity = quantity - :amount',\n * { ':amount': 1 },\n * op => op.gte('quantity', 1)\n * );\n *\n * // Execute the transaction atomically\n * await transaction.execute();\n * ```\n *\n * Note: DynamoDB transactions have some limitations:\n * - Maximum 25 operations per transaction\n * - All operations must be in the same AWS region\n * - Cannot include table scans or queries\n */\nexport class TransactionBuilder {\n private items: TransactionItem[] = [];\n private options: TransactionOptions = {};\n private indexConfig: IndexConfig;\n private readonly executor: TransactionExecutor;\n\n constructor(executor: TransactionExecutor, indexConfig: IndexConfig) {\n this.executor = executor;\n this.indexConfig = indexConfig;\n }\n\n /**\n * Checks if an item with the same primary key already exists in the transaction\n * @private\n */\n private checkForDuplicateItem(tableName: string, newItem: DynamoItem): void {\n const pkName = this.indexConfig.partitionKey;\n const skName = this.indexConfig.sortKey ?? \"\";\n\n // Extract the primary key values from the provided key\n const pkValue = newItem[pkName];\n const skValue = skName ? newItem[skName] : undefined;\n\n if (!pkValue) {\n throw new Error(`Primary key value for '${pkName}' is missing`);\n }\n\n const duplicateItem = this.items.find((item) => {\n // Get the key from the item based on its type\n let itemKey: Record<string, unknown> | undefined;\n let itemTableName: string | undefined;\n\n switch (item.type) {\n case \"Put\":\n itemTableName = item.params.tableName;\n // For Put operations, the key is part of the item\n itemKey = item.params.item;\n break;\n case \"Update\":\n case \"Delete\":\n case \"ConditionCheck\":\n itemTableName = item.params.tableName;\n itemKey = item.params.key;\n break;\n }\n\n // Check if the table name and keys match\n if (itemTableName === tableName && itemKey) {\n const itemPkValue = itemKey[pkName];\n const itemSkValue = skName ? itemKey[skName] : undefined;\n\n // Match if partition keys match and either both sort keys match or both are undefined\n if (itemPkValue === pkValue) {\n if (skValue === undefined && itemSkValue === undefined) {\n return true;\n }\n if (skValue !== undefined && itemSkValue !== undefined && skValue === itemSkValue) {\n return true;\n }\n }\n }\n\n return false;\n });\n\n if (duplicateItem) {\n throw new Error(\n `Duplicate item detected in transaction: Table=${tableName}, ${pkName}=${String(pkValue)}, ${skName}=${skValue !== undefined ? String(skValue) : \"undefined\"}. DynamoDB transactions do not allow multiple operations on the same item.`,\n );\n }\n }\n\n createKeyForPrimaryIndex(key: PrimaryKeyWithoutExpression) {\n // Turn the pk/sk into the key object\n const keyCondition = {\n [this.indexConfig.partitionKey]: key.pk,\n };\n\n if (this.indexConfig.sortKey) {\n if (key.sk === undefined) {\n throw new Error(\"Sort key is required for delete operation\");\n }\n keyCondition[this.indexConfig.sortKey] = key.sk;\n }\n\n return keyCondition;\n }\n\n /**\n * Adds a put operation to the transaction.\n * Use this method when you need to:\n * - Insert new items as part of a transaction\n * - Replace existing items atomically\n * - Ensure items meet certain conditions before insertion\n *\n * The method automatically checks for duplicate items within the transaction\n * to prevent multiple operations on the same item.\n *\n * @example\n * ```typescript\n * // Simple put operation\n * transaction.put('orders', {\n * orderId: '123',\n * status: 'PENDING',\n * amount: 100\n * });\n *\n * // Conditional put operation\n * transaction.put(\n * 'inventory',\n * { productId: 'ABC', quantity: 50 },\n * op => op.attributeNotExists('productId')\n * );\n *\n * // Put with complex condition\n * transaction.put(\n * 'users',\n * { userId: '123', status: 'ACTIVE' },\n * op => op.and([\n * op.attributeNotExists('userId'),\n * op.beginsWith('status', 'ACTIVE')\n * ])\n * );\n * ```\n *\n * @param tableName - The name of the DynamoDB table\n * @param item - The item to put into the table\n * @param condition - Optional condition that must be satisfied\n * @returns The transaction builder for method chaining\n * @throws {Error} If a duplicate item is detected in the transaction\n */\n put<T extends DynamoItem>(tableName: string, item: T, condition?: Condition): this {\n // Check for duplicate item\n this.checkForDuplicateItem(tableName, item);\n\n const transactionItem: TransactionItem = {\n type: \"Put\",\n params: {\n tableName,\n item,\n },\n };\n\n if (condition) {\n const { expression, names, values } = prepareExpressionParams(condition);\n transactionItem.params.conditionExpression = expression;\n transactionItem.params.expressionAttributeNames = names;\n transactionItem.params.expressionAttributeValues = values;\n }\n\n this.items.push(transactionItem);\n return this;\n }\n\n /**\n * Adds a pre-configured put operation to the transaction.\n * Use this method when you need to:\n * - Reuse put commands from PutBuilder\n * - Add complex put operations with pre-configured parameters\n * - Integrate with existing put command configurations\n *\n * This method is particularly useful when working with PutBuilder\n * to maintain consistency in put operations across your application.\n *\n * @example\n * ```typescript\n * // Create a put command with PutBuilder\n * const putCommand = new PutBuilder(executor, newItem, 'users')\n * .condition(op => op.attributeNotExists('userId'))\n * .toDynamoCommand();\n *\n * // Add the command to the transaction\n * transaction.putWithCommand(putCommand);\n * ```\n *\n * @param command - The complete put command configuration\n * @returns The transaction builder for method chaining\n * @throws {Error} If a duplicate item is detected in the transaction\n * @see PutBuilder for creating put commands\n */\n putWithCommand(command: PutCommandParams): TransactionBuilder {\n // Check for duplicate item\n this.checkForDuplicateItem(command.tableName, command.item);\n\n const transactionItem: TransactionItem = {\n type: \"Put\",\n params: command,\n };\n\n this.items.push(transactionItem);\n return this;\n }\n\n /**\n * Adds a delete operation to the transaction.\n * Use this method when you need to:\n * - Remove items as part of a transaction\n * - Conditionally delete items\n * - Ensure items exist before deletion\n *\n * The method automatically checks for duplicate items within the transaction\n * to prevent multiple operations on the same item.\n *\n * @example\n * ```typescript\n * // Simple delete operation\n * transaction.delete('orders', {\n * pk: 'ORDER#123',\n * sk: 'METADATA'\n * });\n *\n * // Conditional delete operation\n * transaction.delete(\n * 'users',\n * { pk: 'USER#123' },\n * op => op.eq('status', 'INACTIVE')\n * );\n *\n * // Delete with complex condition\n * transaction.delete(\n * 'products',\n * { pk: 'PROD#ABC' },\n * op => op.and([\n * op.eq('status', 'DRAFT'),\n * op.lt('version', 5)\n * ])\n * );\n * ```\n *\n * @param tableName - The name of the DynamoDB table\n * @param key - The primary key of the item to delete\n * @param condition - Optional condition that must be satisfied\n * @returns The transaction builder for method chaining\n * @throws {Error} If a duplicate item is detected in the transaction\n */\n delete(tableName: string, key: PrimaryKeyWithoutExpression, condition?: Condition): TransactionBuilder {\n const keyCondition = this.createKeyForPrimaryIndex(key);\n\n // Check for duplicate item\n this.checkForDuplicateItem(tableName, keyCondition);\n\n const transactionItem: TransactionItem = {\n type: \"Delete\",\n params: {\n tableName,\n key: keyCondition,\n },\n };\n\n if (condition) {\n const { expression, names, values } = prepareExpressionParams(condition);\n transactionItem.params.conditionExpression = expression;\n transactionItem.params.expressionAttributeNames = names;\n transactionItem.params.expressionAttributeValues = values;\n }\n\n this.items.push(transactionItem);\n return this;\n }\n\n /**\n * Adds a pre-configured delete operation to the transaction.\n * Use this method when you need to:\n * - Reuse delete commands from DeleteBuilder\n * - Add complex delete operations with pre-configured parameters\n * - Integrate with existing delete command configurations\n *\n * This method is particularly useful when working with DeleteBuilder\n * to maintain consistency in delete operations across your application.\n *\n * @example\n * ```typescript\n * // Create a delete command with DeleteBuilder\n * const deleteCommand = new DeleteBuilder(executor, 'users', { pk: 'USER#123' })\n * .condition(op => op.and([\n * op.attributeExists('pk'),\n * op.eq('status', 'INACTIVE')\n * ]))\n * .toDynamoCommand();\n *\n * // Add the command to the transaction\n * transaction.deleteWithCommand(deleteCommand);\n * ```\n *\n * @param command - The complete delete command configuration\n * @returns The transaction builder for method chaining\n * @throws {Error} If a duplicate item is detected in the transaction\n * @see DeleteBuilder for creating delete commands\n */\n deleteWithCommand(command: DeleteCommandParams): this {\n // The command.key from DeleteBuilder.toDynamoCommand() is in PrimaryKeyWithoutExpression format\n // but DeleteCommandParams expects it to be in the table's actual key format\n // We need to check if it's already converted or needs conversion\n let keyForDuplicateCheck: Record<string, unknown>;\n let keyForTransaction: Record<string, unknown>;\n\n // Check if the key is in PrimaryKeyWithoutExpression format (has pk/sk properties)\n if (typeof command.key === 'object' && command.key !== null && 'pk' in command.key) {\n // Convert from PrimaryKeyWithoutExpression to table key format\n keyForTransaction = this.createKeyForPrimaryIndex(command.key as PrimaryKeyWithoutExpression);\n keyForDuplicateCheck = keyForTransaction;\n } else {\n // Key is already in table format\n keyForTransaction = command.key;\n keyForDuplicateCheck = command.key;\n }\n\n // Check for duplicate item\n this.checkForDuplicateItem(command.tableName, keyForDuplicateCheck);\n\n const transactionItem: TransactionItem = {\n type: \"Delete\",\n params: {\n ...command,\n key: keyForTransaction,\n },\n };\n this.items.push(transactionItem);\n return this;\n }\n\n /**\n * Adds an update operation to the transaction.\n * Use this method when you need to:\n * - Modify existing items as part of a transaction\n * - Update multiple attributes atomically\n * - Apply conditional updates\n * - Perform complex attribute manipulations\n *\n * The method supports all DynamoDB update expressions:\n * - SET: Modify or add attributes\n * - REMOVE: Delete attributes\n * - ADD: Update numbers and sets\n * - DELETE: Remove elements from a set\n *\n * @example\n * ```typescript\n * // Simple update\n * transaction.update(\n * 'orders',\n * { pk: 'ORDER#123' },\n * 'SET #status = :status',\n * { '#status': 'status' },\n * { ':status': 'PROCESSING' }\n * );\n *\n * // Complex update with multiple operations\n * transaction.update(\n * 'products',\n * { pk: 'PROD#ABC' },\n * 'SET #qty = #qty - :amount, #status = :status REMOVE #oldAttr',\n * { '#qty': 'quantity', '#status': 'status', '#oldAttr': 'deprecated_field' },\n * { ':amount': 1, ':status': 'LOW_STOCK' }\n * );\n *\n * // Conditional update\n * transaction.update(\n * 'users',\n * { pk: 'USER#123' },\n * 'SET #lastLogin = :now',\n * { '#lastLogin': 'lastLoginDate' },\n * { ':now': new Date().toISOString() },\n * op => op.attributeExists('pk')\n * );\n * ```\n *\n * @param tableName - The name of the DynamoDB table\n * @param key - The primary key of the item to update\n * @param updateExpression - The update expression (SET, REMOVE, ADD, DELETE)\n * @param expressionAttributeNames - Map of attribute name placeholders to actual names\n * @param expressionAttributeValues - Map of value placeholders to actual values\n * @param condition - Optional condition that must be satisfied\n * @returns The transaction builder for method chaining\n * @throws {Error} If a duplicate item is detected in the transaction\n */\n update<T extends DynamoItem>(\n tableName: string,\n key: PrimaryKeyWithoutExpression,\n updateExpression: string,\n expressionAttributeNames?: Record<string, string>,\n expressionAttributeValues?: Record<string, unknown>,\n condition?: Condition,\n ): this {\n const keyCondition = this.createKeyForPrimaryIndex(key);\n\n // Check for duplicate item\n this.checkForDuplicateItem(tableName, keyCondition);\n\n const transactionItem: TransactionItem = {\n type: \"Update\",\n params: {\n tableName,\n key: keyCondition,\n updateExpression,\n expressionAttributeNames,\n expressionAttributeValues,\n },\n };\n\n if (condition) {\n const { expression, names, values } = prepareExpressionParams(condition);\n transactionItem.params.conditionExpression = expression;\n\n // Merge the condition expression attribute names and values with the update ones\n transactionItem.params.expressionAttributeNames = {\n ...transactionItem.params.expressionAttributeNames,\n ...names,\n };\n\n transactionItem.params.expressionAttributeValues = {\n ...transactionItem.params.expressionAttributeValues,\n ...values,\n };\n }\n\n this.items.push(transactionItem);\n return this;\n }\n\n /**\n * Adds a pre-configured update operation to the transaction.\n * Use this method when you need to:\n * - Reuse update commands from UpdateBuilder\n * - Add complex update operations with pre-configured parameters\n * - Integrate with existing update command configurations\n *\n * This method is particularly useful when working with UpdateBuilder\n * to maintain consistency in update operations across your application.\n *\n * @example\n * ```typescript\n * // Create an update command with UpdateBuilder\n * const updateCommand = new UpdateBuilder(executor, 'inventory', { pk: 'PROD#ABC' })\n * .set('quantity', ':qty')\n * .set('lastUpdated', ':now')\n * .values({\n * ':qty': 100,\n * ':now': new Date().toISOString()\n * })\n * .condition(op => op.gt('quantity', 0))\n * .toDynamoCommand();\n *\n * // Add the command to the transaction\n * transaction.updateWithCommand(updateCommand);\n * ```\n *\n * @param command - The complete update command configuration\n * @returns The transaction builder for method chaining\n * @throws {Error} If a duplicate item is detected in the transaction\n * @see UpdateBuilder for creating update commands\n */\n updateWithCommand(command: UpdateCommandParams): TransactionBuilder {\n // The command.key from UpdateBuilder.toDynamoCommand() is in PrimaryKeyWithoutExpression format\n // but UpdateCommandParams expects it to be in the table's actual key format\n // We need to check if it's already converted or needs conversion\n let keyForDuplicateCheck: Record<string, unknown>;\n let keyForTransaction: Record<string, unknown>;\n\n // Check if the key is in PrimaryKeyWithoutExpression format (has pk/sk properties)\n if (typeof command.key === 'object' && command.key !== null && 'pk' in command.key) {\n // Convert from PrimaryKeyWithoutExpression to table key format\n keyForTransaction = this.createKeyForPrimaryIndex(command.key as PrimaryKeyWithoutExpression);\n keyForDuplicateCheck = keyForTransaction;\n } else {\n // Key is already in table format\n keyForTransaction = command.key;\n keyForDuplicateCheck = command.key;\n }\n\n // Check for duplicate item\n this.checkForDuplicateItem(command.tableName, keyForDuplicateCheck);\n\n const transactionItem: TransactionItem = {\n type: \"Update\",\n params: {\n ...command,\n key: keyForTransaction,\n },\n };\n\n this.items.push(transactionItem);\n return this;\n }\n\n /**\n * Adds a condition check operation to the transaction.\n * Use this method when you need to:\n * - Validate item state without modifying it\n * - Ensure data consistency across tables\n * - Implement complex business rules\n * - Verify preconditions for other operations\n *\n * Condition checks are particularly useful for:\n * - Implementing optimistic locking\n * - Ensuring referential integrity\n * - Validating business rules atomically\n *\n * @example\n * ```typescript\n * // Check if order is in correct state\n * transaction.conditionCheck(\n * 'orders',\n * { pk: 'ORDER#123' },\n * op => op.eq('status', 'PENDING')\n * );\n *\n * // Complex condition check\n * transaction.conditionCheck(\n * 'inventory',\n * { pk: 'PROD#ABC' },\n * op => op.and([\n * op.gt('quantity', 0),\n * op.eq('status', 'ACTIVE'),\n * op.attributeExists('lastRestockDate')\n * ])\n * );\n *\n * // Check with multiple attributes\n * transaction.conditionCheck(\n * 'users',\n * { pk: 'USER#123' },\n * op => op.or([\n * op.eq('status', 'PREMIUM'),\n * op.gte('credits', 100)\n * ])\n * );\n * ```\n *\n * @param tableName - The name of the DynamoDB table\n * @param key - The primary key of the item to check\n * @param condition - The condition that must be satisfied\n * @returns The transaction builder for method chaining\n * @throws {Error} If a duplicate item is detected in the transaction\n * @throws {Error} If condition expression generation fails\n */\n conditionCheck(tableName: string, key: PrimaryKeyWithoutExpression, condition: Condition): TransactionBuilder {\n const keyCondition = this.createKeyForPrimaryIndex(key);\n\n // Check for duplicate item\n this.checkForDuplicateItem(tableName, keyCondition);\n\n const { expression, names, values } = prepareExpressionParams(condition);\n\n if (!expression) {\n throw new Error(\"Failed to generate condition expression\");\n }\n\n const transactionItem: TransactionItem = {\n type: \"ConditionCheck\",\n params: {\n tableName,\n key: keyCondition,\n conditionExpression: expression,\n expressionAttributeNames: names,\n expressionAttributeValues: values,\n },\n };\n\n this.items.push(transactionItem);\n return this;\n }\n\n /**\n * Adds a pre-configured condition check operation to the transaction.\n * Use this method when you need to:\n * - Reuse condition checks from ConditionCheckBuilder\n * - Add complex condition checks with pre-configured parameters\n * - Integrate with existing condition check configurations\n *\n * This method is particularly useful when working with ConditionCheckBuilder\n * to maintain consistency in condition checks across your application.\n *\n * @example\n * ```typescript\n * // Create a condition check with ConditionCheckBuilder\n * const checkCommand = new ConditionCheckBuilder('inventory', { pk: 'PROD#ABC' })\n * .condition(op => op.and([\n * op.between('quantity', 10, 100),\n * op.beginsWith('category', 'ELECTRONICS'),\n * op.attributeExists('lastAuditDate')\n * ]))\n * .toDynamoCommand();\n *\n * // Add the command to the transaction\n * transaction.conditionCheckWithCommand(checkCommand);\n * ```\n *\n * @param command - The complete condition check command configuration\n * @returns The transaction builder for method chaining\n * @throws {Error} If a duplicate item is detected in the transaction\n * @see ConditionCheckBuilder for creating condition check commands\n */\n conditionCheckWithCommand(command: ConditionCheckCommandParams): TransactionBuilder {\n // The command.key from ConditionCheckBuilder.toDynamoCommand() is in PrimaryKeyWithoutExpression format\n // but ConditionCheckCommandParams expects it to be in the table's actual key format\n // We need to check if it's already converted or needs conversion\n let keyForDuplicateCheck: Record<string, unknown>;\n let keyForTransaction: Record<string, unknown>;\n\n // Check if the key is in PrimaryKeyWithoutExpression format (has pk/sk properties)\n if (typeof command.key === 'object' && command.key !== null && 'pk' in command.key) {\n // Convert from PrimaryKeyWithoutExpression to table key format\n keyForTransaction = this.createKeyForPrimaryIndex(command.key as PrimaryKeyWithoutExpression);\n keyForDuplicateCheck = keyForTransaction;\n } else {\n // Key is already in table format\n keyForTransaction = command.key;\n keyForDuplicateCheck = command.key;\n }\n\n // Check for duplicate item\n this.checkForDuplicateItem(command.tableName, keyForDuplicateCheck);\n\n const transactionItem: TransactionItem = {\n type: \"ConditionCheck\",\n params: {\n ...command,\n key: keyForTransaction,\n },\n };\n this.items.push(transactionItem);\n return this;\n }\n\n /**\n * Sets options for the transaction execution.\n * Use this method when you need to:\n * - Enable idempotent transactions\n * - Track consumed capacity\n * - Monitor item collection metrics\n *\n * @example\n * ```typescript\n * // Enable idempotency and capacity tracking\n * transaction.withOptions({\n * clientRequestToken: 'unique-request-id-123',\n * returnConsumedCapacity: 'TOTAL'\n * });\n *\n * // Track item collection metrics\n * transaction.withOptions({\n * returnItemCollectionMetrics: 'SIZE'\n * });\n * ```\n *\n * Note: ClientRequestToken can be used to make transactions idempotent,\n * ensuring the same transaction is not executed multiple times.\n *\n * @param options - Configuration options for the transaction\n * @returns The transaction builder for method chaining\n */\n withOptions(options: TransactionOptions): TransactionBuilder {\n this.options = { ...this.options, ...options };\n return this;\n }\n\n /**\n * Gets a human-readable representation of the transaction items.\n * Use this method when you need to:\n * - Debug complex transactions\n * - Verify operation parameters\n * - Log transaction details\n * - Troubleshoot condition expressions\n *\n * The method resolves all expression placeholders with their actual values,\n * making it easier to understand the transaction's operations.\n *\n * @example\n * ```typescript\n * // Add multiple operations\n * transaction\n * .put('orders', { orderId: '123', status: 'PENDING' })\n * .update('inventory',\n * { productId: 'ABC' },\n * 'SET quantity = quantity - :amount',\n * undefined,\n * { ':amount': 1 }\n * );\n *\n * // Debug the transaction\n * const debugInfo = transaction.debug();\n * console.log('Transaction operations:', debugInfo);\n * ```\n *\n * @returns An array of readable representations of the transaction items\n */\n debug(): DynamoItem[] {\n return debugTransaction(this.items);\n }\n\n /**\n * Executes all operations in the transaction atomically.\n * Use this method when you need to:\n * - Perform multiple operations atomically\n * - Ensure all-or-nothing execution\n * - Maintain data consistency across operations\n *\n * The transaction will only succeed if all operations succeed.\n * If any operation fails, the entire transaction is rolled back.\n *\n * @example\n * ```typescript\n * try {\n * // Build and execute transaction\n * await transaction\n * .put('orders', newOrder)\n * .update('inventory',\n * { productId: 'ABC' },\n * 'SET quantity = quantity - :qty',\n * undefined,\n * { ':qty': 1 }\n * )\n * .conditionCheck('products',\n * { productId: 'ABC' },\n * op => op.eq('status', 'ACTIVE')\n * )\n * .execute();\n *\n * console.log('Transaction completed successfully');\n * } catch (error) {\n * // Handle transaction failure\n * console.error('Transaction failed:', error);\n * }\n * ```\n *\n * @throws {Error} If no transaction items are specified\n * @throws {Error} If any operation in the transaction fails\n * @returns A promise that resolves when the transaction completes\n */\n async execute(): Promise<void> {\n if (this.items.length === 0) {\n throw new Error(\"No transaction items specified\");\n }\n\n const transactItems = this.items.map((item) => {\n switch (item.type) {\n case \"Put\":\n return {\n Put: {\n TableName: item.params.tableName,\n Item: item.params.item,\n ConditionExpression: item.params.conditionExpression,\n ExpressionAttributeNames: item.params.expressionAttributeNames,\n ExpressionAttributeValues: item.params.expressionAttributeValues,\n },\n };\n case \"Delete\":\n return {\n Delete: {\n TableName: item.params.tableName,\n Key: item.params.key,\n ConditionExpression: item.params.conditionExpression,\n ExpressionAttributeNames: item.params.expressionAttributeNames,\n ExpressionAttributeValues: item.params.expressionAttributeValues,\n },\n };\n case \"Update\":\n return {\n Update: {\n TableName: item.params.tableName,\n Key: item.params.key,\n UpdateExpression: item.params.updateExpression,\n ConditionExpression: item.params.conditionExpression,\n ExpressionAttributeNames: item.params.expressionAttributeNames,\n ExpressionAttributeValues: item.params.expressionAttributeValues,\n },\n };\n case \"ConditionCheck\":\n return {\n ConditionCheck: {\n TableName: item.params.tableName,\n Key: item.params.key,\n ConditionExpression: item.params.conditionExpression,\n ExpressionAttributeNames: item.params.expressionAttributeNames,\n ExpressionAttributeValues: item.params.expressionAttributeValues,\n },\n };\n default: {\n // This should never happen as we've covered all cases in the union type\n const exhaustiveCheck: never = item;\n throw new Error(`Unsupported transaction item type: ${String(exhaustiveCheck)}`);\n }\n }\n });\n\n const params: TransactWriteCommandInput = {\n TransactItems: transactItems,\n ClientRequestToken: this.options.clientRequestToken,\n ReturnConsumedCapacity: this.options.returnConsumedCapacity,\n ReturnItemCollectionMetrics: this.options.returnItemCollectionMetrics,\n };\n\n try {\n await this.executor(params);\n } catch (error) {\n console.log(this.debug());\n console.error(\"Error executing transaction:\", error);\n throw error;\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/conditions.ts","../../src/expression.ts","../../src/utils/debug-expression.ts","../../src/builders/update-builder.ts"],"names":["value"],"mappings":";;;AA+FO,IAAM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AAAA;AACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAwBA,KAAoB,GAAA;AAClB,IAAM,MAAA,OAAA,GAAU,KAAK,eAAgB,EAAA;AACrC,IAAA,OAAO,aAAa,OAAO,CAAA;AAAA;AAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA0CA,MAAM,OAAiC,GAAA;AACrC,IAAM,MAAA,MAAA,GAAS,KAAK,eAAgB,EAAA;AACpC,IAAO,OAAA,IAAA,CAAK,SAAS,MAAM,CAAA;AAAA;AAE/B","file":"update-builder.cjs","sourcesContent":["import type { Path, PathType } from \"./builders/types\";\nimport type { DynamoItem } from \"./types\";\n\n/**\n * Supported comparison operators for DynamoDB conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html AWS DynamoDB - Comparison Operator Reference}\n *\n * - eq: Equals (=)\n * - ne: Not equals (≠ / <>)\n * - lt: Less than (<)\n * - lte: Less than or equal to (≤)\n * - gt: Greater than (>)\n * - gte: Greater than or equal to (≥)\n * - between: Between two values (inclusive)\n * - beginsWith: Checks if string attribute begins with specified substring\n * - contains: Checks if string/set attribute contains specified value\n * - attributeExists: Checks if attribute exists\n * - attributeNotExists: Checks if attribute does not exist\n */\nexport type ComparisonOperator =\n | \"eq\"\n | \"ne\"\n | \"lt\"\n | \"lte\"\n | \"gt\"\n | \"gte\"\n | \"between\"\n | \"beginsWith\"\n | \"contains\"\n | \"attributeExists\"\n | \"attributeNotExists\";\n\n/**\n * Logical operators for combining multiple conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - Logical Operator Reference}\n *\n * - and: Evaluates to true if all conditions are true\n * - or: Evaluates to true if any condition is true\n * - not: Negate the result of a condition\n */\nexport type LogicalOperator = \"and\" | \"or\" | \"not\";\n\n/**\n * Represents a DynamoDB condition expression.\n * Can be either a comparison condition or a logical combination of conditions.\n *\n * @example\n * // Simple comparison condition\n * const condition: Condition = {\n * type: \"eq\",\n * attr: \"status\",\n * value: \"ACTIVE\"\n * };\n *\n * @example\n * // Logical combination of conditions\n * const condition: Condition = {\n * type: \"and\",\n * conditions: [\n * { type: \"eq\", attr: \"status\", value: \"ACTIVE\" },\n * { type: \"gt\", attr: \"age\", value: 5 }\n * ]\n * };\n */\nexport interface Condition {\n /** The type of condition (comparison or logical operator) */\n type: ComparisonOperator | LogicalOperator;\n /** The attribute name for comparison conditions */\n attr?: string;\n /** The value to compare against for comparison conditions */\n value?: unknown;\n /** Array of conditions for logical operators (and/or) */\n conditions?: Condition[];\n /** Single condition for the 'not' operator */\n condition?: Condition;\n}\n\n/**\n * Parameters used to build DynamoDB expression strings.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html Expression Attribute Names}\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeValues.html Expression Attribute Values}\n */\nexport interface ExpressionParams {\n /** Map of attribute name placeholders to actual attribute names */\n expressionAttributeNames: Record<string, string>;\n /** Map of value placeholders to actual values */\n expressionAttributeValues: DynamoItem;\n /** Counter for generating unique value placeholders */\n valueCounter: { count: number };\n}\n\n/**\n * Creates a comparison condition builder function for the specified operator.\n * @internal\n */\nexport const createComparisonCondition =\n (type: ComparisonOperator) =>\n (attr: string, value: unknown): Condition => ({\n type,\n attr,\n value,\n });\n\n/**\n * Creates an equals (=) condition\n * @example\n * eq(\"status\", \"ACTIVE\") // status = \"ACTIVE\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const eq = createComparisonCondition(\"eq\");\n\n/**\n * Creates a not equals (≠) condition\n * @example\n * ne(\"status\", \"DELETED\") // status <> \"DELETED\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const ne = createComparisonCondition(\"ne\");\n\n/**\n * Creates a less than (<) condition\n * @example\n * lt(\"age\", 18) // age < 18\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const lt = createComparisonCondition(\"lt\");\n\n/**\n * Creates a less than or equal to (≤) condition\n * @example\n * lte(\"age\", 18) // age <= 18\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const lte = createComparisonCondition(\"lte\");\n\n/**\n * Creates a greater than (>) condition\n * @example\n * gt(\"price\", 100) // price > 100\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const gt = createComparisonCondition(\"gt\");\n\n/**\n * Creates a greater than or equal to (≥) condition\n * @example\n * gte(\"price\", 100) // price >= 100\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const gte = createComparisonCondition(\"gte\");\n\n/**\n * Creates a between condition that checks if a value is within a range (inclusive)\n * @example\n * between(\"age\", 18, 65) // age BETWEEN 18 AND 65\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - BETWEEN}\n */\nexport const between = (attr: string, lower: unknown, upper: unknown): Condition => ({\n type: \"between\",\n attr,\n value: [lower, upper],\n});\n\n/**\n * Creates a begins_with condition that checks if a string attribute starts with a substring\n * @example\n * beginsWith(\"email\", \"@example.com\") // begins_with(email, \"@example.com\")\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - begins_with}\n */\nexport const beginsWith = createComparisonCondition(\"beginsWith\");\n\n/**\n * Creates a contains condition that checks if a string contains a substring or if a set contains an element\n * @example\n * contains(\"tags\", \"important\") // contains(tags, \"important\")\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - contains}\n */\nexport const contains = createComparisonCondition(\"contains\");\n\n/**\n * Creates a condition that checks if an attribute exists\n * @example\n * attributeExists(\"email\") // attribute_exists(email)\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_exists}\n */\nexport const attributeExists = (attr: string): Condition => ({\n type: \"attributeExists\",\n attr,\n});\n\n/**\n * Creates a condition that checks if an attribute does not exist\n * @example\n * attributeNotExists(\"deletedAt\") // attribute_not_exists(deletedAt)\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_not_exists}\n */\nexport const attributeNotExists = (attr: string): Condition => ({\n type: \"attributeNotExists\",\n attr,\n});\n\n// --- Logical Operators ---\n\n/**\n * Combines multiple conditions with AND operator\n * @example\n * and(\n * eq(\"status\", \"ACTIVE\"),\n * gt(\"age\", 18)\n * ) // status = \"ACTIVE\" AND age > 18\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - AND}\n */\nexport const and = (...conditions: Condition[]): Condition => ({\n type: \"and\",\n conditions,\n});\n\n/**\n * Combines multiple conditions with OR operator\n * @example\n * or(\n * eq(\"status\", \"PENDING\"),\n * eq(\"status\", \"PROCESSING\")\n * ) // status = \"PENDING\" OR status = \"PROCESSING\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - OR}\n */\nexport const or = (...conditions: Condition[]): Condition => ({\n type: \"or\",\n conditions,\n});\n\n/**\n * Negates a condition\n * @example\n * not(eq(\"status\", \"DELETED\")) // NOT status = \"DELETED\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - NOT}\n */\nexport const not = (condition: Condition): Condition => ({\n type: \"not\",\n condition,\n});\n\n/**\n * Type-safe operators for building key conditions in DynamoDB queries.\n * Only includes operators that are valid for key conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.KeyConditionExpressions AWS DynamoDB - Key Condition Expressions}\n *\n * @example\n * // Using with sort key conditions\n * table.query({\n * pk: \"USER#123\",\n * sk: op => op.beginsWith(\"ORDER#\")\n * })\n */\nexport type KeyConditionOperator = {\n /** Equals comparison for key attributes */\n eq: (value: unknown) => Condition;\n /** Less than comparison for key attributes */\n lt: (value: unknown) => Condition;\n /** Less than or equal comparison for key attributes */\n lte: (value: unknown) => Condition;\n /** Greater than comparison for key attributes */\n gt: (value: unknown) => Condition;\n /** Greater than or equal comparison for key attributes */\n gte: (value: unknown) => Condition;\n /** Between range comparison for key attributes */\n between: (lower: unknown, upper: unknown) => Condition;\n /** Begins with comparison for key attributes */\n beginsWith: (value: unknown) => Condition;\n /** Combines multiple key conditions with AND */\n and: (...conditions: Condition[]) => Condition;\n};\n\n/**\n * Type-safe operators for building conditions in DynamoDB operations.\n * Includes all available condition operators with proper type inference.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html AWS DynamoDB - Condition Expressions}\n *\n * @example\n * // Using with type-safe conditions\n * interface User {\n * status: string;\n * age: number;\n * email?: string;\n * }\n *\n * table.scan<User>()\n * .where(op => op.and(\n * op.eq(\"status\", \"ACTIVE\"),\n * op.gt(\"age\", 18),\n * op.attributeExists(\"email\")\n * ))\n *\n * @template T The type of the item being operated on\n */\nexport type ConditionOperator<T extends DynamoItem> = {\n eq: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n ne: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n lt: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n lte: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n gt: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n gte: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n between: <K extends Path<T>>(attr: K, lower: PathType<T, K>, upper: PathType<T, K>) => Condition;\n beginsWith: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n contains: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n attributeExists: <K extends Path<T>>(attr: K) => Condition;\n attributeNotExists: <K extends Path<T>>(attr: K) => Condition;\n and: (...conditions: Condition[]) => Condition;\n or: (...conditions: Condition[]) => Condition;\n not: (condition: Condition) => Condition;\n};\n\n/**\n * Primary key type for QUERY operations.\n * Allows building complex key conditions for the sort key.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html AWS DynamoDB - Query Operations}\n *\n * @example\n * // Query items with a specific partition key and sort key prefix\n * table.query({\n * pk: \"USER#123\",\n * sk: op => op.beginsWith(\"ORDER#2023\")\n * })\n *\n * @example\n * // Query items within a specific sort key range\n * table.query({\n * pk: \"USER#123\",\n * sk: op => op.between(\"ORDER#2023-01\", \"ORDER#2023-12\")\n * })\n */\nexport type PrimaryKey = {\n /** Partition key value */\n pk: string;\n /** Optional sort key condition builder */\n sk?: (op: KeyConditionOperator) => Condition;\n};\n\n/**\n * Primary key type for GET and DELETE operations.\n * Used when you need to specify exact key values without conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html AWS DynamoDB - Working with Items}\n *\n * @example\n * // Get a specific item by its complete primary key\n * table.get({\n * pk: \"USER#123\",\n * sk: \"PROFILE#123\"\n * })\n *\n * @example\n * // Delete a specific item by its complete primary key\n * table.delete({\n * pk: \"USER#123\",\n * sk: \"ORDER#456\"\n * })\n */\nexport type PrimaryKeyWithoutExpression = {\n /** Partition key value */\n pk: string;\n /** Optional sort key value */\n sk?: string;\n};\n","import type { ComparisonOperator, Condition, ExpressionParams, LogicalOperator } from \"./conditions\";\n\nexport const generateAttributeName = (params: ExpressionParams, attr: string): string => {\n // Check if the attribute already exists in the expressionAttributeNames\n for (const [existingName, existingAttr] of Object.entries(params.expressionAttributeNames)) {\n if (existingAttr === attr) {\n return existingName;\n }\n }\n\n // If not found, create a new attribute name\n const attrName = `#${Object.keys(params.expressionAttributeNames).length}`;\n params.expressionAttributeNames[attrName] = attr;\n return attrName;\n};\n\nexport const generateValueName = (params: ExpressionParams, value: unknown): string => {\n const valueName = `:${params.valueCounter.count++}`;\n params.expressionAttributeValues[valueName] = value;\n return valueName;\n};\n\nconst validateCondition = (condition: Condition, requiresAttr = true, requiresValue = true): void => {\n if (requiresAttr && !condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n if (requiresValue && condition.value === undefined) {\n throw new Error(`Value is required for ${condition.type} condition`);\n }\n};\n\nconst buildComparisonExpression = (condition: Condition, operator: string, params: ExpressionParams): string => {\n validateCondition(condition);\n\n if (!condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n const attrName = generateAttributeName(params, condition.attr);\n const valueName = generateValueName(params, condition.value);\n\n return `${attrName} ${operator} ${valueName}`;\n};\n\nconst buildBetweenExpression = (condition: Condition, params: ExpressionParams): string => {\n validateCondition(condition);\n\n if (!condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n if (!Array.isArray(condition.value) || condition.value.length !== 2) {\n throw new Error(\"Between condition requires an array of two values\");\n }\n\n const attrName = generateAttributeName(params, condition.attr);\n const lowerName = generateValueName(params, condition.value[0]);\n const upperName = generateValueName(params, condition.value[1]);\n\n return `${attrName} BETWEEN ${lowerName} AND ${upperName}`;\n};\n\nconst buildFunctionExpression = (functionName: string, condition: Condition, params: ExpressionParams): string => {\n validateCondition(condition);\n\n if (!condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n const attrName = generateAttributeName(params, condition.attr);\n const valueName = generateValueName(params, condition.value);\n\n return `${functionName}(${attrName}, ${valueName})`;\n};\n\nconst buildAttributeFunction = (functionName: string, condition: Condition, params: ExpressionParams): string => {\n validateCondition(condition, true, false);\n\n if (!condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n const attrName = generateAttributeName(params, condition.attr);\n return `${functionName}(${attrName})`;\n};\n\nconst buildLogicalExpression = (operator: string, conditions: Condition[], params: ExpressionParams): string => {\n if (!conditions || conditions.length === 0) {\n throw new Error(`At least one condition is required for ${operator} expression`);\n }\n\n const expressions = conditions.map((c) => buildExpression(c, params));\n return `(${expressions.join(` ${operator} `)})`;\n};\n\nexport const buildExpression = (condition: Condition, params: ExpressionParams): string => {\n if (!condition) return \"\";\n\n try {\n // Map of condition types to their expression builders\n const expressionBuilders: Record<ComparisonOperator | LogicalOperator, () => string> = {\n eq: () => buildComparisonExpression(condition, \"=\", params),\n ne: () => buildComparisonExpression(condition, \"<>\", params),\n lt: () => buildComparisonExpression(condition, \"<\", params),\n lte: () => buildComparisonExpression(condition, \"<=\", params),\n gt: () => buildComparisonExpression(condition, \">\", params),\n gte: () => buildComparisonExpression(condition, \">=\", params),\n between: () => buildBetweenExpression(condition, params),\n beginsWith: () => buildFunctionExpression(\"begins_with\", condition, params),\n contains: () => buildFunctionExpression(\"contains\", condition, params),\n attributeExists: () => buildAttributeFunction(\"attribute_exists\", condition, params),\n attributeNotExists: () => buildAttributeFunction(\"attribute_not_exists\", condition, params),\n and: () => {\n if (!condition.conditions) {\n throw new Error(\"Conditions array is required for AND operator\");\n }\n return buildLogicalExpression(\"AND\", condition.conditions, params);\n },\n or: () => {\n if (!condition.conditions) {\n throw new Error(\"Conditions array is required for OR operator\");\n }\n return buildLogicalExpression(\"OR\", condition.conditions, params);\n },\n not: () => {\n if (!condition.condition) {\n throw new Error(\"Condition is required for NOT operator\");\n }\n return `NOT (${buildExpression(condition.condition, params)})`;\n },\n };\n\n const builder = expressionBuilders[condition.type];\n if (!builder) {\n throw new Error(`Unknown condition type: ${condition.type}`);\n }\n\n return builder();\n } catch (error: unknown) {\n if (error instanceof Error) {\n console.error(`Error building expression for condition type ${condition.type}:`, error.message);\n } else {\n console.error(`Error building expression for condition type ${condition.type}:`, error);\n }\n throw error;\n }\n};\n\nexport const prepareExpressionParams = (\n condition?: Condition,\n): {\n expression?: string;\n names?: Record<string, string>;\n values?: Record<string, unknown>;\n} => {\n if (!condition) return {};\n\n const params: ExpressionParams = {\n expressionAttributeNames: {},\n expressionAttributeValues: {},\n valueCounter: { count: 0 },\n };\n\n const expression = buildExpression(condition, params);\n\n return {\n expression,\n names: Object.keys(params.expressionAttributeNames).length > 0 ? params.expressionAttributeNames : undefined,\n values: Object.keys(params.expressionAttributeValues).length > 0 ? params.expressionAttributeValues : undefined,\n };\n};\n","/**\n * Interface for DynamoDB command objects that can contain expressions\n */\nexport interface DynamoCommandWithExpressions {\n conditionExpression?: string;\n updateExpression?: string;\n filterExpression?: string;\n keyConditionExpression?: string;\n projectionExpression?: string;\n expressionAttributeNames?: Record<string, string>;\n expressionAttributeValues?: Record<string, unknown>;\n [key: string]: unknown;\n}\n\ntype ReadableDynamoCommand = {\n conditionExpression?: string;\n updateExpression?: string;\n filterExpression?: string;\n keyConditionExpression?: string;\n projectionExpression?: string;\n};\n\n/**\n * Utility function to debug a DynamoDB command by replacing all placeholders\n * in expressions with their actual values.\n *\n * @param command Any DynamoDB command with expressions and attribute maps\n * @returns An object with the same structure but with readable expressions\n */\nexport function debugCommand<T extends DynamoCommandWithExpressions>(\n command: T,\n): {\n raw: T;\n readable: ReadableDynamoCommand;\n} {\n // Create a copy of the command\n const result: ReadableDynamoCommand = {};\n\n function replaceAliases(expressionString: string) {\n if (!expressionString) {\n return expressionString;\n }\n\n let replacedString = expressionString;\n for (const alias in command.expressionAttributeNames) {\n const attributeName = command.expressionAttributeNames[alias];\n const regex = new RegExp(alias, \"g\");\n\n replacedString = replacedString.replace(regex, attributeName as string);\n }\n\n for (const alias in command.expressionAttributeValues) {\n let attributeValue = command.expressionAttributeValues[alias];\n\n // Handle Set objects for better readability\n if (attributeValue instanceof Set) {\n const array = Array.from(attributeValue);\n attributeValue = `Set(${array.length}){${array.map((v) => JSON.stringify(v)).join(\", \")}}`;\n } else {\n // Stringify other values for display\n attributeValue = JSON.stringify(attributeValue);\n }\n\n const regex = new RegExp(alias, \"g\");\n replacedString = replacedString.replace(regex, attributeValue as string);\n }\n\n return replacedString;\n }\n\n if (command.updateExpression) {\n result.updateExpression = replaceAliases(command.updateExpression);\n }\n if (command.conditionExpression) {\n result.conditionExpression = replaceAliases(command.conditionExpression);\n }\n if (command.filterExpression) {\n result.filterExpression = replaceAliases(command.filterExpression);\n }\n if (command.keyConditionExpression) {\n result.keyConditionExpression = replaceAliases(command.keyConditionExpression);\n }\n if (command.projectionExpression) {\n result.projectionExpression = replaceAliases(command.projectionExpression);\n }\n\n return {\n raw: command,\n readable: result,\n };\n}\n","import type { Condition, ConditionOperator, PrimaryKeyWithoutExpression } from \"../conditions\";\nimport {\n eq,\n ne,\n lt,\n lte,\n gt,\n gte,\n between,\n beginsWith,\n contains,\n attributeExists,\n attributeNotExists,\n and,\n or,\n not,\n} from \"../conditions\";\nimport type { Path, PathType } from \"./types\";\nimport type { TransactionBuilder } from \"./transaction-builder\";\nimport { buildExpression, generateAttributeName, generateValueName } from \"../expression\";\nimport { debugCommand } from \"../utils/debug-expression\";\nimport type { UpdateCommandParams } from \"./builder-types\";\nimport type { DynamoItem } from \"../types\";\n\n/**\n * Configuration options for DynamoDB update operations.\n */\nexport interface UpdateOptions {\n /** Optional condition that must be satisfied for the update to succeed */\n condition?: Condition;\n /** Determines which item attributes to include in the response */\n returnValues?: \"ALL_NEW\" | \"UPDATED_NEW\" | \"ALL_OLD\" | \"UPDATED_OLD\" | \"NONE\";\n}\n\n/**\n * Function type for executing DynamoDB update operations.\n * @typeParam T - The type of the item being updated\n */\ntype UpdateExecutor<T extends DynamoItem> = (params: UpdateCommandParams) => Promise<{ item?: T }>;\n\n/**\n * Represents a single update action within an update operation.\n * Each action modifies the item in a specific way:\n * - SET: Modify or add attributes\n * - REMOVE: Delete attributes\n * - ADD: Update numbers and sets\n * - DELETE: Remove elements from a set\n */\nexport type UpdateAction = {\n /** The type of update action */\n type: \"SET\" | \"REMOVE\" | \"ADD\" | \"DELETE\";\n /** The attribute path to update */\n path: string;\n /** The value to use in the update (not used for REMOVE actions) */\n value?: unknown;\n};\n\n/**\n * Type utility to get the element type of a set.\n * Extracts the element type from either a Set or Array type.\n * @typeParam T - The set or array type\n */\ntype SetElementType<T> = T extends Set<infer U> ? U : T extends Array<infer U> ? U : never;\n\n/**\n * Type utility to get the element type from a path that points to a set.\n * Combines PathType and SetElementType to get the element type at a specific path.\n * @typeParam T - The type of the item\n * @typeParam K - The path within the item\n */\ntype PathSetElementType<T, K extends Path<T>> = SetElementType<PathType<T, K>>;\n\n/**\n * Builder for creating DynamoDB update operations.\n *\n * The builder supports all DynamoDB update operations:\n * - SET: Modify or add attributes\n * - REMOVE: Delete attributes\n * - ADD: Update numbers and sets\n * - DELETE: Remove elements from a set\n *\n * @example\n * ```typescript\n * // Simple update\n * const result = await new UpdateBuilder(executor, 'dinosaurs', { id: 'TREX-001' })\n * .set('status', 'HUNTING')\n * .set('lastFed', new Date().toISOString())\n * .execute();\n *\n * // Complex update with multiple operations\n * const result = await new UpdateBuilder(executor, 'habitats', { id: 'PADDOCK-A' })\n * .set({\n * status: 'OCCUPIED',\n * occupants: 3,\n * 'metadata.lastInspection': new Date().toISOString()\n * })\n * .add('securityBreaches', 1)\n * .deleteElementsFromSet('suitableDinosaurs', ['VELOCIRAPTOR'])\n * .condition(op => op.gt('securityLevel', 8))\n * .returnValues('ALL_NEW')\n * .execute();\n * ```\n *\n * @typeParam T - The type of item being updated\n */\nexport class UpdateBuilder<T extends DynamoItem> {\n private updates: UpdateAction[] = [];\n private options: UpdateOptions = {\n returnValues: \"ALL_NEW\",\n };\n private readonly executor: UpdateExecutor<T>;\n private readonly tableName: string;\n private readonly key: PrimaryKeyWithoutExpression;\n\n constructor(executor: UpdateExecutor<T>, tableName: string, key: PrimaryKeyWithoutExpression) {\n this.executor = executor;\n this.tableName = tableName;\n this.key = key;\n }\n\n /**\n * Sets multiple attributes of an item using an object.\n *\n * @example\n * ```typescript\n * // Update multiple attributes\n * builder.set({\n * species: 'Tyrannosaurus Rex',\n * height: 20,\n * diet: 'CARNIVORE',\n * 'stats.threatLevel': 10\n * });\n * ```\n */\n set(values: Partial<T>): UpdateBuilder<T>;\n\n /**\n * Sets a single attribute to a specific value.\n *\n * @example\n * ```typescript\n * // Set simple attributes\n * builder\n * .set('status', 'SLEEPING')\n * .set('lastFeeding', new Date().toISOString());\n *\n * // Set nested attributes\n * builder\n * .set('location.zone', 'RESTRICTED')\n * .set('stats.health', 100);\n * ```\n */\n set<K extends Path<T>>(path: K, value: PathType<T, K>): UpdateBuilder<T>;\n set<K extends Path<T>>(valuesOrPath: K | Partial<T>, value?: PathType<T, K>): this {\n if (typeof valuesOrPath === \"object\") {\n for (const [key, value] of Object.entries(valuesOrPath)) {\n this.updates.push({\n type: \"SET\",\n path: key,\n value,\n });\n }\n } else {\n this.updates.push({\n type: \"SET\",\n path: valuesOrPath,\n value,\n });\n }\n\n return this;\n }\n\n /**\n * Removes an attribute from the item.\n *\n * @example\n * ```typescript\n * // Remove simple attributes\n * builder\n * .remove('temporaryTag')\n * .remove('previousLocation');\n *\n * // Remove nested attributes\n * builder\n * .remove('metadata.testData')\n * .remove('stats.experimentalMetrics');\n * ```\n *\n * @param path - The path to the attribute to remove\n * @returns The builder instance for method chaining\n */\n remove<K extends Path<T>>(path: K): this {\n this.updates.push({\n type: \"REMOVE\",\n path,\n });\n return this;\n }\n\n /**\n * Adds a value to a number attribute or adds elements to a set.\n *\n * @example\n * ```typescript\n * // Increment counters\n * builder\n * .add('escapeAttempts', 1)\n * .add('feedingCount', 1);\n *\n * // Add to sets\n * builder\n * .add('knownBehaviors', new Set(['PACK_HUNTING', 'AMBUSH_TACTICS']))\n * .add('visitedZones', new Set(['ZONE_A', 'ZONE_B']));\n * ```\n *\n * @param path - The path to the attribute to update\n * @param value - The value to add (number or set)\n * @returns The builder instance for method chaining\n */\n add<K extends Path<T>>(path: K, value: PathType<T, K>): this {\n this.updates.push({\n type: \"ADD\",\n path,\n value,\n });\n return this;\n }\n\n /**\n * Removes elements from a set attribute.\n *\n * @example\n * ```typescript\n * // Remove from sets using arrays\n * builder.deleteElementsFromSet(\n * 'allowedHabitats',\n * ['JUNGLE', 'COASTAL']\n * );\n *\n * // Remove from sets using Set DynamoItems\n * builder.deleteElementsFromSet(\n * 'knownBehaviors',\n * new Set(['NOCTURNAL', 'TERRITORIAL'])\n * );\n *\n * // Remove from nested sets\n * builder.deleteElementsFromSet(\n * 'stats.compatibleSpecies',\n * ['VELOCIRAPTOR', 'DILOPHOSAURUS']\n * );\n * ```\n *\n * @param path - The path to the set attribute\n * @param value - Elements to remove (array or Set)\n * @returns The builder instance for method chaining\n */\n deleteElementsFromSet<K extends Path<T>>(\n path: K,\n value: PathSetElementType<T, K>[] | Set<PathSetElementType<T, K>>,\n ): this {\n let valuesToDelete: Set<PathSetElementType<T, K>>;\n\n if (Array.isArray(value)) {\n valuesToDelete = new Set(value);\n } else {\n valuesToDelete = value;\n }\n\n this.updates.push({\n type: \"DELETE\",\n path,\n value: valuesToDelete,\n });\n return this;\n }\n\n /**\n * Adds a condition that must be satisfied for the update to succeed.\n *\n * @example\n * ```typescript\n * // Simple condition\n * builder.condition(op =>\n * op.eq('status', 'ACTIVE')\n * );\n *\n * // Health check condition\n * builder.condition(op =>\n * op.and([\n * op.gt('health', 50),\n * op.eq('status', 'HUNTING')\n * ])\n * );\n *\n * // Complex security condition\n * builder.condition(op =>\n * op.and([\n * op.attributeExists('securitySystem'),\n * op.eq('containmentStatus', 'SECURE'),\n * op.lt('aggressionLevel', 8)\n * ])\n * );\n *\n * // Version check (optimistic locking)\n * builder.condition(op =>\n * op.eq('version', currentVersion)\n * );\n * ```\n *\n * @param condition - Either a Condition DynamoItem or a callback function that builds the condition\n * @returns The builder instance for method chaining\n */\n condition(condition: Condition | ((op: ConditionOperator<T>) => Condition)): this {\n if (typeof condition === \"function\") {\n const conditionOperator: ConditionOperator<T> = {\n eq,\n ne,\n lt,\n lte,\n gt,\n gte,\n between,\n beginsWith,\n contains,\n attributeExists,\n attributeNotExists,\n and,\n or,\n not,\n };\n this.options.condition = condition(conditionOperator);\n } else {\n this.options.condition = condition;\n }\n return this;\n }\n\n /**\n * Sets which item attributes to include in the response.\n *\n * Available options:\n * - ALL_NEW: All attributes after the update\n * - UPDATED_NEW: Only updated attributes, new values\n * - ALL_OLD: All attributes before the update\n * - UPDATED_OLD: Only updated attributes, old values\n * - NONE: No attributes returned (default)\n *\n * @example\n * ```typescript\n * // Get complete updated dinosaur\n * const result = await builder\n * .set('status', 'SLEEPING')\n * .returnValues('ALL_NEW')\n * .execute();\n *\n * // Track specific attribute changes\n * const result = await builder\n * .set({\n * 'stats.health': 100,\n * 'stats.energy': 95\n * })\n * .returnValues('UPDATED_OLD')\n * .execute();\n *\n * if (result.item) {\n * console.log('Previous health:', result.item.stats?.health);\n * }\n * ```\n *\n * @param returnValues - Which attributes to return in the response\n * @returns The builder instance for method chaining\n */\n returnValues(returnValues: \"ALL_NEW\" | \"UPDATED_NEW\" | \"ALL_OLD\" | \"UPDATED_OLD\" | \"NONE\"): this {\n this.options.returnValues = returnValues;\n return this;\n }\n\n /**\n * Generate the DynamoDB command parameters\n */\n toDynamoCommand(): UpdateCommandParams {\n if (this.updates.length === 0) {\n throw new Error(\"No update actions specified\");\n }\n\n const expressionParams: {\n expressionAttributeNames: Record<string, string>;\n expressionAttributeValues: DynamoItem;\n valueCounter: { count: number };\n } = {\n expressionAttributeNames: {},\n expressionAttributeValues: {},\n valueCounter: { count: 0 },\n };\n\n // Build the update expression\n let updateExpression = \"\";\n\n // Group updates by type\n const setUpdates: UpdateAction[] = [];\n const removeUpdates: UpdateAction[] = [];\n const addUpdates: UpdateAction[] = [];\n const deleteUpdates: UpdateAction[] = [];\n\n for (const update of this.updates) {\n switch (update.type) {\n case \"SET\":\n setUpdates.push(update);\n break;\n case \"REMOVE\":\n removeUpdates.push(update);\n break;\n case \"ADD\":\n addUpdates.push(update);\n break;\n case \"DELETE\":\n deleteUpdates.push(update);\n break;\n }\n }\n\n // Build SET clause\n if (setUpdates.length > 0) {\n updateExpression += \"SET \";\n updateExpression += setUpdates\n .map((update) => {\n const attrName = generateAttributeName(expressionParams, update.path);\n const valueName = generateValueName(expressionParams, update.value);\n expressionParams.expressionAttributeValues[valueName] = update.value;\n return `${attrName} = ${valueName}`;\n })\n .join(\", \");\n }\n\n // Build REMOVE clause\n if (removeUpdates.length > 0) {\n if (updateExpression) {\n updateExpression += \" \";\n }\n updateExpression += \"REMOVE \";\n updateExpression += removeUpdates\n .map((update) => {\n return generateAttributeName(expressionParams, update.path);\n })\n .join(\", \");\n }\n\n // Build ADD clause\n if (addUpdates.length > 0) {\n if (updateExpression) {\n updateExpression += \" \";\n }\n updateExpression += \"ADD \";\n updateExpression += addUpdates\n .map((update) => {\n const attrName = generateAttributeName(expressionParams, update.path);\n const valueName = generateValueName(expressionParams, update.value);\n\n return `${attrName} ${valueName}`;\n })\n .join(\", \");\n }\n\n // Build DELETE clause\n if (deleteUpdates.length > 0) {\n if (updateExpression) {\n updateExpression += \" \";\n }\n\n updateExpression += \"DELETE \";\n updateExpression += deleteUpdates\n .map((update) => {\n const attrName = generateAttributeName(expressionParams, update.path);\n const valueName = generateValueName(expressionParams, update.value);\n\n return `${attrName} ${valueName}`;\n })\n .join(\", \");\n }\n\n // Build condition expression if provided\n let conditionExpression: string | undefined;\n if (this.options.condition) {\n conditionExpression = buildExpression(this.options.condition, expressionParams);\n }\n\n const { expressionAttributeNames, expressionAttributeValues } = expressionParams;\n\n return {\n tableName: this.tableName,\n key: this.key,\n updateExpression,\n conditionExpression,\n expressionAttributeNames: Object.keys(expressionAttributeNames).length > 0 ? expressionAttributeNames : undefined,\n expressionAttributeValues:\n Object.keys(expressionAttributeValues).length > 0 ? expressionAttributeValues : undefined,\n returnValues: this.options.returnValues,\n };\n }\n\n /**\n * Adds this update operation to a transaction.\n *\n * @example\n * ```typescript\n * const transaction = new TransactionBuilder(executor);\n *\n * // Update dinosaur status and habitat occupancy atomically\n * new UpdateBuilder(executor, 'dinosaurs', { id: 'TREX-001' })\n * .set('location', 'PADDOCK_A')\n * .set('status', 'CONTAINED')\n * .withTransaction(transaction);\n *\n * new UpdateBuilder(executor, 'habitats', { id: 'PADDOCK-A' })\n * .add('occupants', 1)\n * .set('lastOccupied', new Date().toISOString())\n * .withTransaction(transaction);\n *\n * // Execute all operations atomically\n * await transaction.execute();\n * ```\n *\n * @param transaction - The transaction builder to add this operation to\n * @returns The builder instance for method chaining\n */\n withTransaction(transaction: TransactionBuilder) {\n const command = this.toDynamoCommand();\n transaction.updateWithCommand(command);\n }\n\n /**\n * Gets a human-readable representation of the update command.\n *\n * @example\n * ```typescript\n * // Create complex update\n * const builder = new UpdateBuilder(executor, 'dinosaurs', { id: 'RAPTOR-001' })\n * .set({\n * status: 'HUNTING',\n * 'stats.health': 95,\n * 'behavior.lastObserved': new Date().toISOString()\n * })\n * .add('huntingSuccesses', 1)\n * .condition(op => op.gt('health', 50));\n *\n * // Debug the update\n * const debugInfo = builder.debug();\n * console.log('Update operation:', debugInfo);\n * ```\n *\n * @returns A readable representation of the update command with resolved expressions\n */\n debug(): DynamoItem {\n const command = this.toDynamoCommand();\n return debugCommand(command);\n }\n\n /**\n * Executes the update operation against DynamoDB.\n *\n * @example\n * ```typescript\n * try {\n * // Update dinosaur status with conditions\n * const result = await new UpdateBuilder(executor, 'dinosaurs', { id: 'TREX-001' })\n * .set({\n * status: 'FEEDING',\n * lastMeal: new Date().toISOString(),\n * 'stats.hunger': 0\n * })\n * .add('feedingCount', 1)\n * .condition(op =>\n * op.and([\n * op.gt('stats.hunger', 80),\n * op.eq('status', 'HUNTING')\n * ])\n * )\n * .returnValues('ALL_NEW')\n * .execute();\n *\n * if (result.item) {\n * console.log('Updated dinosaur:', result.item);\n * }\n * } catch (error) {\n * // Handle condition check failure\n * console.error('Failed to update dinosaur:', error);\n * // Check if dinosaur wasn't hungry enough\n * if (error.name === 'ConditionalCheckFailedException') {\n * console.log('Dinosaur not ready for feeding');\n * }\n * }\n * ```\n *\n * @returns A promise that resolves to an DynamoItem containing the updated item (if returnValues is set)\n * @throws {ConditionalCheckFailedException} If the condition check fails\n * @throws {Error} If the update operation fails for other reasons\n */\n async execute(): Promise<{ item?: T }> {\n const params = this.toDynamoCommand();\n return this.executor(params);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/conditions.ts","../../src/expression.ts","../../src/utils/debug-expression.ts","../../src/builders/update-builder.ts"],"names":["value"],"mappings":";;;AA+FO,IAAM,yBACX,GAAA,CAAC,IACD,KAAA,CAAC,MAAc,KAA+B,MAAA;AAAA,EAC5C,IAAA;AAAA,EACA,IAAA;AAAA,EACA;AACF,CAAA,CAAA;AAQK,IAAM,EAAA,GAAK,0BAA0B,IAAI,CAAA;AAQzC,IAAM,EAAA,GAAK,0BAA0B,IAAI,CAAA;AAQzC,IAAM,EAAA,GAAK,0BAA0B,IAAI,CAAA;AAQzC,IAAM,GAAA,GAAM,0BAA0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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA0CA,MAAM,OAAiC,GAAA;AACrC,IAAM,MAAA,MAAA,GAAS,KAAK,eAAgB,EAAA;AACpC,IAAO,OAAA,IAAA,CAAK,SAAS,MAAM,CAAA;AAAA;AAE/B","file":"update-builder.cjs","sourcesContent":["import type { Path, PathType } from \"./builders/types\";\nimport type { DynamoItem } from \"./types\";\n\n/**\n * Supported comparison operators for DynamoDB conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html AWS DynamoDB - Comparison Operator Reference}\n *\n * - eq: Equals (=)\n * - ne: Not equals (≠ / <>)\n * - lt: Less than (<)\n * - lte: Less than or equal to (≤)\n * - gt: Greater than (>)\n * - gte: Greater than or equal to (≥)\n * - between: Between two values (inclusive)\n * - beginsWith: Checks if string attribute begins with specified substring\n * - contains: Checks if string/set attribute contains specified value\n * - attributeExists: Checks if attribute exists\n * - attributeNotExists: Checks if attribute does not exist\n */\nexport type ComparisonOperator =\n | \"eq\"\n | \"ne\"\n | \"lt\"\n | \"lte\"\n | \"gt\"\n | \"gte\"\n | \"between\"\n | \"beginsWith\"\n | \"contains\"\n | \"attributeExists\"\n | \"attributeNotExists\";\n\n/**\n * Logical operators for combining multiple conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - Logical Operator Reference}\n *\n * - and: Evaluates to true if all conditions are true\n * - or: Evaluates to true if any condition is true\n * - not: Negate the result of a condition\n */\nexport type LogicalOperator = \"and\" | \"or\" | \"not\";\n\n/**\n * Represents a DynamoDB condition expression.\n * Can be either a comparison condition or a logical combination of conditions.\n *\n * @example\n * // Simple comparison condition\n * const condition: Condition = {\n * type: \"eq\",\n * attr: \"status\",\n * value: \"ACTIVE\"\n * };\n *\n * @example\n * // Logical combination of conditions\n * const condition: Condition = {\n * type: \"and\",\n * conditions: [\n * { type: \"eq\", attr: \"status\", value: \"ACTIVE\" },\n * { type: \"gt\", attr: \"age\", value: 5 }\n * ]\n * };\n */\nexport interface Condition {\n /** The type of condition (comparison or logical operator) */\n type: ComparisonOperator | LogicalOperator;\n /** The attribute name for comparison conditions */\n attr?: string;\n /** The value to compare against for comparison conditions */\n value?: unknown;\n /** Array of conditions for logical operators (and/or) */\n conditions?: Condition[];\n /** Single condition for the 'not' operator */\n condition?: Condition;\n}\n\n/**\n * Parameters used to build DynamoDB expression strings.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html Expression Attribute Names}\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeValues.html Expression Attribute Values}\n */\nexport interface ExpressionParams {\n /** Map of attribute name placeholders to actual attribute names */\n expressionAttributeNames: Record<string, string>;\n /** Map of value placeholders to actual values */\n expressionAttributeValues: DynamoItem;\n /** Counter for generating unique value placeholders */\n valueCounter: { count: number };\n}\n\n/**\n * Creates a comparison condition builder function for the specified operator.\n * @internal\n */\nexport const createComparisonCondition =\n (type: ComparisonOperator) =>\n (attr: string, value: unknown): Condition => ({\n type,\n attr,\n value,\n });\n\n/**\n * Creates an equals (=) condition\n * @example\n * eq(\"status\", \"ACTIVE\") // status = \"ACTIVE\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const eq = createComparisonCondition(\"eq\");\n\n/**\n * Creates a not equals (≠) condition\n * @example\n * ne(\"status\", \"DELETED\") // status <> \"DELETED\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const ne = createComparisonCondition(\"ne\");\n\n/**\n * Creates a less than (<) condition\n * @example\n * lt(\"age\", 18) // age < 18\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const lt = createComparisonCondition(\"lt\");\n\n/**\n * Creates a less than or equal to (≤) condition\n * @example\n * lte(\"age\", 18) // age <= 18\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const lte = createComparisonCondition(\"lte\");\n\n/**\n * Creates a greater than (>) condition\n * @example\n * gt(\"price\", 100) // price > 100\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const gt = createComparisonCondition(\"gt\");\n\n/**\n * Creates a greater than or equal to (≥) condition\n * @example\n * gte(\"price\", 100) // price >= 100\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}\n */\nexport const gte = createComparisonCondition(\"gte\");\n\n/**\n * Creates a between condition that checks if a value is within a range (inclusive)\n * @example\n * between(\"age\", 18, 65) // age BETWEEN 18 AND 65\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - BETWEEN}\n */\nexport const between = (attr: string, lower: unknown, upper: unknown): Condition => ({\n type: \"between\",\n attr,\n value: [lower, upper],\n});\n\n/**\n * Creates a begins_with condition that checks if a string attribute starts with a substring\n * @example\n * beginsWith(\"email\", \"@example.com\") // begins_with(email, \"@example.com\")\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - begins_with}\n */\nexport const beginsWith = createComparisonCondition(\"beginsWith\");\n\n/**\n * Creates a contains condition that checks if a string contains a substring or if a set contains an element\n * @example\n * contains(\"tags\", \"important\") // contains(tags, \"important\")\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - contains}\n */\nexport const contains = createComparisonCondition(\"contains\");\n\n/**\n * Creates a condition that checks if an attribute exists\n * @example\n * attributeExists(\"email\") // attribute_exists(email)\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_exists}\n */\nexport const attributeExists = (attr: string): Condition => ({\n type: \"attributeExists\",\n attr,\n});\n\n/**\n * Creates a condition that checks if an attribute does not exist\n * @example\n * attributeNotExists(\"deletedAt\") // attribute_not_exists(deletedAt)\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_not_exists}\n */\nexport const attributeNotExists = (attr: string): Condition => ({\n type: \"attributeNotExists\",\n attr,\n});\n\n// --- Logical Operators ---\n\n/**\n * Combines multiple conditions with AND operator\n * @example\n * and(\n * eq(\"status\", \"ACTIVE\"),\n * gt(\"age\", 18)\n * ) // status = \"ACTIVE\" AND age > 18\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - AND}\n */\nexport const and = (...conditions: Condition[]): Condition => ({\n type: \"and\",\n conditions,\n});\n\n/**\n * Combines multiple conditions with OR operator\n * @example\n * or(\n * eq(\"status\", \"PENDING\"),\n * eq(\"status\", \"PROCESSING\")\n * ) // status = \"PENDING\" OR status = \"PROCESSING\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - OR}\n */\nexport const or = (...conditions: Condition[]): Condition => ({\n type: \"or\",\n conditions,\n});\n\n/**\n * Negates a condition\n * @example\n * not(eq(\"status\", \"DELETED\")) // NOT status = \"DELETED\"\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - NOT}\n */\nexport const not = (condition: Condition): Condition => ({\n type: \"not\",\n condition,\n});\n\n/**\n * Type-safe operators for building key conditions in DynamoDB queries.\n * Only includes operators that are valid for key conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.KeyConditionExpressions AWS DynamoDB - Key Condition Expressions}\n *\n * @example\n * // Using with sort key conditions\n * table.query({\n * pk: \"USER#123\",\n * sk: op => op.beginsWith(\"ORDER#\")\n * })\n */\nexport type KeyConditionOperator = {\n /** Equals comparison for key attributes */\n eq: (value: unknown) => Condition;\n /** Less than comparison for key attributes */\n lt: (value: unknown) => Condition;\n /** Less than or equal comparison for key attributes */\n lte: (value: unknown) => Condition;\n /** Greater than comparison for key attributes */\n gt: (value: unknown) => Condition;\n /** Greater than or equal comparison for key attributes */\n gte: (value: unknown) => Condition;\n /** Between range comparison for key attributes */\n between: (lower: unknown, upper: unknown) => Condition;\n /** Begins with comparison for key attributes */\n beginsWith: (value: unknown) => Condition;\n /** Combines multiple key conditions with AND */\n and: (...conditions: Condition[]) => Condition;\n};\n\n/**\n * Type-safe operators for building conditions in DynamoDB operations.\n * Includes all available condition operators with proper type inference.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html AWS DynamoDB - Condition Expressions}\n *\n * @example\n * // Using with type-safe conditions\n * interface User {\n * status: string;\n * age: number;\n * email?: string;\n * }\n *\n * table.scan<User>()\n * .where(op => op.and(\n * op.eq(\"status\", \"ACTIVE\"),\n * op.gt(\"age\", 18),\n * op.attributeExists(\"email\")\n * ))\n *\n * @template T The type of the item being operated on\n */\nexport type ConditionOperator<T extends DynamoItem> = {\n eq: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n ne: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n lt: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n lte: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n gt: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n gte: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n between: <K extends Path<T>>(attr: K, lower: PathType<T, K>, upper: PathType<T, K>) => Condition;\n beginsWith: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n contains: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;\n attributeExists: <K extends Path<T>>(attr: K) => Condition;\n attributeNotExists: <K extends Path<T>>(attr: K) => Condition;\n and: (...conditions: Condition[]) => Condition;\n or: (...conditions: Condition[]) => Condition;\n not: (condition: Condition) => Condition;\n};\n\n/**\n * Primary key type for QUERY operations.\n * Allows building complex key conditions for the sort key.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html AWS DynamoDB - Query Operations}\n *\n * @example\n * // Query items with a specific partition key and sort key prefix\n * table.query({\n * pk: \"USER#123\",\n * sk: op => op.beginsWith(\"ORDER#2023\")\n * })\n *\n * @example\n * // Query items within a specific sort key range\n * table.query({\n * pk: \"USER#123\",\n * sk: op => op.between(\"ORDER#2023-01\", \"ORDER#2023-12\")\n * })\n */\nexport type PrimaryKey = {\n /** Partition key value */\n pk: string;\n /** Optional sort key condition builder */\n sk?: (op: KeyConditionOperator) => Condition;\n};\n\n/**\n * Primary key type for GET and DELETE operations.\n * Used when you need to specify exact key values without conditions.\n * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html AWS DynamoDB - Working with Items}\n *\n * @example\n * // Get a specific item by its complete primary key\n * table.get({\n * pk: \"USER#123\",\n * sk: \"PROFILE#123\"\n * })\n *\n * @example\n * // Delete a specific item by its complete primary key\n * table.delete({\n * pk: \"USER#123\",\n * sk: \"ORDER#456\"\n * })\n */\nexport type PrimaryKeyWithoutExpression = {\n /** Partition key value */\n pk: string;\n /** Optional sort key value */\n sk?: string;\n};\n","import type { ComparisonOperator, Condition, ExpressionParams, LogicalOperator } from \"./conditions\";\n\nexport const generateAttributeName = (params: ExpressionParams, attr: string): string => {\n // Check if the attribute already exists in the expressionAttributeNames\n for (const [existingName, existingAttr] of Object.entries(params.expressionAttributeNames)) {\n if (existingAttr === attr) {\n return existingName;\n }\n }\n\n // If not found, create a new attribute name\n const attrName = `#${Object.keys(params.expressionAttributeNames).length}`;\n params.expressionAttributeNames[attrName] = attr;\n return attrName;\n};\n\nexport const generateValueName = (params: ExpressionParams, value: unknown): string => {\n const valueName = `:${params.valueCounter.count++}`;\n params.expressionAttributeValues[valueName] = value;\n return valueName;\n};\n\nconst validateCondition = (condition: Condition, requiresAttr = true, requiresValue = true): void => {\n if (requiresAttr && !condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n if (requiresValue && condition.value === undefined) {\n throw new Error(`Value is required for ${condition.type} condition`);\n }\n};\n\nconst buildComparisonExpression = (condition: Condition, operator: string, params: ExpressionParams): string => {\n validateCondition(condition);\n\n if (!condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n const attrName = generateAttributeName(params, condition.attr);\n const valueName = generateValueName(params, condition.value);\n\n return `${attrName} ${operator} ${valueName}`;\n};\n\nconst buildBetweenExpression = (condition: Condition, params: ExpressionParams): string => {\n validateCondition(condition);\n\n if (!condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n if (!Array.isArray(condition.value) || condition.value.length !== 2) {\n throw new Error(\"Between condition requires an array of two values\");\n }\n\n const attrName = generateAttributeName(params, condition.attr);\n const lowerName = generateValueName(params, condition.value[0]);\n const upperName = generateValueName(params, condition.value[1]);\n\n return `${attrName} BETWEEN ${lowerName} AND ${upperName}`;\n};\n\nconst buildFunctionExpression = (functionName: string, condition: Condition, params: ExpressionParams): string => {\n validateCondition(condition);\n\n if (!condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n const attrName = generateAttributeName(params, condition.attr);\n const valueName = generateValueName(params, condition.value);\n\n return `${functionName}(${attrName}, ${valueName})`;\n};\n\nconst buildAttributeFunction = (functionName: string, condition: Condition, params: ExpressionParams): string => {\n validateCondition(condition, true, false);\n\n if (!condition.attr) {\n throw new Error(`Attribute is required for ${condition.type} condition`);\n }\n\n const attrName = generateAttributeName(params, condition.attr);\n return `${functionName}(${attrName})`;\n};\n\nconst buildLogicalExpression = (operator: string, conditions: Condition[], params: ExpressionParams): string => {\n if (!conditions || conditions.length === 0) {\n throw new Error(`At least one condition is required for ${operator} expression`);\n }\n\n const expressions = conditions.map((c) => buildExpression(c, params));\n return `(${expressions.join(` ${operator} `)})`;\n};\n\nexport const buildExpression = (condition: Condition, params: ExpressionParams): string => {\n if (!condition) return \"\";\n\n try {\n // Map of condition types to their expression builders\n const expressionBuilders: Record<ComparisonOperator | LogicalOperator, () => string> = {\n eq: () => buildComparisonExpression(condition, \"=\", params),\n ne: () => buildComparisonExpression(condition, \"<>\", params),\n lt: () => buildComparisonExpression(condition, \"<\", params),\n lte: () => buildComparisonExpression(condition, \"<=\", params),\n gt: () => buildComparisonExpression(condition, \">\", params),\n gte: () => buildComparisonExpression(condition, \">=\", params),\n between: () => buildBetweenExpression(condition, params),\n beginsWith: () => buildFunctionExpression(\"begins_with\", condition, params),\n contains: () => buildFunctionExpression(\"contains\", condition, params),\n attributeExists: () => buildAttributeFunction(\"attribute_exists\", condition, params),\n attributeNotExists: () => buildAttributeFunction(\"attribute_not_exists\", condition, params),\n and: () => {\n if (!condition.conditions) {\n throw new Error(\"Conditions array is required for AND operator\");\n }\n return buildLogicalExpression(\"AND\", condition.conditions, params);\n },\n or: () => {\n if (!condition.conditions) {\n throw new Error(\"Conditions array is required for OR operator\");\n }\n return buildLogicalExpression(\"OR\", condition.conditions, params);\n },\n not: () => {\n if (!condition.condition) {\n throw new Error(\"Condition is required for NOT operator\");\n }\n return `NOT (${buildExpression(condition.condition, params)})`;\n },\n };\n\n const builder = expressionBuilders[condition.type];\n if (!builder) {\n throw new Error(`Unknown condition type: ${condition.type}`);\n }\n\n return builder();\n } catch (error: unknown) {\n if (error instanceof Error) {\n console.error(`Error building expression for condition type ${condition.type}:`, error.message);\n } else {\n console.error(`Error building expression for condition type ${condition.type}:`, error);\n }\n throw error;\n }\n};\n\nexport const prepareExpressionParams = (\n condition?: Condition,\n): {\n expression?: string;\n names?: Record<string, string>;\n values?: Record<string, unknown>;\n} => {\n if (!condition) return {};\n\n const params: ExpressionParams = {\n expressionAttributeNames: {},\n expressionAttributeValues: {},\n valueCounter: { count: 0 },\n };\n\n const expression = buildExpression(condition, params);\n\n return {\n expression,\n names: Object.keys(params.expressionAttributeNames).length > 0 ? params.expressionAttributeNames : undefined,\n values: Object.keys(params.expressionAttributeValues).length > 0 ? params.expressionAttributeValues : undefined,\n };\n};\n","/**\n * Interface for DynamoDB command objects that can contain expressions\n */\nexport interface DynamoCommandWithExpressions {\n conditionExpression?: string;\n updateExpression?: string;\n filterExpression?: string;\n keyConditionExpression?: string;\n projectionExpression?: string;\n expressionAttributeNames?: Record<string, string>;\n expressionAttributeValues?: Record<string, unknown>;\n [key: string]: unknown;\n}\n\ntype ReadableDynamoCommand = {\n conditionExpression?: string;\n updateExpression?: string;\n filterExpression?: string;\n keyConditionExpression?: string;\n projectionExpression?: string;\n};\n\n/**\n * Utility function to debug a DynamoDB command by replacing all placeholders\n * in expressions with their actual values.\n *\n * @param command Any DynamoDB command with expressions and attribute maps\n * @returns An object with the same structure but with readable expressions\n */\nexport function debugCommand<T extends DynamoCommandWithExpressions>(\n command: T,\n): {\n raw: T;\n readable: ReadableDynamoCommand;\n} {\n // Create a copy of the command\n const result: ReadableDynamoCommand = {};\n\n function replaceAliases(expressionString: string) {\n if (!expressionString) {\n return expressionString;\n }\n\n let replacedString = expressionString;\n for (const alias in command.expressionAttributeNames) {\n const attributeName = command.expressionAttributeNames[alias];\n const regex = new RegExp(alias, \"g\");\n\n replacedString = replacedString.replace(regex, attributeName as string);\n }\n\n for (const alias in command.expressionAttributeValues) {\n let attributeValue = command.expressionAttributeValues[alias];\n\n // Handle Set objects for better readability\n if (attributeValue instanceof Set) {\n const array = Array.from(attributeValue);\n attributeValue = `Set(${array.length}){${array.map((v) => JSON.stringify(v)).join(\", \")}}`;\n } else {\n // Stringify other values for display\n attributeValue = JSON.stringify(attributeValue);\n }\n\n const regex = new RegExp(alias, \"g\");\n replacedString = replacedString.replace(regex, attributeValue as string);\n }\n\n return replacedString;\n }\n\n if (command.updateExpression) {\n result.updateExpression = replaceAliases(command.updateExpression);\n }\n if (command.conditionExpression) {\n result.conditionExpression = replaceAliases(command.conditionExpression);\n }\n if (command.filterExpression) {\n result.filterExpression = replaceAliases(command.filterExpression);\n }\n if (command.keyConditionExpression) {\n result.keyConditionExpression = replaceAliases(command.keyConditionExpression);\n }\n if (command.projectionExpression) {\n result.projectionExpression = replaceAliases(command.projectionExpression);\n }\n\n return {\n raw: command,\n readable: result,\n };\n}\n","import type { Condition, ConditionOperator, PrimaryKeyWithoutExpression } from \"../conditions\";\nimport {\n eq,\n ne,\n lt,\n lte,\n gt,\n gte,\n between,\n beginsWith,\n contains,\n attributeExists,\n attributeNotExists,\n and,\n or,\n not,\n} from \"../conditions\";\nimport type { Path, PathType } from \"./types\";\nimport type { TransactionBuilder } from \"./transaction-builder\";\nimport { buildExpression, generateAttributeName, generateValueName } from \"../expression\";\nimport { debugCommand } from \"../utils/debug-expression\";\nimport type { UpdateCommandParams } from \"./builder-types\";\nimport type { DynamoItem } from \"../types\";\n\n/**\n * Configuration options for DynamoDB update operations.\n */\nexport interface UpdateOptions {\n /** Optional condition that must be satisfied for the update to succeed */\n condition?: Condition;\n /** Determines which item attributes to include in the response */\n returnValues?: \"ALL_NEW\" | \"UPDATED_NEW\" | \"ALL_OLD\" | \"UPDATED_OLD\" | \"NONE\";\n}\n\n/**\n * Function type for executing DynamoDB update operations.\n * @typeParam T - The type of the item being updated\n */\ntype UpdateExecutor<T extends DynamoItem> = (params: UpdateCommandParams) => Promise<{ item?: T }>;\n\n/**\n * Represents a single update action within an update operation.\n * Each action modifies the item in a specific way:\n * - SET: Modify or add attributes\n * - REMOVE: Delete attributes\n * - ADD: Update numbers and sets\n * - DELETE: Remove elements from a set\n */\nexport type UpdateAction = {\n /** The type of update action */\n type: \"SET\" | \"REMOVE\" | \"ADD\" | \"DELETE\";\n /** The attribute path to update */\n path: string;\n /** The value to use in the update (not used for REMOVE actions) */\n value?: unknown;\n};\n\n/**\n * Type utility to get the element type of a set.\n * Extracts the element type from either a Set or Array type.\n * @typeParam T - The set or array type\n */\ntype SetElementType<T> = T extends Set<infer U> ? U : T extends Array<infer U> ? U : never;\n\n/**\n * Type utility to get the element type from a path that points to a set.\n * Combines PathType and SetElementType to get the element type at a specific path.\n * @typeParam T - The type of the item\n * @typeParam K - The path within the item\n */\ntype PathSetElementType<T, K extends Path<T>> = SetElementType<PathType<T, K>>;\n\n/**\n * Builder for creating DynamoDB update operations.\n *\n * The builder supports all DynamoDB update operations:\n * - SET: Modify or add attributes\n * - REMOVE: Delete attributes\n * - ADD: Update numbers and sets\n * - DELETE: Remove elements from a set\n *\n * @example\n * ```typescript\n * // Simple update\n * const result = await new UpdateBuilder(executor, 'dinosaurs', { id: 'TREX-001' })\n * .set('status', 'HUNTING')\n * .set('lastFed', new Date().toISOString())\n * .execute();\n *\n * // Complex update with multiple operations\n * const result = await new UpdateBuilder(executor, 'habitats', { id: 'PADDOCK-A' })\n * .set({\n * status: 'OCCUPIED',\n * occupants: 3,\n * 'metadata.lastInspection': new Date().toISOString()\n * })\n * .add('securityBreaches', 1)\n * .deleteElementsFromSet('suitableDinosaurs', ['VELOCIRAPTOR'])\n * .condition(op => op.gt('securityLevel', 8))\n * .returnValues('ALL_NEW')\n * .execute();\n * ```\n *\n * @typeParam T - The type of item being updated\n */\nexport class UpdateBuilder<T extends DynamoItem> {\n private updates: UpdateAction[] = [];\n private options: UpdateOptions = {\n returnValues: \"ALL_NEW\",\n };\n private readonly executor: UpdateExecutor<T>;\n private readonly tableName: string;\n private readonly key: PrimaryKeyWithoutExpression;\n\n constructor(executor: UpdateExecutor<T>, tableName: string, key: PrimaryKeyWithoutExpression) {\n this.executor = executor;\n this.tableName = tableName;\n this.key = key;\n }\n\n /**\n * Sets multiple attributes of an item using an object.\n *\n * @example\n * ```typescript\n * // Update multiple attributes\n * builder.set({\n * species: 'Tyrannosaurus Rex',\n * height: 20,\n * diet: 'CARNIVORE',\n * 'stats.threatLevel': 10\n * });\n * ```\n */\n set(values: Partial<T>): UpdateBuilder<T>;\n\n /**\n * Sets a single attribute to a specific value.\n *\n * @example\n * ```typescript\n * // Set simple attributes\n * builder\n * .set('status', 'SLEEPING')\n * .set('lastFeeding', new Date().toISOString());\n *\n * // Set nested attributes\n * builder\n * .set('location.zone', 'RESTRICTED')\n * .set('stats.health', 100);\n * ```\n */\n set<K extends Path<T>>(path: K, value: PathType<T, K>): UpdateBuilder<T>;\n set<K extends Path<T>>(valuesOrPath: K | Partial<T>, value?: PathType<T, K>): this {\n if (typeof valuesOrPath === \"object\") {\n for (const [key, value] of Object.entries(valuesOrPath)) {\n this.updates.push({\n type: \"SET\",\n path: key,\n value,\n });\n }\n } else {\n this.updates.push({\n type: \"SET\",\n path: valuesOrPath,\n value,\n });\n }\n\n return this;\n }\n\n /**\n * Removes an attribute from the item.\n *\n * @example\n * ```typescript\n * // Remove simple attributes\n * builder\n * .remove('temporaryTag')\n * .remove('previousLocation');\n *\n * // Remove nested attributes\n * builder\n * .remove('metadata.testData')\n * .remove('stats.experimentalMetrics');\n * ```\n *\n * @param path - The path to the attribute to remove\n * @returns The builder instance for method chaining\n */\n remove<K extends Path<T>>(path: K): this {\n this.updates.push({\n type: \"REMOVE\",\n path,\n });\n return this;\n }\n\n /**\n * Adds a value to a number attribute or adds elements to a set.\n *\n * @example\n * ```typescript\n * // Increment counters\n * builder\n * .add('escapeAttempts', 1)\n * .add('feedingCount', 1);\n *\n * // Add to sets\n * builder\n * .add('knownBehaviors', new Set(['PACK_HUNTING', 'AMBUSH_TACTICS']))\n * .add('visitedZones', new Set(['ZONE_A', 'ZONE_B']));\n * ```\n *\n * @param path - The path to the attribute to update\n * @param value - The value to add (number or set)\n * @returns The builder instance for method chaining\n */\n add<K extends Path<T>>(path: K, value: PathType<T, K>): this {\n this.updates.push({\n type: \"ADD\",\n path,\n value,\n });\n return this;\n }\n\n /**\n * Removes elements from a set attribute.\n *\n * @example\n * ```typescript\n * // Remove from sets using arrays\n * builder.deleteElementsFromSet(\n * 'allowedHabitats',\n * ['JUNGLE', 'COASTAL']\n * );\n *\n * // Remove from sets using Set DynamoItems\n * builder.deleteElementsFromSet(\n * 'knownBehaviors',\n * new Set(['NOCTURNAL', 'TERRITORIAL'])\n * );\n *\n * // Remove from nested sets\n * builder.deleteElementsFromSet(\n * 'stats.compatibleSpecies',\n * ['VELOCIRAPTOR', 'DILOPHOSAURUS']\n * );\n * ```\n *\n * @param path - The path to the set attribute\n * @param value - Elements to remove (array or Set)\n * @returns The builder instance for method chaining\n */\n deleteElementsFromSet<K extends Path<T>>(\n path: K,\n value: PathSetElementType<T, K>[] | Set<PathSetElementType<T, K>>,\n ): this {\n let valuesToDelete: Set<PathSetElementType<T, K>>;\n\n if (Array.isArray(value)) {\n valuesToDelete = new Set(value);\n } else {\n valuesToDelete = value;\n }\n\n this.updates.push({\n type: \"DELETE\",\n path,\n value: valuesToDelete,\n });\n return this;\n }\n\n /**\n * Adds a condition that must be satisfied for the update to succeed.\n *\n * @example\n * ```typescript\n * // Simple condition\n * builder.condition(op =>\n * op.eq('status', 'ACTIVE')\n * );\n *\n * // Health check condition\n * builder.condition(op =>\n * op.and([\n * op.gt('health', 50),\n * op.eq('status', 'HUNTING')\n * ])\n * );\n *\n * // Complex security condition\n * builder.condition(op =>\n * op.and([\n * op.attributeExists('securitySystem'),\n * op.eq('containmentStatus', 'SECURE'),\n * op.lt('aggressionLevel', 8)\n * ])\n * );\n *\n * // Version check (optimistic locking)\n * builder.condition(op =>\n * op.eq('version', currentVersion)\n * );\n * ```\n *\n * @param condition - Either a Condition DynamoItem or a callback function that builds the condition\n * @returns The builder instance for method chaining\n */\n condition(condition: Condition | ((op: ConditionOperator<T>) => Condition)): this {\n if (typeof condition === \"function\") {\n const conditionOperator: ConditionOperator<T> = {\n eq,\n ne,\n lt,\n lte,\n gt,\n gte,\n between,\n beginsWith,\n contains,\n attributeExists,\n attributeNotExists,\n and,\n or,\n not,\n };\n this.options.condition = condition(conditionOperator);\n } else {\n this.options.condition = condition;\n }\n return this;\n }\n\n /**\n * Sets which item attributes to include in the response.\n *\n * Available options:\n * - ALL_NEW: All attributes after the update\n * - UPDATED_NEW: Only updated attributes, new values\n * - ALL_OLD: All attributes before the update\n * - UPDATED_OLD: Only updated attributes, old values\n * - NONE: No attributes returned (default)\n *\n * @example\n * ```typescript\n * // Get complete updated dinosaur\n * const result = await builder\n * .set('status', 'SLEEPING')\n * .returnValues('ALL_NEW')\n * .execute();\n *\n * // Track specific attribute changes\n * const result = await builder\n * .set({\n * 'stats.health': 100,\n * 'stats.energy': 95\n * })\n * .returnValues('UPDATED_OLD')\n * .execute();\n *\n * if (result.item) {\n * console.log('Previous health:', result.item.stats?.health);\n * }\n * ```\n *\n * @param returnValues - Which attributes to return in the response\n * @returns The builder instance for method chaining\n */\n returnValues(returnValues: \"ALL_NEW\" | \"UPDATED_NEW\" | \"ALL_OLD\" | \"UPDATED_OLD\" | \"NONE\"): this {\n this.options.returnValues = returnValues;\n return this;\n }\n\n /**\n * Generate the DynamoDB command parameters\n */\n toDynamoCommand(): UpdateCommandParams {\n if (this.updates.length === 0) {\n throw new Error(\"No update actions specified\");\n }\n\n const expressionParams: {\n expressionAttributeNames: Record<string, string>;\n expressionAttributeValues: DynamoItem;\n valueCounter: { count: number };\n } = {\n expressionAttributeNames: {},\n expressionAttributeValues: {},\n valueCounter: { count: 0 },\n };\n\n // Build the update expression\n let updateExpression = \"\";\n\n // Group updates by type\n const setUpdates: UpdateAction[] = [];\n const removeUpdates: UpdateAction[] = [];\n const addUpdates: UpdateAction[] = [];\n const deleteUpdates: UpdateAction[] = [];\n\n for (const update of this.updates) {\n switch (update.type) {\n case \"SET\":\n setUpdates.push(update);\n break;\n case \"REMOVE\":\n removeUpdates.push(update);\n break;\n case \"ADD\":\n addUpdates.push(update);\n break;\n case \"DELETE\":\n deleteUpdates.push(update);\n break;\n }\n }\n\n // Build SET clause\n if (setUpdates.length > 0) {\n updateExpression += \"SET \";\n updateExpression += setUpdates\n .map((update) => {\n const attrName = generateAttributeName(expressionParams, update.path);\n const valueName = generateValueName(expressionParams, update.value);\n expressionParams.expressionAttributeValues[valueName] = update.value;\n return `${attrName} = ${valueName}`;\n })\n .join(\", \");\n }\n\n // Build REMOVE clause\n if (removeUpdates.length > 0) {\n if (updateExpression) {\n updateExpression += \" \";\n }\n updateExpression += \"REMOVE \";\n updateExpression += removeUpdates\n .map((update) => {\n return generateAttributeName(expressionParams, update.path);\n })\n .join(\", \");\n }\n\n // Build ADD clause\n if (addUpdates.length > 0) {\n if (updateExpression) {\n updateExpression += \" \";\n }\n updateExpression += \"ADD \";\n updateExpression += addUpdates\n .map((update) => {\n const attrName = generateAttributeName(expressionParams, update.path);\n const valueName = generateValueName(expressionParams, update.value);\n\n return `${attrName} ${valueName}`;\n })\n .join(\", \");\n }\n\n // Build DELETE clause\n if (deleteUpdates.length > 0) {\n if (updateExpression) {\n updateExpression += \" \";\n }\n\n updateExpression += \"DELETE \";\n updateExpression += deleteUpdates\n .map((update) => {\n const attrName = generateAttributeName(expressionParams, update.path);\n const valueName = generateValueName(expressionParams, update.value);\n\n return `${attrName} ${valueName}`;\n })\n .join(\", \");\n }\n\n // Build condition expression if provided\n let conditionExpression: string | undefined;\n if (this.options.condition) {\n conditionExpression = buildExpression(this.options.condition, expressionParams);\n }\n\n const { expressionAttributeNames, expressionAttributeValues } = expressionParams;\n\n return {\n tableName: this.tableName,\n key: this.key,\n updateExpression,\n conditionExpression,\n expressionAttributeNames: Object.keys(expressionAttributeNames).length > 0 ? expressionAttributeNames : undefined,\n expressionAttributeValues:\n Object.keys(expressionAttributeValues).length > 0 ? expressionAttributeValues : undefined,\n returnValues: this.options.returnValues,\n };\n }\n\n /**\n * Adds this update operation to a transaction.\n *\n * @example\n * ```typescript\n * const transaction = new TransactionBuilder(executor);\n *\n * // Update dinosaur status and habitat occupancy atomically\n * new UpdateBuilder(executor, 'dinosaurs', { id: 'TREX-001' })\n * .set('location', 'PADDOCK_A')\n * .set('status', 'CONTAINED')\n * .withTransaction(transaction);\n *\n * new UpdateBuilder(executor, 'habitats', { id: 'PADDOCK-A' })\n * .add('occupants', 1)\n * .set('lastOccupied', new Date().toISOString())\n * .withTransaction(transaction);\n *\n * // Execute all operations atomically\n * await transaction.execute();\n * ```\n *\n * @param transaction - The transaction builder to add this operation to\n * @returns The builder instance for method chaining\n */\n withTransaction(transaction: TransactionBuilder) {\n const command = this.toDynamoCommand();\n transaction.updateWithCommand(command);\n }\n\n /**\n * Gets a human-readable representation of the update command.\n *\n * @example\n * ```typescript\n * // Create complex update\n * const builder = new UpdateBuilder(executor, 'dinosaurs', { id: 'RAPTOR-001' })\n * .set({\n * status: 'HUNTING',\n * 'stats.health': 95,\n * 'behavior.lastObserved': new Date().toISOString()\n * })\n * .add('huntingSuccesses', 1)\n * .condition(op => op.gt('health', 50));\n *\n * // Debug the update\n * const debugInfo = builder.debug();\n * console.log('Update operation:', debugInfo);\n * ```\n *\n * @returns A readable representation of the update command with resolved expressions\n */\n debug(): DynamoItem {\n const command = this.toDynamoCommand();\n return debugCommand(command);\n }\n\n /**\n * Executes the update operation against DynamoDB.\n *\n * @example\n * ```typescript\n * try {\n * // Update dinosaur status with conditions\n * const result = await new UpdateBuilder(executor, 'dinosaurs', { id: 'TREX-001' })\n * .set({\n * status: 'FEEDING',\n * lastMeal: new Date().toISOString(),\n * 'stats.hunger': 0\n * })\n * .add('feedingCount', 1)\n * .condition(op =>\n * op.and([\n * op.gt('stats.hunger', 80),\n * op.eq('status', 'HUNTING')\n * ])\n * )\n * .returnValues('ALL_NEW')\n * .execute();\n *\n * if (result.item) {\n * console.log('Updated dinosaur:', result.item);\n * }\n * } catch (error) {\n * // Handle condition check failure\n * console.error('Failed to update dinosaur:', error);\n * // Check if dinosaur wasn't hungry enough\n * if (error.name === 'ConditionalCheckFailedException') {\n * console.log('Dinosaur not ready for feeding');\n * }\n * }\n * ```\n *\n * @returns A promise that resolves to an DynamoItem containing the updated item (if returnValues is set)\n * @throws {ConditionalCheckFailedException} If the condition check fails\n * @throws {Error} If the update operation fails for other reasons\n */\n async execute(): Promise<{ item?: T }> {\n const params = this.toDynamoCommand();\n return this.executor(params);\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { P as PrimaryKeyWithoutExpression, c as Path, d as PathType, C as Condition, b as ConditionOperator } from '../conditions-ChhQWd6z.cjs';
|
|
2
2
|
import { TransactionBuilder } from './transaction-builder.cjs';
|
|
3
3
|
import { U as UpdateCommandParams } from '../builder-types-DtwbqMeF.cjs';
|
|
4
4
|
import { DynamoItem } from '../types.cjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { P as PrimaryKeyWithoutExpression, c as Path, d as PathType, C as Condition, b as ConditionOperator } from '../conditions--ld9a78i.js';
|
|
2
2
|
import { TransactionBuilder } from './transaction-builder.js';
|
|
3
3
|
import { U as UpdateCommandParams } from '../builder-types-C_PDZhnP.js';
|
|
4
4
|
import { DynamoItem } from '../types.js';
|