@xapp/dynamo-service
Advanced tools
Comparing version 0.0.34 to 0.0.35
@@ -26,2 +26,7 @@ import { DynamoDB } from "aws-sdk"; | ||
} | ||
export interface ConditionExpression { | ||
ConditionExpression?: DynamoDB.DocumentClient.ConditionExpression; | ||
ExpressionAttributeNames?: DynamoDB.DocumentClient.ExpressionAttributeNameMap; | ||
ExpressionAttributeValues?: DynamoDB.DocumentClient.ExpressionAttributeValueMap; | ||
} | ||
export declare type Set<T> = Partial<T>; | ||
@@ -41,6 +46,11 @@ export declare type Remove<T> = (keyof T)[]; | ||
update<T>(table: string, key: DynamoDB.DocumentClient.Key, update: UpdateBody<T>): Promise<void>; | ||
update<T>(table: string, key: DynamoDB.DocumentClient.Key, update: UpdateBody<T>, condition: ConditionExpression): Promise<void>; | ||
update<T>(table: string, key: DynamoDB.DocumentClient.Key, update: UpdateBody<T>, returns: "NONE"): Promise<void>; | ||
update<T>(table: string, key: DynamoDB.DocumentClient.Key, update: UpdateBody<T>, condition: ConditionExpression, returns: "NONE"): Promise<void>; | ||
update<T>(table: string, key: DynamoDB.DocumentClient.Key, update: UpdateBody<T>, returns: "UPDATED_OLD" | "UPDATED_NEW"): Promise<Partial<T>>; | ||
update<T>(table: string, key: DynamoDB.DocumentClient.Key, update: UpdateBody<T>, condition: ConditionExpression, returns: "UPDATED_OLD" | "UPDATED_NEW"): Promise<Partial<T>>; | ||
update<T>(table: string, key: DynamoDB.DocumentClient.Key, update: UpdateBody<T>, returns: "ALL_OLD" | "ALL_NEW"): Promise<T>; | ||
update<T>(table: string, key: DynamoDB.DocumentClient.Key, update: UpdateBody<T>, condition: ConditionExpression, returns: "UPDATED_OLD" | "UPDATED_NEW"): Promise<Partial<T>>; | ||
update<T>(table: string, key: DynamoDB.DocumentClient.Key, update: UpdateBody<T>, returns: string): Promise<void>; | ||
update<T>(table: string, key: DynamoDB.DocumentClient.Key, update: UpdateBody<T>, condition: ConditionExpression, returns: string): Promise<void>; | ||
get<T>(table: string, key: DynamoDB.DocumentClient.Key): Promise<T>; | ||
@@ -47,0 +57,0 @@ get<T>(table: string, key: DynamoDB.DocumentClient.Key[]): Promise<T[]>; |
@@ -16,5 +16,12 @@ "use strict"; | ||
} | ||
update(table, key, update, returns = "NONE") { | ||
update(table, key, update, conditionOrReturns = "NONE", returns = "NONE") { | ||
const updateExpression = getUpdateParameters(update); | ||
const params = Object.assign({ TableName: table, Key: key, ReturnValues: returns }, updateExpression); | ||
const conditionExpression = (typeof conditionOrReturns === "object") ? conditionOrReturns : {}; | ||
const ReturnValues = (typeof conditionOrReturns === "object") ? returns : conditionOrReturns; | ||
const params = Object.assign({ TableName: table, Key: key, ReturnValues }, updateExpression); | ||
if (Object_1.objHasAttrs(conditionExpression)) { | ||
params.ConditionExpression = conditionExpression.ConditionExpression; | ||
params.ExpressionAttributeNames = Object.assign({}, params.ExpressionAttributeNames, conditionExpression.ExpressionAttributeNames); | ||
params.ExpressionAttributeValues = Object.assign({}, params.ExpressionAttributeValues, conditionExpression.ExpressionAttributeValues); | ||
} | ||
return this.db.update(params).promise().then((item) => { return item.Attributes; }); | ||
@@ -113,4 +120,4 @@ } | ||
if (set.hasOwnProperty(key)) { | ||
const alias = "#" + key; | ||
const name = ":a" + ++index; | ||
const alias = "#__dynoservice_" + key; | ||
const name = ":__dynoservice_a" + ++index; | ||
setExpression += alias + " = " + name + ","; | ||
@@ -129,7 +136,7 @@ setValues[name] = set[key]; | ||
if (append.hasOwnProperty(key)) { | ||
const alias = "#append" + key; | ||
const name = ":c" + ++index; | ||
setExpression += alias + " = list_append(if_not_exists(" + alias + ", :append_empty_list)," + name + "),"; | ||
const alias = "#__dynoservice_append_" + key; | ||
const name = ":__dynoservice_c" + ++index; | ||
setExpression += alias + " = list_append(if_not_exists(" + alias + ", :__dynoservice_append_empty_list)," + name + "),"; | ||
setValues[name] = append[key]; | ||
setValues[":append_empty_list"] = []; | ||
setValues[":__dynoservice_append_empty_list"] = []; | ||
setAliasMap[alias] = key; | ||
@@ -144,3 +151,3 @@ } | ||
remove.forEach((key) => { | ||
const alias = "#" + key; | ||
const alias = "#__dynoservice_" + key; | ||
setExpression += alias + ","; | ||
@@ -170,3 +177,3 @@ setAliasMap[alias] = key; | ||
expression.forEach((value, index) => { | ||
const key = "#proj" + index; | ||
const key = "#__dynoservice_proj" + index; | ||
ExpressionAttributeNames[key] = value; | ||
@@ -173,0 +180,0 @@ ProjectionExpression += key; |
@@ -1,2 +0,2 @@ | ||
import { DynamoService, QueryParams, QueryResult, ScanParams, ScanResult, UpdateBody, UpdateReturnType } from "./DynamoService"; | ||
import { ConditionExpression, DynamoService, QueryParams, QueryResult, ScanParams, ScanResult, UpdateBody, UpdateReturnType } from "./DynamoService"; | ||
export { DynamoService, QueryParams, QueryResult, ScanParams, ScanResult, UpdateBody, UpdateReturnType }; | ||
@@ -28,6 +28,10 @@ export declare type DynamoType = "S" | "N" | "M" | "L"; | ||
update(key: Partial<T>, obj: UpdateBody<T>): Promise<void>; | ||
update(key: Partial<T>, obj: UpdateBody<T>, conditionExpression: ConditionExpression): Promise<void>; | ||
update(key: Partial<T>, obj: UpdateBody<T>, returnType: "NONE"): Promise<void>; | ||
update(key: Partial<T>, obj: UpdateBody<T>, conditionExpression: ConditionExpression, returnType: "NONE"): Promise<void>; | ||
update(key: Partial<T>, obj: UpdateBody<T>, returnType: "UPDATED_OLD" | "UPDATED_NEW"): Promise<Partial<T>>; | ||
update(key: Partial<T>, obj: UpdateBody<T>, conditionExpression: ConditionExpression, returnType: "UPDATED_OLD" | "UPDATED_NEW"): Promise<Partial<T>>; | ||
update(key: Partial<T>, obj: UpdateBody<T>, returnType: "ALL_OLD" | "ALL_NEW"): Promise<T>; | ||
update(key: Partial<T>, obj: UpdateBody<T>, returnType?: string): Promise<void>; | ||
update(key: Partial<T>, obj: UpdateBody<T>, conditionExpression: ConditionExpression, returnType: "ALL_OLD" | "ALL_NEW"): Promise<T>; | ||
update(key: Partial<T>, obj: UpdateBody<T>, returnType: string): Promise<void>; | ||
get(key: Partial<T>): Promise<T>; | ||
@@ -34,0 +38,0 @@ get(key: Partial<T>[]): Promise<T[]>; |
@@ -48,7 +48,7 @@ "use strict"; | ||
} | ||
update(key, obj, returnType) { | ||
update(key, obj, conditionExpression, returnType) { | ||
Object_1.throwIfDoesContain(obj.remove, this.constantKeys.concat(this.requiredKeys)); | ||
Object_1.throwIfDoesContain(obj.set, this.constantKeys); | ||
Object_1.throwIfDoesContain(obj.append, this.constantKeys); | ||
return this.db.update(this.tableName, key, obj, returnType); | ||
return this.db.update(this.tableName, key, obj, conditionExpression, returnType); | ||
} | ||
@@ -55,0 +55,0 @@ get(key, projection) { |
{ | ||
"name": "@xapp/dynamo-service", | ||
"version": "0.0.34", | ||
"version": "0.0.35", | ||
"description": "A dynamo help class which will help maintain data integrity.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
118527
20
3219