@twin.org/entity-storage-connector-dynamodb 0.0.1-next.10 → 0.0.1-next.12

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.
@@ -295,13 +295,20 @@ class DynamoDbEntityStorageConnector {
295
295
  [DynamoDbEntityStorageConnector._PARTITION_ID_NAME]: DynamoDbEntityStorageConnector._PARTITION_ID_VALUE,
296
296
  ...entity
297
297
  },
298
- ConditionExpression: conditionExpression,
298
+ // Only set the condition expression if we have conditions to match
299
+ // and the primary key exists, otherwise we are creating a new object
300
+ ConditionExpression: core.Is.stringValue(conditionExpression)
301
+ ? `(attribute_exists(${this._primaryKey.property}) AND ${conditionExpression}) OR attribute_not_exists(${this._primaryKey.property})`
302
+ : undefined,
299
303
  ExpressionAttributeNames: attributeNames,
300
304
  ExpressionAttributeValues: attributeValues
301
305
  });
302
306
  await docClient.send(putCommand);
303
307
  }
304
308
  catch (err) {
309
+ if (core.BaseError.isErrorName(err, "ConditionalCheckFailedException")) {
310
+ return;
311
+ }
305
312
  if (core.BaseError.isErrorCode(err, "ResourceNotFoundException")) {
306
313
  throw new core.GeneralError(this.CLASS_NAME, "tableDoesNotExist", {
307
314
  tableName: this._config.tableName
@@ -293,13 +293,20 @@ class DynamoDbEntityStorageConnector {
293
293
  [DynamoDbEntityStorageConnector._PARTITION_ID_NAME]: DynamoDbEntityStorageConnector._PARTITION_ID_VALUE,
294
294
  ...entity
295
295
  },
296
- ConditionExpression: conditionExpression,
296
+ // Only set the condition expression if we have conditions to match
297
+ // and the primary key exists, otherwise we are creating a new object
298
+ ConditionExpression: Is.stringValue(conditionExpression)
299
+ ? `(attribute_exists(${this._primaryKey.property}) AND ${conditionExpression}) OR attribute_not_exists(${this._primaryKey.property})`
300
+ : undefined,
297
301
  ExpressionAttributeNames: attributeNames,
298
302
  ExpressionAttributeValues: attributeValues
299
303
  });
300
304
  await docClient.send(putCommand);
301
305
  }
302
306
  catch (err) {
307
+ if (BaseError.isErrorName(err, "ConditionalCheckFailedException")) {
308
+ return;
309
+ }
303
310
  if (BaseError.isErrorCode(err, "ResourceNotFoundException")) {
304
311
  throw new GeneralError(this.CLASS_NAME, "tableDoesNotExist", {
305
312
  tableName: this._config.tableName
package/docs/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @twin.org/entity-storage-connector-dynamodb - Changelog
2
2
 
3
- ## v0.0.1-next.10
3
+ ## v0.0.1-next.12
4
4
 
5
5
  - Initial Release
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/entity-storage-connector-dynamodb",
3
- "version": "0.0.1-next.10",
3
+ "version": "0.0.1-next.12",
4
4
  "description": "Entity Storage connector implementation using DynamoDb storage",
5
5
  "repository": {
6
6
  "type": "git",
@@ -19,7 +19,7 @@
19
19
  "@aws-sdk/util-dynamodb": "3.656",
20
20
  "@twin.org/core": "next",
21
21
  "@twin.org/entity": "next",
22
- "@twin.org/entity-storage-models": "0.0.1-next.10",
22
+ "@twin.org/entity-storage-models": "0.0.1-next.12",
23
23
  "@twin.org/logging-models": "next",
24
24
  "@twin.org/nameof": "next"
25
25
  },