@izara_project/izara-core-library-dynamodb 1.0.6 → 1.0.8
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.
package/index.js
CHANGED
|
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
18
18
|
'use strict';
|
|
19
19
|
|
|
20
20
|
// Import the Dynamodb shared library functions
|
|
21
|
-
const dynamodbSharedLib = require('./src/
|
|
21
|
+
const dynamodbSharedLib = require('./src/DynamoDBSharedLib');
|
|
22
22
|
|
|
23
23
|
// Export all the functions
|
|
24
24
|
module.exports = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@izara_project/izara-core-library-dynamodb",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Connecting with AWS DynamoDB Resource",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,18 +14,16 @@
|
|
|
14
14
|
"license": "AGPL-3.0-or-later",
|
|
15
15
|
"homepage": "https://bitbucket.org/izara-core-libraries/izara-core-library-dynamodb/src/master/README.md",
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"jest": "^
|
|
17
|
+
"jest": "^30.0.5"
|
|
18
18
|
},
|
|
19
19
|
"jest": {
|
|
20
20
|
"testEnvironment": "node"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@aws-sdk/client-dynamodb": "^3.
|
|
24
|
-
"@aws-sdk/lib-dynamodb": "^3.
|
|
25
|
-
"@aws-sdk/util-dynamodb": "^3.
|
|
26
|
-
"@izara_project/izara-core-library-core": "^1.0.
|
|
27
|
-
"@izara_project/izara-core-library-logger": "^1.0.7",
|
|
28
|
-
"@izara_project/izara-core-library-service-schemas": "^1.0.49",
|
|
23
|
+
"@aws-sdk/client-dynamodb": "^3.864.0",
|
|
24
|
+
"@aws-sdk/lib-dynamodb": "^3.864.0",
|
|
25
|
+
"@aws-sdk/util-dynamodb": "^3.864.0",
|
|
26
|
+
"@izara_project/izara-core-library-core": "^1.0.20",
|
|
29
27
|
"lodash.clonedeep": "^4.5.0"
|
|
30
28
|
}
|
|
31
29
|
}
|
|
@@ -20,10 +20,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
20
20
|
const { DynamoDBDocument } = require('@aws-sdk/lib-dynamodb');
|
|
21
21
|
const { DynamoDB } = require('@aws-sdk/client-dynamodb');
|
|
22
22
|
const { marshall, unmarshall } = require('@aws-sdk/util-dynamodb');
|
|
23
|
+
|
|
23
24
|
const cloneDeep = require('lodash.clonedeep');
|
|
24
25
|
|
|
25
26
|
// External Izara project imports
|
|
26
|
-
const Logger = require('@izara_project/izara-core-library-logger');
|
|
27
27
|
const NoRetryError = require('@izara_project/izara-core-library-core').NoRetryError;
|
|
28
28
|
// const { getServiceNameWithCache } = require('@izara_project/izara-core-library-service-schemas').serviceConfig;
|
|
29
29
|
|
|
@@ -58,16 +58,6 @@ module.exports.tableName = async (_izContext, tableName, serviceTag = null) => {
|
|
|
58
58
|
return serviceTag + process.env.iz_stage + tableName;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
// /**
|
|
62
|
-
// * create table name for external service
|
|
63
|
-
// * @param {string} tableName - suffix tablename
|
|
64
|
-
// *
|
|
65
|
-
// * @returns {string} full tablename
|
|
66
|
-
// */
|
|
67
|
-
// module.exports.tableNameExternal = (serviceName, tableName) => {
|
|
68
|
-
// return serviceName + process.env.iz_stage + tableName;
|
|
69
|
-
// }
|
|
70
|
-
|
|
71
61
|
|
|
72
62
|
/**
|
|
73
63
|
* Creates a string set element for use with documentClient
|
|
@@ -86,7 +76,7 @@ module.exports.arrayToStringSet = (stringSetArray) => {
|
|
|
86
76
|
return stringSet
|
|
87
77
|
|
|
88
78
|
} catch (e) {
|
|
89
|
-
|
|
79
|
+
console.error('error arrayToStringSet:', e)
|
|
90
80
|
throw (e)
|
|
91
81
|
}
|
|
92
82
|
};
|
|
@@ -457,15 +447,17 @@ module.exports.query = async (_izContext, tableName, partitionKeyValue, queryEle
|
|
|
457
447
|
throw new NoRetryError('partitionKeyValue should be "object" type.')
|
|
458
448
|
}
|
|
459
449
|
|
|
450
|
+
let attributeReservedNames = ['partitionKeyValue', 'betweenStartValue', 'betweenEndValue'];
|
|
451
|
+
|
|
460
452
|
// ------------ set payload ---------------
|
|
461
453
|
let payload = {
|
|
462
454
|
TableName: tableName, // require
|
|
463
455
|
// KeyConditionExpression: '',
|
|
464
|
-
KeyConditionExpression: `${Object.keys(partitionKeyValue)[0]} =
|
|
456
|
+
KeyConditionExpression: `${Object.keys(partitionKeyValue)[0]} = :partitionKeyValue`, // require partition key
|
|
465
457
|
ExpressionAttributeValues: {}, // require value of partition key
|
|
466
458
|
ReturnConsumedCapacity: "TOTAL" // NONE(default) | TOTAL | INDEXES
|
|
467
459
|
}
|
|
468
|
-
payload.ExpressionAttributeValues[
|
|
460
|
+
payload.ExpressionAttributeValues[`:partitionKeyValue`] = partitionKeyValue[Object.keys(partitionKeyValue)[0]]
|
|
469
461
|
|
|
470
462
|
// ---- sortKeyCondition ----
|
|
471
463
|
/* NOTE: KeyConditionExpression
|
|
@@ -494,20 +486,26 @@ module.exports.query = async (_izContext, tableName, partitionKeyValue, queryEle
|
|
|
494
486
|
payload.KeyConditionExpression += ' AND '
|
|
495
487
|
|
|
496
488
|
if (queryElements.sortKeyCondition.comparison == 'between') {
|
|
497
|
-
//
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
489
|
+
// can compare both numeric and stringfs in Dynamo, but the typoe sent must match the type store in Dynamo
|
|
490
|
+
// in future maybe check type from objectSchema to make sure they match
|
|
491
|
+
// if (!queryElements.sortKeyCondition.hasOwnProperty('betweenStartValue') || !queryElements.sortKeyCondition.hasOwnProperty('betweenEndValue')
|
|
492
|
+
// || typeof queryElements.sortKeyCondition.betweenStartValue !== 'number' || typeof queryElements.sortKeyCondition.betweenEndValue !== 'number'
|
|
493
|
+
// ) {
|
|
494
|
+
// throw new NoRetryError('sortKeyCondition should set both side-hand betweenStartValue/end and value should be number')
|
|
495
|
+
// }
|
|
503
496
|
// sortKeyName BETWEEN :sortkeyval1 AND :sortkeyval2
|
|
504
|
-
payload.KeyConditionExpression += `${queryElements.sortKeyCondition.name} BETWEEN
|
|
505
|
-
payload.ExpressionAttributeValues[
|
|
506
|
-
payload.ExpressionAttributeValues[
|
|
497
|
+
payload.KeyConditionExpression += `${queryElements.sortKeyCondition.name} BETWEEN :betweenStartValue AND :betweenEndValue`
|
|
498
|
+
payload.ExpressionAttributeValues[`:betweenStartValue`] = queryElements.sortKeyCondition.betweenStartValue
|
|
499
|
+
payload.ExpressionAttributeValues[`:betweenEndValue`] = queryElements.sortKeyCondition.betweenEndValue
|
|
507
500
|
|
|
508
501
|
|
|
509
502
|
} else { // others comparisons eg. < > <> = , has one side-hand
|
|
510
503
|
|
|
504
|
+
// check does not use attributeReservedNames
|
|
505
|
+
if (attributeReservedNames.includes(queryElements.sortKeyCondition.name)) {
|
|
506
|
+
throw new NoRetryError(`sortKeyCondition.name cannot be a attributeReservedName (${queryElements.sortKeyCondition.name})`);
|
|
507
|
+
};
|
|
508
|
+
|
|
511
509
|
let subKeyConditionalExpression = null
|
|
512
510
|
if (queryElements.sortKeyCondition.comparison == 'begins_with') { // begins_with ( sortKeyName, :sortkeyval ) ***CANNOT USE WITH NUMBER TYPE
|
|
513
511
|
if (typeof queryElements.sortKeyCondition.value !== 'string') {
|