@twin.org/entity-storage-connector-dynamodb 0.0.1-next.6 → 0.0.1-next.7

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.
@@ -347,7 +347,6 @@ class DynamoDbEntityStorageConnector {
347
347
  * and a cursor which can be used to request more entities.
348
348
  */
349
349
  async query(conditions, sortProperties, properties, cursor, pageSize) {
350
- const sql = "";
351
350
  try {
352
351
  const returnSize = pageSize ?? DynamoDbEntityStorageConnector._PAGE_SIZE;
353
352
  let indexName;
@@ -417,9 +416,7 @@ class DynamoDbEntityStorageConnector {
417
416
  table: this._config.tableName
418
417
  }, err);
419
418
  }
420
- throw new core.GeneralError(this.CLASS_NAME, "queryFailed", {
421
- sql
422
- }, err);
419
+ throw new core.GeneralError(this.CLASS_NAME, "queryFailed", undefined, err);
423
420
  }
424
421
  }
425
422
  /**
@@ -434,7 +431,7 @@ class DynamoDbEntityStorageConnector {
434
431
  catch { }
435
432
  }
436
433
  /**
437
- * Create an SQL condition clause.
434
+ * Create the parameters for a query.
438
435
  * @param objectPath The path for the nested object.
439
436
  * @param condition The conditions to create the query from.
440
437
  * @param attributeNames The attribute names to use in the query.
@@ -451,11 +448,21 @@ class DynamoDbEntityStorageConnector {
451
448
  };
452
449
  }
453
450
  if ("conditions" in condition) {
451
+ if (condition.conditions.length === 0) {
452
+ return {
453
+ keyCondition: "",
454
+ filterCondition: ""
455
+ };
456
+ }
454
457
  // It's a group of comparisons, so check the individual items and combine with the logical operator
455
458
  const joinConditions = condition.conditions.map(c => this.buildQueryParameters(objectPath, c, attributeNames, attributeValues));
456
459
  const logicalOperator = this.mapConditionalOperator(condition.logicalOperator);
457
- const keyCondition = joinConditions.map(j => j.keyCondition).join(` ${logicalOperator} `);
460
+ const keyCondition = joinConditions
461
+ .filter(j => j.keyCondition.length > 0)
462
+ .map(j => j.keyCondition)
463
+ .join(` ${logicalOperator} `);
458
464
  const filterCondition = joinConditions
465
+ .filter(j => j.filterCondition.length > 0)
459
466
  .map(j => j.filterCondition)
460
467
  .join(` ${logicalOperator} `);
461
468
  return {
@@ -345,7 +345,6 @@ class DynamoDbEntityStorageConnector {
345
345
  * and a cursor which can be used to request more entities.
346
346
  */
347
347
  async query(conditions, sortProperties, properties, cursor, pageSize) {
348
- const sql = "";
349
348
  try {
350
349
  const returnSize = pageSize ?? DynamoDbEntityStorageConnector._PAGE_SIZE;
351
350
  let indexName;
@@ -415,9 +414,7 @@ class DynamoDbEntityStorageConnector {
415
414
  table: this._config.tableName
416
415
  }, err);
417
416
  }
418
- throw new GeneralError(this.CLASS_NAME, "queryFailed", {
419
- sql
420
- }, err);
417
+ throw new GeneralError(this.CLASS_NAME, "queryFailed", undefined, err);
421
418
  }
422
419
  }
423
420
  /**
@@ -432,7 +429,7 @@ class DynamoDbEntityStorageConnector {
432
429
  catch { }
433
430
  }
434
431
  /**
435
- * Create an SQL condition clause.
432
+ * Create the parameters for a query.
436
433
  * @param objectPath The path for the nested object.
437
434
  * @param condition The conditions to create the query from.
438
435
  * @param attributeNames The attribute names to use in the query.
@@ -449,11 +446,21 @@ class DynamoDbEntityStorageConnector {
449
446
  };
450
447
  }
451
448
  if ("conditions" in condition) {
449
+ if (condition.conditions.length === 0) {
450
+ return {
451
+ keyCondition: "",
452
+ filterCondition: ""
453
+ };
454
+ }
452
455
  // It's a group of comparisons, so check the individual items and combine with the logical operator
453
456
  const joinConditions = condition.conditions.map(c => this.buildQueryParameters(objectPath, c, attributeNames, attributeValues));
454
457
  const logicalOperator = this.mapConditionalOperator(condition.logicalOperator);
455
- const keyCondition = joinConditions.map(j => j.keyCondition).join(` ${logicalOperator} `);
458
+ const keyCondition = joinConditions
459
+ .filter(j => j.keyCondition.length > 0)
460
+ .map(j => j.keyCondition)
461
+ .join(` ${logicalOperator} `);
456
462
  const filterCondition = joinConditions
463
+ .filter(j => j.filterCondition.length > 0)
457
464
  .map(j => j.filterCondition)
458
465
  .join(` ${logicalOperator} `);
459
466
  return {
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.6
3
+ ## v0.0.1-next.7
4
4
 
5
5
  - Initial Release
package/locales/en.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "setFailed": "Unable to set entity \"{id}\"",
14
14
  "getFailed": "Unable to get entity \"{id}\"",
15
15
  "removeFailed": "Unable to remove entity \"{id}\"",
16
- "queryFailed": "The query failed when issuing the following command \"{sql}\"",
16
+ "queryFailed": "The query failed",
17
17
  "comparisonNotSupported": "Comparison operator \"{comparison}\" is not supported",
18
18
  "conditionalNotSupported": "Conditional operator \"{operator}\" is not supported",
19
19
  "sortSingle": "You can only sort by a single property",
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.6",
3
+ "version": "0.0.1-next.7",
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.6",
22
+ "@twin.org/entity-storage-models": "0.0.1-next.7",
23
23
  "@twin.org/logging-models": "next",
24
24
  "@twin.org/nameof": "next"
25
25
  },