@jupiterone/dynamodb-dao
Advanced tools
Comparing version 1.4.0 to 1.5.2
@@ -83,5 +83,17 @@ import { DocumentClient } from 'aws-sdk/clients/dynamodb'; | ||
} | ||
export declare type PutOptions = ConditionalOptions; | ||
export declare type UpdateOptions = ConditionalOptions; | ||
export declare type DeleteOptions = ConditionalOptions; | ||
export interface SaveBehavior { | ||
optimisticLockVersionAttribute?: string; | ||
optimisticLockVersionIncrement?: number; | ||
} | ||
export interface MutateBehavior { | ||
ignoreOptimisticLocking?: boolean; | ||
} | ||
export declare type PutOptions = ConditionalOptions & MutateBehavior; | ||
export declare type UpdateOptions = ConditionalOptions & MutateBehavior; | ||
export declare type DeleteOptions = ConditionalOptions & MutateBehavior; | ||
export interface BuildOptimisticLockOptionsInput extends ConditionalOptions { | ||
versionAttribute: string; | ||
versionAttributeValue: any; | ||
} | ||
export declare function buildOptimisticLockOptions(options: BuildOptimisticLockOptionsInput): ConditionalOptions; | ||
export interface GenerateUpdateParamsInput extends UpdateOptions { | ||
@@ -92,6 +104,7 @@ tableName: string; | ||
} | ||
export declare function generateUpdateParams(options: GenerateUpdateParamsInput): DocumentClient.UpdateItemInput; | ||
interface DynamoDbDaoInput { | ||
export declare function generateUpdateParams(options: GenerateUpdateParamsInput & SaveBehavior): DocumentClient.UpdateItemInput; | ||
export interface DynamoDbDaoInput<T> { | ||
tableName: string; | ||
documentClient: DocumentClient; | ||
optimisticLockingAttribute?: keyof NumberPropertiesInType<T>; | ||
} | ||
@@ -118,3 +131,4 @@ export declare function encodeQueryUntilLimitCursor(lastKey: string | undefined, skip: number | undefined): string; | ||
readonly documentClient: DocumentClient; | ||
constructor(options: DynamoDbDaoInput); | ||
readonly optimisticLockingAttribute?: keyof NumberPropertiesInType<DataModel>; | ||
constructor(options: DynamoDbDaoInput<DataModel>); | ||
/** | ||
@@ -128,3 +142,3 @@ * Fetches an item by it's key schema | ||
*/ | ||
delete(key: KeySchema, options?: DeleteOptions): Promise<DataModel | undefined>; | ||
delete(key: KeySchema, options?: DeleteOptions, data?: Partial<DataModel>): Promise<DataModel | undefined>; | ||
/** | ||
@@ -131,0 +145,0 @@ * Creates/Updates an item in the table |
{ | ||
"name": "@jupiterone/dynamodb-dao", | ||
"version": "1.4.0", | ||
"version": "1.5.2", | ||
"description": "DynamoDB Data Access Object (DAO) helper library", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -140,2 +140,39 @@ # dynamodb-dao | ||
**Optimistic Locking with Version Numbers** | ||
For callers who wish to enable an optimistic locking strategy there are two | ||
available toggles: | ||
1. Provide the attribute you wish to be used to store the version number. This | ||
will enable optimistic locking on the following operations: `put`, `update`, | ||
and `delete`. | ||
Writes for documents that do not have a version number attribute will | ||
initialize the version number to 1. All subsequent writes will need to | ||
provide the current version number. If an out-of-date version number is | ||
supplied, an error will be thrown. | ||
Example of Dao constructed with optimistic locking enabled. | ||
``` | ||
const dao = new DynamoDbDao<DataModel, KeySchema>({ | ||
tableName, | ||
documentClient, | ||
optimisticLockingAttribute: 'version', | ||
}); | ||
``` | ||
2. If you wish to ignore optimistic locking for a save operation, specify | ||
`ignoreOptimisticLocking: true` in the options on your `put`, `update`, or | ||
`delete`. | ||
NOTE: Optimistic locking is NOT supported for `batchWrite` or `batchPut` | ||
operations. Consuming those APIs for data models that do have optimistic locking | ||
enabled may clobber your version data and could produce undesirable effects for | ||
other callers. | ||
This was modeled after the | ||
[Java Dynamo client](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBMapper.OptimisticLocking.html) | ||
implementation. | ||
## Developing | ||
@@ -142,0 +179,0 @@ |
Sorry, the diff of this file is too big to display
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
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
89064
726
198