diff --git a/package.json b/package.json index eb9e6a0..ced2b1d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dynadash", - "version": "1.9.18", + "version": "1.9.19", "description": "DynamoDb helpers", "main": "dist/index.js", "types": "dist/types/index.d.ts", diff --git a/src/client.ts b/src/client.ts index e84b8a7..0536f71 100644 --- a/src/client.ts +++ b/src/client.ts @@ -4,11 +4,13 @@ export let ddbClientInstance: DynamoDBClient | null = null; export function initDdbClient( credentialDefaultProvider?: DynamoDBClientConfig["credentialDefaultProvider"], - maxAttempts = 5, + maxAttempts = 10, + retryMode: DynamoDBClientConfig["retryMode"] = "adaptive", ): DynamoDBClient { if (!ddbClientInstance) { const config: DynamoDBClientConfig = { maxAttempts, + retryMode, }; if (credentialDefaultProvider) { config.credentialDefaultProvider = credentialDefaultProvider; diff --git a/src/utils.ts b/src/utils.ts index 51460ae..b660ef9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -4,6 +4,7 @@ import { BatchWriteItemInput, Capacity, ConsumedCapacity, + DynamoDBServiceException, QueryCommandInput, QueryCommandOutput, WriteRequest, @@ -41,12 +42,13 @@ export function getExpressionFromMap(type: "FilterExpression" | "KeyConditionExp const ExpressionAttributeValues: { [key: string]: string | number } = {}; const ExpressionAttributeNames: { [key: string]: string } = {}; try { - for (const key in map) { + for (const k in map) { + const key = cleanAttributeName(k); if (map.hasOwnProperty(key)) { const v = map[key]; const attribute = `#${key}`; const anchor = `:${key}`; - ExpressionAttributeNames[cleanAttributeName(attribute)] = key; + ExpressionAttributeNames[attribute] = key; if (typeof v === "undefined") { throw Error("Value must not be undefined in an expression."); } @@ -310,7 +312,9 @@ export function getConditionExpression(row: T, condExps?: Conditio if (Array.isArray(condExps)) { for (const condExp of condExps) { - const { key, op, value, func, logicOp } = condExp; + const { op, value, func, logicOp } = condExp; + let { key } = condExp; + key = cleanAttributeName(key); let cond; if (op === "IN") { @@ -322,24 +326,24 @@ export function getConditionExpression(row: T, condExps?: Conditio }) .join(", "); cond = `(#${key} IN (${valStr}))`; - ExpressionAttributeNames[cleanAttributeName(`#${key}`)] = key; + ExpressionAttributeNames[`#${key}`] = key; } else if (op === "BETWEEN") { cond = `(#${key} between :${key}Xaa and :${key}Xbb)`; expressionAttributeValues[`:${key}Xaa`] = value[0]; expressionAttributeValues[`:${key}Xbb`] = value[1]; - ExpressionAttributeNames[cleanAttributeName(`#${key}`)] = key; + ExpressionAttributeNames[`#${key}`] = key; } else if (typeof op === "undefined" && func) { if (!op) { cond = `${func}(#${key})`; - ExpressionAttributeNames[cleanAttributeName(`#${key}`)] = key; + ExpressionAttributeNames[`#${key}`] = key; } else { cond = `${func}(#${key}) ${op} :${key}Xvv`; expressionAttributeValues[`:${key}Xvv`] = value; - ExpressionAttributeNames[cleanAttributeName(`#${key}`)] = key; + ExpressionAttributeNames[`#${key}`] = key; } } else { cond = `#${key} ${op} :${key}Xvv`; - ExpressionAttributeNames[cleanAttributeName(`#${key}`)] = key; + ExpressionAttributeNames[`#${key}`] = key; expressionAttributeValues[`:${key}Xvv`] = value; } @@ -356,12 +360,12 @@ export function getConditionExpression(row: T, condExps?: Conditio const val = row[key]; updateExpressions.push(`#${key} = :${key}`); expressionAttributeValues[`:${key}`] = val; - ExpressionAttributeNames[cleanAttributeName(`#${key}`)] = key; + ExpressionAttributeNames[`#${key}`] = key; } } } else { for (const key in row) { - if (ExpressionAttributeNames[cleanAttributeName(`#${key}`)]) { + if (ExpressionAttributeNames[`#${key}`]) { updateExpressions.push(`#${key} = :${key}`); } }