import { AttributeValue, UpdateItemCommandInput, UpdateItemCommandOutput } from '@aws-sdk/client-dynamodb'; /** * This class helps with writes or updates to single items in DDB */ declare class Updater { private _ddb; private _params; private _marked; private _createdAtState; private _updatedAtState; private _internals; constructor(config: { region: string; }, table: string, key: { [key: string]: AttributeValue; }); /** * Sets the TableName parameter for the command input. * This method is not necessary if you provided the table name in the construction of Scanner. * * @param name - string of the table name to update on * @returns Updater with populated params */ table(name: string): Updater; /** * Marks the provided attribute names as being of type Set. * This is used during the final conversion of internal params to the command input. * * @param arr - list of attribute names to mark * @returns Updater with populated params */ mark(arr?: string[]): Updater; /** * Sets the Key value of the command input. This method is not required if the Updater is initialized with a key. * * @param key - object of the key of the item to update * @returns Updater with populated params */ key(key: { [key: string]: AttributeValue; }): Updater; /** * Helper method to mark you don't want to update the createdAt attribute of the item you are updating. * * @returns Updater with populated params */ disableCreatedAt(): Updater; /** * Helper method to set the createdAt timespace of the item you are creating. * * @param str - string or Date to assign to createdAt attribute * @returns Updater with populated params */ createdAt(str: string | Date): Updater; /** * Helper method to mark you don't want to update the updatedAt attribute of the item you are updating. * * @returns Updater with populated params */ disableUpdatedAt(): Updater; /** * Helper method to set the updatedAt timestamp of the item you are updating. * * @param str - string or Date to assign to updatedAt attribute * @returns Updater with populated params */ updatedAt(str: string | Date): Updater; /** * This is an additional method that helps us with using the optimistic locking technique. If you use this method, * you NO longer need to add the 'and #rev = :rev' and 'SET #rev = #rev + :_addOne' expressions * * @param rev - number of the rev to save * @returns Updated with populated params */ rev(rev: number): Updater; /** * This is the recommended method for adding new items or updating existing items. * Pass the new item or the various new attribute names and/or new attribte values of an existing item. * * @param item - object of a new item or new values for an existing item * @returns Updater with populated params */ item(item: { [key: string]: AttributeValue; }): Updater; /** * Same as using UpdateExpression with the SET clause to set the UpdateExpression parameter of the command input. * IMPORTANT: your expression should NOT include the 'SET' keyword * * @param expression - string to update * @returns Updater with populated params * * @example Set a new attribute to be a new value * ```ts * # Usage * Updater.names({ '#newAttribute': 'newAttribute' }).values({ ':newValue': { S: 'newValue' } }).set('#newAttribute = :newValue') * ``` */ set(expression: string): Updater; /** * Same as using UpdateExpression with the ADD clause to set the UpdateExpression parameter of the command input. * IMPORTANT: your expression should NOT include the 'ADD' keyword * Use to add a number to a numerical attribute, add a new attribute, or add an element to a set * * @param expression - string to update * @returns Updater with populated params * * @example Add newValye to myNum * ```ts * # Usage * Updater.names({ '#myNum': 'myNum' }).values({ ':newValue': { S: 'newValue' } }).add('#myNum :newValue') * ``` */ add(expression: string): Updater; /** * Same as using UpdateExpression with the REMOVE clause to set the UpdateExpression parameter of the command input. * IMPORTANT: your expression should NOT include the 'REMOVE' keyword * Use to remove attribute(s) from an item that exists * * @param expression - string to update * @returns Updater with populated params * * @example Remove attributeToRemove * ```ts * # Usage * Updater.names({ '#attributeToRemove': 'attributeToRemove' }).remove('#attributeToRemove') * ``` */ remove(expression: string | string[]): Updater; /** * Same as using UpdateExpression with the DELETE clause to set the UpdateExpression parameter of the command input. * IMPORTANT: your expression should NOT include the 'DELETE' keyword * Use to delete an item from a set that is the value of an attribute * * @param expression - string to update * @returns Updater with populated params * * @example Remove attributeToRemove * ```ts * # Usage * Updater.names({ '#itemToDeleteFrom': 'itemToDeleteFrom' }).values({ ':itemToDelete': { S: 'itemToDelete' } }).delete('#itemToDeleteFrom :itemToDelete') * ``` */ delete(expression: string): Updater; /** * Sets the ExpressionAttributeNames of the command input. * The following are some use cases for using ExpressionAttributeNames: * To access an attribute whose name conflicts with a DynamoDB reserved word: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ReservedWords.html * To create a placeholder for repeating occurrences of an attribute name in an expression. * To prevent special characters in an attribute name from being misinterpreted in an expression. * Use the # character in an expression to dereference an attribute name. * * @param obj - object of one or more substitution tokens for attribute names in an expression * @returns Updater with populated params * * @example Using the reserved word 'Percentile' in your request * ```ts * # Usage * Updater.names({"#P":"Percentile"}).condition("#P = 50"); * ``` */ names(obj?: { [key: string]: string; }): Updater; /** * Sets the ExpressionAttributeValues of the command input. * Use the : (colon) character in an expression to dereference an attribute value. * * @param obj - object of one or more values that can be substituted in an expression * @returns Updater with populated params * * @example Conditional update on status * ```ts * # Usage * Updater.values({ ":avail":{"S":"Available"}, ":back":{"S":"Backordered"}, ":disc":{"S":"Discontinued"} }).condition('ProductStatus IN (:avail, :back, :disc)'); * ``` */ values(obj?: { [key: string]: AttributeValue; }): Updater; /** * Sets the ConditionExpression of the command input. This condition must be satisfied in order for a condition update to succeed. * An expression can contain any of the following: * Functions: attribute_exists | attribute_not_exists | attribute_type | contains | begins_with | size (These function names ARE case-sensitive) * Comparison operators: = | \<\> | \< | \> | \<= | \>= | BETWEEN | IN * Logical operators: AND | OR | NOT * * @param str - string of the condition * @returns Updater with populated params * * @example Set the condition to update if an attribute does not exist * ```ts * # Usage * Udpater.condition('attribute_not_exists(newAttribute)'); * ``` */ condition(str: string, separator?: string): Updater; /** * Sets the ReturnValues parameter of the command input. * Use ReturnValues if you want to get the item attributes as they appear before or after they are updated. * For UpdateItem, the valid values are: * NONE - If ReturnValues is not specified, or if its value is NONE, then nothing is returned. (This setting is the default for ReturnValues.) * ALL_OLD - Returns all of the attributes of the item, as they appeared before the UpdateItem operation. * UPDATED_OLD - Returns only the updated attributes, as they appeared before the UpdateItem operation. * ALL_NEW - Returns all of the attributes of the item, as they appear after the UpdateItem operation. * UPDATED_NEW - Returns only the updated attributes, as they appear after the UpdateItem operation. * * @param str - NONE, ALL_OLD, UPDATED_OLD, ALL_NEW, or UPDATED_NEW (not case sensitive) * @returns Updater with populated params */ return(str: 'NONE' | 'ALL_OLD' | 'UPDATED_OLD' | 'ALL_NEW' | 'UPDATED_NEW'): Updater; /** * Sets the ReturnItemCollectionMetrics of the command input. Determines whether item collection metrics are returned. * If set to SIZE, the response includes statistics about item collections, if any, that were modified during the operation are returned in the response. * If set to NONE (the default), no statistics are returned. * * @param str - size or none (non case sensitive) * @returns Updater with populated params */ metrics(str: 'NONE' | 'SIZE'): Updater; /** * Sets the ReturnConsumedCapacity of the command input. Determines the level of detail about either provisioned or on-demand throughput consumption that is returned in the response: * INDEXES - The response includes the aggregate ConsumedCapacity for the operation, together with ConsumedCapacity for each table and secondary index that was accessed. * TOTAL - The response includes only the aggregate ConsumedCapacity for the operation. * NONE - No ConsumedCapacity details are included in the response. * * @param str - indexes, total, or none (non case sensitive strings) * @returns Updater with populated params */ capacity(str: 'INDEXES' | 'TOTAL' | 'NONE'): Updater; /** * Gets the internal _params value of the command input. For testing purposes. * * @returns The parameters for the UpdateItemCommandInput * * @example Returning command input * ```ts * # Result * { * Key: {}, * TableName: '', * ConditionExpression?: string, * ExpressionAttributeNames?: {}, * ExpressionAttributeValues?: {}, * ReturnConsumedCapacity?: 'INDEXES' | 'TOTAL' | 'NONE', * ReturnItemCollectionMetrics?: 'SIZE' | 'NONE', * ReturnValues?: 'NONE' |'ALL_OLD' |'UPDATED_OLD' |'ALL_NEW' | 'UPDATED_NEW', * UpdateExpression?: string, * } * ``` */ getParams(): UpdateItemCommandInput; /** * Sends the internal parameters as input to the DynamoDB table to execute the update item request. Call this after populating the command input params with the above methods. * Attributes will appear in the response only if ReturnValues does not equal NONE was set before the command. * Attributes are returned unmarshalled. * * @returns The output from the update item command * * @example * ```ts * # Result * { * Attributes?: {} * ConsumedCapacity?: [], * ItemCollectionMetrics?: {} * /} * ``` */ execute(): Promise; } export default Updater; //# sourceMappingURL=updater.d.ts.map