chatbot-nc 2.0.83 → 2.0.84
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/dist/cjs/aws/index.d.ts +179 -0
- package/dist/cjs/aws/index.js +52 -0
- package/dist/cjs/aws/index.js.map +1 -0
- package/dist/cjs/aws/services/AESEncryptionUsingKMS.d.ts +4 -0
- package/dist/cjs/aws/services/AESEncryptionUsingKMS.js +101 -0
- package/dist/cjs/aws/services/AESEncryptionUsingKMS.js.map +1 -0
- package/dist/cjs/aws/services/AWSChimeMeeting.d.ts +8 -0
- package/dist/cjs/aws/services/AWSChimeMeeting.js +99 -0
- package/dist/cjs/aws/services/AWSChimeMeeting.js.map +1 -0
- package/dist/cjs/aws/services/AWSCodepipeline.d.ts +16 -0
- package/dist/cjs/aws/services/AWSCodepipeline.js +43 -0
- package/dist/cjs/aws/services/AWSCodepipeline.js.map +1 -0
- package/dist/cjs/aws/services/AWSComprehend.d.ts +3 -0
- package/dist/cjs/aws/services/AWSComprehend.js +30 -0
- package/dist/cjs/aws/services/AWSComprehend.js.map +1 -0
- package/dist/cjs/aws/services/AWSConnect.d.ts +296 -0
- package/dist/cjs/aws/services/AWSConnect.js +865 -0
- package/dist/cjs/aws/services/AWSConnect.js.map +1 -0
- package/dist/cjs/aws/services/AWSConnectCases.d.ts +7 -0
- package/dist/cjs/aws/services/AWSConnectCases.js +81 -0
- package/dist/cjs/aws/services/AWSConnectCases.js.map +1 -0
- package/dist/cjs/aws/services/AWSConnectParticipant.d.ts +7 -0
- package/dist/cjs/aws/services/AWSConnectParticipant.js +87 -0
- package/dist/cjs/aws/services/AWSConnectParticipant.js.map +1 -0
- package/dist/cjs/aws/services/AWSCustomerProfiles.d.ts +5 -0
- package/dist/cjs/aws/services/AWSCustomerProfiles.js +45 -0
- package/dist/cjs/aws/services/AWSCustomerProfiles.js.map +1 -0
- package/dist/cjs/aws/services/AWSDynamoDb.d.ts +6 -0
- package/dist/cjs/aws/services/AWSDynamoDb.js +77 -0
- package/dist/cjs/aws/services/AWSDynamoDb.js.map +1 -0
- package/dist/cjs/aws/services/AWSGateway.d.ts +5 -0
- package/dist/cjs/aws/services/AWSGateway.js +45 -0
- package/dist/cjs/aws/services/AWSGateway.js.map +1 -0
- package/dist/cjs/aws/services/AWSGatewayManagement.d.ts +5 -0
- package/dist/cjs/aws/services/AWSGatewayManagement.js +49 -0
- package/dist/cjs/aws/services/AWSGatewayManagement.js.map +1 -0
- package/dist/cjs/aws/services/AWSLambda.d.ts +3 -0
- package/dist/cjs/aws/services/AWSLambda.js +25 -0
- package/dist/cjs/aws/services/AWSLambda.js.map +1 -0
- package/dist/cjs/aws/services/AWSLexModel.d.ts +24 -0
- package/dist/cjs/aws/services/AWSLexModel.js +387 -0
- package/dist/cjs/aws/services/AWSLexModel.js.map +1 -0
- package/dist/cjs/aws/services/AWSLexRuntime.d.ts +5 -0
- package/dist/cjs/aws/services/AWSLexRuntime.js +47 -0
- package/dist/cjs/aws/services/AWSLexRuntime.js.map +1 -0
- package/dist/cjs/aws/services/AWSPinpoint.d.ts +6 -0
- package/dist/cjs/aws/services/AWSPinpoint.js +65 -0
- package/dist/cjs/aws/services/AWSPinpoint.js.map +1 -0
- package/dist/cjs/aws/services/AWSPinpointSMSVoice.d.ts +9 -0
- package/dist/cjs/aws/services/AWSPinpointSMSVoice.js +111 -0
- package/dist/cjs/aws/services/AWSPinpointSMSVoice.js.map +1 -0
- package/dist/cjs/aws/services/AWSQConnect.d.ts +9 -0
- package/dist/cjs/aws/services/AWSQConnect.js +118 -0
- package/dist/cjs/aws/services/AWSQConnect.js.map +1 -0
- package/dist/cjs/aws/services/AWSS3.d.ts +11 -0
- package/dist/cjs/aws/services/AWSS3.js +186 -0
- package/dist/cjs/aws/services/AWSS3.js.map +1 -0
- package/dist/cjs/aws/services/AWSSES.d.ts +4 -0
- package/dist/cjs/aws/services/AWSSES.js +23 -0
- package/dist/cjs/aws/services/AWSSES.js.map +1 -0
- package/dist/cjs/aws/services/AWSSNS.d.ts +12 -0
- package/dist/cjs/aws/services/AWSSNS.js +73 -0
- package/dist/cjs/aws/services/AWSSNS.js.map +1 -0
- package/dist/cjs/aws/services/AWSSSM.d.ts +4 -0
- package/dist/cjs/aws/services/AWSSSM.js +82 -0
- package/dist/cjs/aws/services/AWSSSM.js.map +1 -0
- package/dist/cjs/aws/services/AWSSTS.d.ts +4 -0
- package/dist/cjs/aws/services/AWSSTS.js +28 -0
- package/dist/cjs/aws/services/AWSSTS.js.map +1 -0
- package/dist/cjs/aws/services/AWSTranslate.d.ts +4 -0
- package/dist/cjs/aws/services/AWSTranslate.js +27 -0
- package/dist/cjs/aws/services/AWSTranslate.js.map +1 -0
- package/dist/cjs/communication/communicationService.d.ts +20 -0
- package/dist/cjs/communication/communicationService.js +283 -0
- package/dist/cjs/communication/communicationService.js.map +1 -0
- package/dist/cjs/communication/index.d.ts +49 -0
- package/dist/cjs/communication/index.js +219 -0
- package/dist/cjs/communication/index.js.map +1 -0
- package/dist/cjs/config/SSMParameters.d.ts +26 -0
- package/dist/cjs/config/SSMParameters.js +34 -0
- package/dist/cjs/config/SSMParameters.js.map +1 -0
- package/dist/cjs/enum/index.d.ts +236 -0
- package/dist/cjs/enum/index.js +289 -0
- package/dist/cjs/enum/index.js.map +1 -0
- package/dist/cjs/hashing/idObfuscation.d.ts +20 -0
- package/dist/cjs/hashing/idObfuscation.js +56 -0
- package/dist/cjs/hashing/idObfuscation.js.map +1 -0
- package/dist/cjs/hashing/index.d.ts +33 -0
- package/dist/cjs/hashing/index.js +192 -0
- package/dist/cjs/hashing/index.js.map +1 -0
- package/dist/cjs/index.d.ts +12 -0
- package/dist/cjs/index.js +52 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/logger/index.d.ts +3 -0
- package/dist/cjs/logger/index.js +70 -0
- package/dist/cjs/logger/index.js.map +1 -0
- package/dist/cjs/logger/loggerTransports.d.ts +11 -0
- package/dist/cjs/logger/loggerTransports.js +72 -0
- package/dist/cjs/logger/loggerTransports.js.map +1 -0
- package/dist/cjs/repository/dynamodb.d.ts +121 -0
- package/dist/cjs/repository/dynamodb.js +696 -0
- package/dist/cjs/repository/dynamodb.js.map +1 -0
- package/dist/cjs/shortner/index.d.ts +4 -0
- package/dist/cjs/shortner/index.js +34 -0
- package/dist/cjs/shortner/index.js.map +1 -0
- package/dist/cjs/utils/common.d.ts +7 -0
- package/dist/cjs/utils/common.js +199 -0
- package/dist/cjs/utils/common.js.map +1 -0
- package/dist/cjs/utils/date-format.d.ts +16 -0
- package/dist/cjs/utils/date-format.js +282 -0
- package/dist/cjs/utils/date-format.js.map +1 -0
- package/dist/cjs/utils/index.d.ts +37 -0
- package/dist/cjs/utils/index.js +12 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/intent.d.ts +12 -0
- package/dist/cjs/utils/intent.js +205 -0
- package/dist/cjs/utils/intent.js.map +1 -0
- package/dist/cjs/webbookEvent/index.d.ts +22 -0
- package/dist/cjs/webbookEvent/index.js +151 -0
- package/dist/cjs/webbookEvent/index.js.map +1 -0
- package/dist/esm/aws/index.d.ts +1 -0
- package/dist/esm/aws/services/AESEncryptionUsingKMS.js +20 -11
- package/dist/esm/aws/services/AESEncryptionUsingKMS.js.map +1 -1
- package/dist/esm/aws/services/AWSChimeMeeting.js +24 -15
- package/dist/esm/aws/services/AWSChimeMeeting.js.map +1 -1
- package/dist/esm/aws/services/AWSCodepipeline.js +34 -21
- package/dist/esm/aws/services/AWSCodepipeline.js.map +1 -1
- package/dist/esm/aws/services/AWSComprehend.js +12 -3
- package/dist/esm/aws/services/AWSComprehend.js.map +1 -1
- package/dist/esm/aws/services/AWSConnect.js +144 -135
- package/dist/esm/aws/services/AWSConnect.js.map +1 -1
- package/dist/esm/aws/services/AWSConnectCases.js +21 -12
- package/dist/esm/aws/services/AWSConnectCases.js.map +1 -1
- package/dist/esm/aws/services/AWSConnectParticipant.js +21 -12
- package/dist/esm/aws/services/AWSConnectParticipant.js.map +1 -1
- package/dist/esm/aws/services/AWSCustomerProfiles.js +15 -6
- package/dist/esm/aws/services/AWSCustomerProfiles.js.map +1 -1
- package/dist/esm/aws/services/AWSDynamoDb.js +18 -9
- package/dist/esm/aws/services/AWSDynamoDb.js.map +1 -1
- package/dist/esm/aws/services/AWSGateway.js +15 -6
- package/dist/esm/aws/services/AWSGateway.js.map +1 -1
- package/dist/esm/aws/services/AWSGatewayManagement.js +15 -6
- package/dist/esm/aws/services/AWSGatewayManagement.js.map +1 -1
- package/dist/esm/aws/services/AWSLambda.js +13 -4
- package/dist/esm/aws/services/AWSLambda.js.map +1 -1
- package/dist/esm/aws/services/AWSLexModel.js +72 -63
- package/dist/esm/aws/services/AWSLexModel.js.map +1 -1
- package/dist/esm/aws/services/AWSLexRuntime.js +15 -6
- package/dist/esm/aws/services/AWSLexRuntime.js.map +1 -1
- package/dist/esm/aws/services/AWSPinpoint.js +18 -9
- package/dist/esm/aws/services/AWSPinpoint.js.map +1 -1
- package/dist/esm/aws/services/AWSPinpointSMSVoice.js +27 -18
- package/dist/esm/aws/services/AWSPinpointSMSVoice.js.map +1 -1
- package/dist/esm/aws/services/AWSQConnect.js +27 -18
- package/dist/esm/aws/services/AWSQConnect.js.map +1 -1
- package/dist/esm/aws/services/AWSS3.js +37 -28
- package/dist/esm/aws/services/AWSS3.js.map +1 -1
- package/dist/esm/aws/services/AWSSES.js +13 -4
- package/dist/esm/aws/services/AWSSES.js.map +1 -1
- package/dist/esm/aws/services/AWSSNS.js +20 -11
- package/dist/esm/aws/services/AWSSNS.js.map +1 -1
- package/dist/esm/aws/services/AWSSSM.d.ts +1 -0
- package/dist/esm/aws/services/AWSSSM.js +50 -3
- package/dist/esm/aws/services/AWSSSM.js.map +1 -1
- package/dist/esm/aws/services/AWSSTS.js +12 -3
- package/dist/esm/aws/services/AWSSTS.js.map +1 -1
- package/dist/esm/aws/services/AWSTranslate.js +12 -3
- package/dist/esm/aws/services/AWSTranslate.js.map +1 -1
- package/dist/esm/communication/communicationService.js +38 -29
- package/dist/esm/communication/communicationService.js.map +1 -1
- package/dist/esm/communication/index.js +148 -125
- package/dist/esm/communication/index.js.map +1 -1
- package/dist/esm/hashing/idObfuscation.js +43 -28
- package/dist/esm/hashing/idObfuscation.js.map +1 -1
- package/dist/esm/hashing/index.js +168 -141
- package/dist/esm/hashing/index.js.map +1 -1
- package/dist/esm/repository/dynamodb.js +398 -369
- package/dist/esm/repository/dynamodb.js.map +1 -1
- package/dist/esm/shortner/index.js +31 -20
- package/dist/esm/shortner/index.js.map +1 -1
- package/dist/esm/utils/common.js +11 -2
- package/dist/esm/utils/common.js.map +1 -1
- package/dist/esm/utils/intent.js +33 -24
- package/dist/esm/utils/intent.js.map +1 -1
- package/dist/esm/webbookEvent/index.js +128 -105
- package/dist/esm/webbookEvent/index.js.map +1 -1
- package/package.json +5 -4
|
@@ -0,0 +1,696 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const client_dynamodb_1 = require("@aws-sdk/client-dynamodb"); // ES Modules import
|
|
4
|
+
const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
|
|
5
|
+
const awsRegion = process.env.AWS_DEFAULT_REGION || 'us-east-1';
|
|
6
|
+
/**
|
|
7
|
+
* Base Repository of Dynamodb
|
|
8
|
+
* @param {object} item // Object containing add for target item
|
|
9
|
+
*/
|
|
10
|
+
class BaseDynamoDBRepository {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.TABLE_NAME = '';
|
|
13
|
+
this.PRIMARY_KEY = [];
|
|
14
|
+
let client = new client_dynamodb_1.DynamoDBClient({
|
|
15
|
+
region: awsRegion,
|
|
16
|
+
});
|
|
17
|
+
this.documentClient = lib_dynamodb_1.DynamoDBDocumentClient.from(client);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Add item in DynamoDB table
|
|
21
|
+
* @param {object} item // Object containing add for target item
|
|
22
|
+
*/
|
|
23
|
+
async add(item) {
|
|
24
|
+
try {
|
|
25
|
+
item = this.parseDate(item);
|
|
26
|
+
var params = {
|
|
27
|
+
TableName: this.TABLE_NAME,
|
|
28
|
+
Item: Object.assign({}, item)
|
|
29
|
+
};
|
|
30
|
+
if (!("createdAt" in params.Item))
|
|
31
|
+
params.Item.createdAt = Number(Date.now());
|
|
32
|
+
if (!("updatedAt" in params.Item))
|
|
33
|
+
params.Item.updatedAt = Number(Date.now());
|
|
34
|
+
const response = await this.documentClient.send(new lib_dynamodb_1.PutCommand(params));
|
|
35
|
+
console.log('dbItem');
|
|
36
|
+
return response;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
this.handleError(error);
|
|
40
|
+
// // throw new DatabaseException( error.code );
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Update item in DynamoDB table
|
|
45
|
+
* @param {object} key // Object containing target item key(s)
|
|
46
|
+
* @param {object} item // Object containing updates for target item
|
|
47
|
+
*/
|
|
48
|
+
async update(key, item) {
|
|
49
|
+
try {
|
|
50
|
+
const itemKeys = Object.keys(item).filter(k => k !== key);
|
|
51
|
+
const params = {
|
|
52
|
+
TableName: this.TABLE_NAME,
|
|
53
|
+
UpdateExpression: `SET ${itemKeys.map((k, index) => `#field${index} = :value${index}`).join(', ')}`,
|
|
54
|
+
ExpressionAttributeNames: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`#field${index}`]: k })), {}),
|
|
55
|
+
ExpressionAttributeValues: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`:value${index}`]: item[k] })), {}),
|
|
56
|
+
Key: {
|
|
57
|
+
[key]: item[key]
|
|
58
|
+
},
|
|
59
|
+
ReturnValues: 'ALL_NEW'
|
|
60
|
+
};
|
|
61
|
+
return await this.documentClient.send(new lib_dynamodb_1.UpdateCommand(params));
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
this.handleError(error);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Update item in DynamoDB table
|
|
69
|
+
* @param {String[]} keys // String Array containing target item key(s)
|
|
70
|
+
* @param {object} item // Object containing updates for target item
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
async updateByMutiple(keys, item) {
|
|
74
|
+
try {
|
|
75
|
+
// const itemKeys = Object.keys(item).filter(k => !key.includes(k));
|
|
76
|
+
const itemKeys = Object.keys(item).filter(k => !keys.includes(k));
|
|
77
|
+
const keyItem = Object.keys(item).filter(k => keys.includes(k));
|
|
78
|
+
const params = {
|
|
79
|
+
TableName: this.TABLE_NAME,
|
|
80
|
+
UpdateExpression: `SET ${itemKeys.map((k, index) => `#field${index} = :value${index}`).join(', ')}`,
|
|
81
|
+
ExpressionAttributeNames: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`#field${index}`]: k })), {}),
|
|
82
|
+
ExpressionAttributeValues: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`:value${index}`]: item[k] })), {}),
|
|
83
|
+
Key: keyItem.reduce((obj, key) => {
|
|
84
|
+
obj[key] = item[key];
|
|
85
|
+
return obj;
|
|
86
|
+
}, {}),
|
|
87
|
+
ReturnValues: 'ALL_NEW'
|
|
88
|
+
};
|
|
89
|
+
return await this.documentClient.send(new lib_dynamodb_1.UpdateCommand(params));
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
this.handleError(error);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
*
|
|
97
|
+
* @param key Only Partition Key (No Primary Key or Combination Key)
|
|
98
|
+
* @param item Object of Keys
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
// public async updateByMutipleValue (key: string, item: any) {
|
|
102
|
+
// try {
|
|
103
|
+
// const keyItem = Object.keys(item).filter(k => k == key).reduce((obj: any, key: any) => {
|
|
104
|
+
// obj[key] = item[key];
|
|
105
|
+
// return obj;
|
|
106
|
+
// }, {});
|
|
107
|
+
// let responseItem = await this.getSingleItem(keyItem);
|
|
108
|
+
// if(responseItem)
|
|
109
|
+
// {
|
|
110
|
+
// const itemKeys = Object.keys(item).filter(k => k !== key).reduce((obj: any, key: any) => {
|
|
111
|
+
// obj[key] = item[key];
|
|
112
|
+
// return obj;
|
|
113
|
+
// }, {});
|
|
114
|
+
// let returnResponse = this.parseDate({...responseItem,...itemKeys,updatedAt:Number(Date.now())});
|
|
115
|
+
// var params: PutCommandInput = {
|
|
116
|
+
// TableName: this.TABLE_NAME,
|
|
117
|
+
// Item: returnResponse
|
|
118
|
+
// }
|
|
119
|
+
// console.log(returnResponse);
|
|
120
|
+
// await this.documentClient.send(new PutCommand(params))
|
|
121
|
+
// return returnResponse;
|
|
122
|
+
// }
|
|
123
|
+
// return responseItem;
|
|
124
|
+
// } catch (error) {
|
|
125
|
+
// this.handleError(error);
|
|
126
|
+
// }
|
|
127
|
+
// }
|
|
128
|
+
/**
|
|
129
|
+
* Get item in DynamoDB table
|
|
130
|
+
* @param {object} id // Object containing target item key(s)
|
|
131
|
+
* @param {object} version // Object containing updates for target item
|
|
132
|
+
*/
|
|
133
|
+
async getById(key) {
|
|
134
|
+
console.info("Dynamo db Repository: getById Start");
|
|
135
|
+
var params = {
|
|
136
|
+
TableName: this.TABLE_NAME,
|
|
137
|
+
Key: key
|
|
138
|
+
};
|
|
139
|
+
try {
|
|
140
|
+
console.info("Dynamo db Repository: getById End");
|
|
141
|
+
const command = new lib_dynamodb_1.GetCommand(params);
|
|
142
|
+
const response = await this.documentClient.send(command);
|
|
143
|
+
if (response && response.Item) {
|
|
144
|
+
return this.unparseDate(response.Item);
|
|
145
|
+
}
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
console.error(`error occured while getting custom order log by primary keys - customOrderLog - ${error}`);
|
|
150
|
+
console.error("Dynamo db Repository: Error: ");
|
|
151
|
+
this.handleError(error);
|
|
152
|
+
// throw new DatabaseException( error.code );
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Get item in DynamoDB table
|
|
157
|
+
* @param {object} id // Object containing target item key(s)
|
|
158
|
+
* @param {object} version // Object containing updates for target item
|
|
159
|
+
*/
|
|
160
|
+
// public async getSingleItem (key: object) {
|
|
161
|
+
// let response = await this.query(key);
|
|
162
|
+
// if(response)
|
|
163
|
+
// return response[0];
|
|
164
|
+
// else
|
|
165
|
+
// return null;
|
|
166
|
+
// }
|
|
167
|
+
/**
|
|
168
|
+
* Get items in DynamoDB table
|
|
169
|
+
* @param {object} item // Object containing target item key(s)
|
|
170
|
+
*/
|
|
171
|
+
async query(item, condition, indexName, projectionExpression, limit, scanIndexForward = true, exclusiveStartKey) {
|
|
172
|
+
console.info("Dynamo db Repository: query Start");
|
|
173
|
+
try {
|
|
174
|
+
const itemKeys = Object.keys(item);
|
|
175
|
+
// let Key, Filter;
|
|
176
|
+
// if (!indexName) {
|
|
177
|
+
// Key = `${itemKeys.map((k, index) => {
|
|
178
|
+
// if (this.PRIMARY_KEY.length === 0 || this.PRIMARY_KEY.includes(k))
|
|
179
|
+
// if (!this.isComparator(condition![index] || '='))
|
|
180
|
+
// return `${condition![index]}(#field${index} ,:value${index})`
|
|
181
|
+
// else
|
|
182
|
+
// return `#field${index} ${condition![index] || '='} :value${index}`
|
|
183
|
+
// }).filter(a => a).join(' and ')}`;
|
|
184
|
+
// Filter = `${itemKeys.map((k, index) => {
|
|
185
|
+
// if (!this.PRIMARY_KEY.includes(k))
|
|
186
|
+
// if (!this.isComparator(condition![index] || '='))
|
|
187
|
+
// if(condition![index].toUpperCase() == 'IN')
|
|
188
|
+
// return `#field${index} ${condition![index]}(${Object.keys(this.getArrayValue(item[k],index)).toString()})`
|
|
189
|
+
// else
|
|
190
|
+
// return `${condition![index]}(#field${index} ,:value${index})`
|
|
191
|
+
// else
|
|
192
|
+
// return `#field${index} ${condition![index] || '='} :value${index}`
|
|
193
|
+
// }).filter(a => a).join(' and ')}`;
|
|
194
|
+
// }
|
|
195
|
+
// else {
|
|
196
|
+
// Key = `${itemKeys.map((k, index) => {
|
|
197
|
+
// if (indexName.split('-').includes(k)) {
|
|
198
|
+
// if (!this.isComparator(condition![index] || '='))
|
|
199
|
+
// return `${condition![index]}(#field${index} ,:value${index})`
|
|
200
|
+
// else
|
|
201
|
+
// return `#field${index} ${condition![index] || '='} :value${index}`
|
|
202
|
+
// }
|
|
203
|
+
// }).filter(a => a).join(' and ')}`;
|
|
204
|
+
// Filter = `${itemKeys.map((k, index) => {
|
|
205
|
+
// if (!indexName.split('-').includes(k)) {
|
|
206
|
+
// if (!this.isComparator(condition![index] || '='))
|
|
207
|
+
// if(condition![index].toUpperCase() == 'IN')
|
|
208
|
+
// return `#field${index} ${condition![index]}(${Object.keys(this.getArrayValue(item[k],index)).toString()})`
|
|
209
|
+
// else
|
|
210
|
+
// return `${condition![index]}(#field${index} ,:value${index})`
|
|
211
|
+
// else
|
|
212
|
+
// return `#field${index} ${condition![index] || '='} :value${index}`
|
|
213
|
+
// }
|
|
214
|
+
// }).filter(a => a).join(' and ')}`;
|
|
215
|
+
// }
|
|
216
|
+
let [Key, Filter] = await this.getKeyAndFilter(item, condition, indexName);
|
|
217
|
+
let params = {
|
|
218
|
+
TableName: this.TABLE_NAME,
|
|
219
|
+
ExpressionAttributeNames: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`#field${index}`]: k })), {}),
|
|
220
|
+
ExpressionAttributeValues: itemKeys.reduce((accumulator, k, index) => {
|
|
221
|
+
if (Array.isArray(item[k])) {
|
|
222
|
+
let data = this.getArrayValue(item[k], index);
|
|
223
|
+
return Object.assign(Object.assign({}, accumulator), data);
|
|
224
|
+
}
|
|
225
|
+
else
|
|
226
|
+
return Object.assign(Object.assign({}, accumulator), { [`:value${index}`]: item[k] });
|
|
227
|
+
}, {}),
|
|
228
|
+
KeyConditionExpression: Key,
|
|
229
|
+
ScanIndexForward: scanIndexForward
|
|
230
|
+
};
|
|
231
|
+
if (exclusiveStartKey)
|
|
232
|
+
params = Object.assign(params, { ExclusiveStartKey: exclusiveStartKey });
|
|
233
|
+
if (indexName)
|
|
234
|
+
params = Object.assign(params, { IndexName: indexName });
|
|
235
|
+
if (projectionExpression)
|
|
236
|
+
params = Object.assign(params, { ProjectionExpression: projectionExpression });
|
|
237
|
+
if (Filter)
|
|
238
|
+
params = Object.assign(params, { FilterExpression: Filter });
|
|
239
|
+
// if (limit)
|
|
240
|
+
// params = Object.assign(params, { Limit:limit});
|
|
241
|
+
let response, acc = [];
|
|
242
|
+
do {
|
|
243
|
+
response = await this.documentClient.send(new lib_dynamodb_1.QueryCommand(params));
|
|
244
|
+
console.info("Repository: query End");
|
|
245
|
+
params.ExclusiveStartKey = response.LastEvaluatedKey;
|
|
246
|
+
console.log("Last Evaluated Key");
|
|
247
|
+
if (limit) {
|
|
248
|
+
if (response && response.Items) {
|
|
249
|
+
if (response.Items.length <= limit - acc.length)
|
|
250
|
+
acc = [...acc, ...response.Items];
|
|
251
|
+
else
|
|
252
|
+
acc = [...acc, ...response.Items.slice(0, limit - acc.length)];
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
else if (response && response.Items)
|
|
256
|
+
acc = [...acc, ...response.Items];
|
|
257
|
+
} while (response && response.Items && response.LastEvaluatedKey && (!limit || acc.length < limit));
|
|
258
|
+
if (acc.length > 0)
|
|
259
|
+
return this.unparseDate(acc);
|
|
260
|
+
else
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
this.handleError(error);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Get items in DynamoDB table with Pagination
|
|
269
|
+
* @param {object} item // Object containing target item key(s)
|
|
270
|
+
*/
|
|
271
|
+
async queryWithPagination(item, condition, indexName, projectionExpression, limit = 1000, scanIndexForward = true, exclusiveStartKey) {
|
|
272
|
+
console.info("Dynamo db Repository: query Start");
|
|
273
|
+
try {
|
|
274
|
+
const itemKeys = Object.keys(item);
|
|
275
|
+
// let Key, Filter;
|
|
276
|
+
// if (!indexName) {
|
|
277
|
+
// Key = `${itemKeys.map((k, index) => {
|
|
278
|
+
// if (this.PRIMARY_KEY.length === 0 || this.PRIMARY_KEY.includes(k))
|
|
279
|
+
// if (!this.isComparator(condition![index] || '='))
|
|
280
|
+
// return `${condition![index]}(#field${index} ,:value${index})`
|
|
281
|
+
// else
|
|
282
|
+
// return `#field${index} ${condition![index] || '='} :value${index}`
|
|
283
|
+
// }).filter(a => a).join(' and ')}`;
|
|
284
|
+
// Filter = `${itemKeys.map((k, index) => {
|
|
285
|
+
// if (!this.PRIMARY_KEY.includes(k))
|
|
286
|
+
// if (!this.isComparator(condition![index] || '='))
|
|
287
|
+
// if(condition![index].toUpperCase() == 'IN')
|
|
288
|
+
// return `#field${index} ${condition![index]}(${Object.keys(this.getArrayValue(item[k],index)).toString()})`
|
|
289
|
+
// else
|
|
290
|
+
// return `${condition![index]}(#field${index} ,:value${index})`
|
|
291
|
+
// else
|
|
292
|
+
// return `#field${index} ${condition![index] || '='} :value${index}`
|
|
293
|
+
// }).filter(a => a).join(' and ')}`;
|
|
294
|
+
// }
|
|
295
|
+
// else {
|
|
296
|
+
// Key = `${itemKeys.map((k, index) => {
|
|
297
|
+
// if (indexName.split('-').includes(k)) {
|
|
298
|
+
// if (!this.isComparator(condition![index] || '='))
|
|
299
|
+
// return `${condition![index]}(#field${index} ,:value${index})`
|
|
300
|
+
// else
|
|
301
|
+
// return `#field${index} ${condition![index] || '='} :value${index}`
|
|
302
|
+
// }
|
|
303
|
+
// }).filter(a => a).join(' and ')}`;
|
|
304
|
+
// Filter = `${itemKeys.map((k, index) => {
|
|
305
|
+
// if (!indexName.split('-').includes(k)) {
|
|
306
|
+
// if (!this.isComparator(condition![index] || '='))
|
|
307
|
+
// if(condition![index].toUpperCase() == 'IN')
|
|
308
|
+
// return `#field${index} ${condition![index]}(${Object.keys(this.getArrayValue(item[k],index)).toString()})`
|
|
309
|
+
// else
|
|
310
|
+
// return `${condition![index]}(#field${index} ,:value${index})`
|
|
311
|
+
// else
|
|
312
|
+
// return `#field${index} ${condition![index] || '='} :value${index}`
|
|
313
|
+
// }
|
|
314
|
+
// }).filter(a => a).join(' and ')}`;
|
|
315
|
+
// }
|
|
316
|
+
let [Key, Filter] = await this.getKeyAndFilter(item, condition, indexName);
|
|
317
|
+
let params = {
|
|
318
|
+
TableName: this.TABLE_NAME,
|
|
319
|
+
ExpressionAttributeNames: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`#field${index}`]: k })), {}),
|
|
320
|
+
ExpressionAttributeValues: itemKeys.reduce((accumulator, k, index) => {
|
|
321
|
+
if (Array.isArray(item[k])) {
|
|
322
|
+
let data = this.getArrayValue(item[k], index);
|
|
323
|
+
return Object.assign(Object.assign({}, accumulator), data);
|
|
324
|
+
}
|
|
325
|
+
else
|
|
326
|
+
return Object.assign(Object.assign({}, accumulator), { [`:value${index}`]: item[k] });
|
|
327
|
+
}, {}),
|
|
328
|
+
KeyConditionExpression: Key,
|
|
329
|
+
ScanIndexForward: scanIndexForward
|
|
330
|
+
};
|
|
331
|
+
if (exclusiveStartKey)
|
|
332
|
+
params = Object.assign(params, { ExclusiveStartKey: exclusiveStartKey });
|
|
333
|
+
if (indexName)
|
|
334
|
+
params = Object.assign(params, { IndexName: indexName });
|
|
335
|
+
if (projectionExpression)
|
|
336
|
+
params = Object.assign(params, { ProjectionExpression: projectionExpression });
|
|
337
|
+
if (Filter)
|
|
338
|
+
params = Object.assign(params, { FilterExpression: Filter });
|
|
339
|
+
if (limit)
|
|
340
|
+
params = Object.assign(params, { Limit: limit });
|
|
341
|
+
let response, acc = { exclusiveStartKey: "", data: [] };
|
|
342
|
+
do {
|
|
343
|
+
response = await this.documentClient.send(new lib_dynamodb_1.QueryCommand(params));
|
|
344
|
+
console.info("Repository: query End");
|
|
345
|
+
params.ExclusiveStartKey = response.LastEvaluatedKey;
|
|
346
|
+
console.log("Last Evaluated Key");
|
|
347
|
+
acc.exclusiveStartKey = response.LastEvaluatedKey;
|
|
348
|
+
if (response && response.Items)
|
|
349
|
+
acc.data = [...acc.data, ...response.Items];
|
|
350
|
+
if (limit)
|
|
351
|
+
params.Limit = limit - acc.data.length;
|
|
352
|
+
} while (response && response.Items && response.LastEvaluatedKey && acc.data.length < limit);
|
|
353
|
+
if (acc.data.length > 0) {
|
|
354
|
+
acc.data = this.unparseDate(acc.data);
|
|
355
|
+
return acc;
|
|
356
|
+
}
|
|
357
|
+
else
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
catch (error) {
|
|
361
|
+
this.handleError(error);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Get items in DynamoDB table
|
|
366
|
+
* @param {object} item // Object containing target item key(s)
|
|
367
|
+
* @param {Array} condition // Array containing target item key(s) condition
|
|
368
|
+
* @param {String} projectionExpression // if you want only selected filed should return
|
|
369
|
+
*/
|
|
370
|
+
async scan(item, condition, projectionExpression, exclusiveStartKey) {
|
|
371
|
+
console.info("Dynamo db Repository: query Start");
|
|
372
|
+
try {
|
|
373
|
+
const itemKeys = Object.keys(item);
|
|
374
|
+
const Key = `${itemKeys.map((k, index) => `#field${index} ${condition[index]} :value${index}`).join(' and ')}`;
|
|
375
|
+
let params = {
|
|
376
|
+
TableName: this.TABLE_NAME,
|
|
377
|
+
ExpressionAttributeNames: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`#field${index}`]: k })), {}),
|
|
378
|
+
ExpressionAttributeValues: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`:value${index}`]: item[k] })), {}),
|
|
379
|
+
FilterExpression: Key
|
|
380
|
+
};
|
|
381
|
+
if (projectionExpression)
|
|
382
|
+
params = Object.assign(params, { ProjectionExpression: projectionExpression });
|
|
383
|
+
if (exclusiveStartKey)
|
|
384
|
+
params = Object.assign(params, { ExclusiveStartKey: exclusiveStartKey });
|
|
385
|
+
let response, acc = [];
|
|
386
|
+
do {
|
|
387
|
+
response = await this.documentClient.send(new lib_dynamodb_1.ScanCommand(params));
|
|
388
|
+
console.info("Repository: query End");
|
|
389
|
+
params.ExclusiveStartKey = response.LastEvaluatedKey;
|
|
390
|
+
console.log("Last Evaluated Key");
|
|
391
|
+
if (response && response.Items)
|
|
392
|
+
acc = [...acc, ...response.Items];
|
|
393
|
+
} while (response && response.Items && response.LastEvaluatedKey);
|
|
394
|
+
if (acc.length > 0)
|
|
395
|
+
return this.unparseDate(acc);
|
|
396
|
+
else
|
|
397
|
+
return null;
|
|
398
|
+
}
|
|
399
|
+
catch (error) {
|
|
400
|
+
this.handleError(error);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Delete item in DynamoDB table
|
|
405
|
+
* @param {object} key // Object containing target item key(s)
|
|
406
|
+
*/
|
|
407
|
+
async delete(key) {
|
|
408
|
+
console.info("Dynamo db Repository: delete Start");
|
|
409
|
+
var params = {
|
|
410
|
+
TableName: this.TABLE_NAME,
|
|
411
|
+
Key: key
|
|
412
|
+
};
|
|
413
|
+
try {
|
|
414
|
+
const command = new lib_dynamodb_1.DeleteCommand(params);
|
|
415
|
+
const data = await this.documentClient.send(command);
|
|
416
|
+
console.info("Dynamo db Repository: delete End");
|
|
417
|
+
}
|
|
418
|
+
catch (error) {
|
|
419
|
+
console.error(`error occured while deleting custom order log by primary keys - customOrderLog - ${error}`);
|
|
420
|
+
console.error("Dynamo db Repository: Error: ");
|
|
421
|
+
this.handleError(error);
|
|
422
|
+
// throw new DatabaseException( error.code );
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Get All items in DynamoDB table
|
|
427
|
+
*/
|
|
428
|
+
async getAll(exclusiveStartKey) {
|
|
429
|
+
var params = {
|
|
430
|
+
TableName: this.TABLE_NAME
|
|
431
|
+
};
|
|
432
|
+
try {
|
|
433
|
+
console.info("Dynamo Repository: getAll Start");
|
|
434
|
+
if (exclusiveStartKey)
|
|
435
|
+
params = Object.assign(params, { ExclusiveStartKey: exclusiveStartKey });
|
|
436
|
+
let response, acc = [];
|
|
437
|
+
do {
|
|
438
|
+
response = await this.documentClient.send(new lib_dynamodb_1.ScanCommand(params));
|
|
439
|
+
console.info("Repository: query End");
|
|
440
|
+
params.ExclusiveStartKey = response.LastEvaluatedKey;
|
|
441
|
+
console.log("Last Evaluated Key");
|
|
442
|
+
if (response && response.Items)
|
|
443
|
+
acc = [...acc, ...response.Items];
|
|
444
|
+
} while (response && response.Items && response.LastEvaluatedKey);
|
|
445
|
+
console.info("Dynamo db Repository: getAll End");
|
|
446
|
+
return this.unparseDate(acc);
|
|
447
|
+
}
|
|
448
|
+
catch (error) {
|
|
449
|
+
console.error(`error occured while get all custom order log by primary keys - customOrderLog - ${error}`);
|
|
450
|
+
console.error("Dynamo db Repository: Error: ");
|
|
451
|
+
this.handleError(error);
|
|
452
|
+
// throw new DatabaseException( error.code );
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Bulk Upload item in DynamoDB table
|
|
457
|
+
* @param {object} item // Object containing add for target item
|
|
458
|
+
*/
|
|
459
|
+
async bulkUpload(items) {
|
|
460
|
+
try {
|
|
461
|
+
let insertItem = await Promise.all(items.map(async (item) => {
|
|
462
|
+
item = this.parseDate(item);
|
|
463
|
+
return item;
|
|
464
|
+
// return {PutRequest:{Item:item}};
|
|
465
|
+
}));
|
|
466
|
+
// chunkArray is a local convenience function. It takes an array and returns
|
|
467
|
+
// a generator function. The generator function yields every N items.
|
|
468
|
+
const itemChunks = [...Array(Math.ceil(insertItem.length / 25))].map(_ => insertItem.splice(0, 25));
|
|
469
|
+
// For every chunk of 25 items, make one BatchWrite request.
|
|
470
|
+
for (const chunk of itemChunks) {
|
|
471
|
+
const putRequests = chunk.map((data) => ({
|
|
472
|
+
PutRequest: {
|
|
473
|
+
Item: data,
|
|
474
|
+
},
|
|
475
|
+
}));
|
|
476
|
+
const command = new lib_dynamodb_1.BatchWriteCommand({
|
|
477
|
+
RequestItems: {
|
|
478
|
+
// An existing table is required. A composite key of 'title' and 'year' is recommended
|
|
479
|
+
// to account for duplicate titles.
|
|
480
|
+
[this.TABLE_NAME]: putRequests
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
const response = await this.documentClient.send(command);
|
|
484
|
+
console.log('dbItem');
|
|
485
|
+
}
|
|
486
|
+
console.log("Upload Successfully");
|
|
487
|
+
return true;
|
|
488
|
+
}
|
|
489
|
+
catch (error) {
|
|
490
|
+
this.handleError(error);
|
|
491
|
+
// // throw new DatabaseException( error.code );
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
*
|
|
496
|
+
* @param data
|
|
497
|
+
* @returns
|
|
498
|
+
*/
|
|
499
|
+
parseDate(data) {
|
|
500
|
+
return JSON.parse(JSON.stringify(data));
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
*
|
|
504
|
+
* @param data
|
|
505
|
+
* @returns
|
|
506
|
+
*/
|
|
507
|
+
unparseDate(data) {
|
|
508
|
+
//const dateFormat = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/;
|
|
509
|
+
var ISO_8601_FULL = /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+)?(([+-]\d\d:\d\d)|Z)?$/i;
|
|
510
|
+
var DATE_STRING = /^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$/i;
|
|
511
|
+
function reviver(key, value) {
|
|
512
|
+
if ((typeof value === "string" && ISO_8601_FULL.test(value))) {
|
|
513
|
+
//var tzoffset = (new Date(value)).getTimezoneOffset() * 60000; //offset in milliseconds
|
|
514
|
+
var localISOTime = new Date(value).toISOString();
|
|
515
|
+
return new Date(localISOTime);
|
|
516
|
+
}
|
|
517
|
+
if (typeof value === "string" && DATE_STRING.test(value)) {
|
|
518
|
+
return new Date(value);
|
|
519
|
+
}
|
|
520
|
+
return value;
|
|
521
|
+
}
|
|
522
|
+
const text = JSON.stringify(data);
|
|
523
|
+
const obj = JSON.parse(text, reviver);
|
|
524
|
+
return obj;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
*
|
|
528
|
+
* @param err
|
|
529
|
+
* @returns
|
|
530
|
+
*/
|
|
531
|
+
// Handles errors during PutItem execution. Use recommendations in error messages below to
|
|
532
|
+
// add error handling specific to your application use-case.
|
|
533
|
+
handleError(err) {
|
|
534
|
+
if (!err) {
|
|
535
|
+
console.error("Encountered error object was empty");
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
if (!err.code) {
|
|
539
|
+
console.error(`An exception occurred, investigate and configure retry strategy. Error: ${JSON.stringify(err)}`);
|
|
540
|
+
}
|
|
541
|
+
switch (err.code) {
|
|
542
|
+
case "ConditionalCheckFailedException":
|
|
543
|
+
console.error(`Condition check specified in the operation failed, review and update the condition check before retrying. Error: ${err.message}`);
|
|
544
|
+
break;
|
|
545
|
+
case "TransactionConflictException":
|
|
546
|
+
console.error(`Operation was rejected because there is an ongoing transaction for the item, generally safe to retry ' +
|
|
547
|
+
'with exponential back-off. Error: ${err.message}`);
|
|
548
|
+
break;
|
|
549
|
+
case "ItemCollectionSizeLimitExceededException":
|
|
550
|
+
console.error("An item collection is too large, you're using Local Secondary Index and exceeded size limit of" +
|
|
551
|
+
`items per partition key. Consider using Global Secondary Index instead. Error: ${err.message}`);
|
|
552
|
+
break;
|
|
553
|
+
default:
|
|
554
|
+
break;
|
|
555
|
+
// Common DynamoDB API errors are handled below
|
|
556
|
+
}
|
|
557
|
+
this.handleCommonErrors(err);
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
*
|
|
561
|
+
* @param err
|
|
562
|
+
*/
|
|
563
|
+
handleCommonErrors(err) {
|
|
564
|
+
switch (err.code) {
|
|
565
|
+
case "InternalServerError":
|
|
566
|
+
console.error(`Internal Server Error, generally safe to retry with exponential back-off. Error: ${err.message}`);
|
|
567
|
+
break;
|
|
568
|
+
case "ProvisionedThroughputExceededException":
|
|
569
|
+
console.error("Request rate is too high. If you're using a custom retry strategy make sure to retry with exponential back-off."
|
|
570
|
+
+ `Otherwise consider reducing frequency of requests or increasing provisioned capacity for your table or secondary index. Error: ${err.message}`);
|
|
571
|
+
break;
|
|
572
|
+
case "ResourceNotFoundException":
|
|
573
|
+
console.error(`One of the tables was not found, verify table exists before retrying. Error: ${err.message}`);
|
|
574
|
+
break;
|
|
575
|
+
case "ServiceUnavailable":
|
|
576
|
+
console.error(`Had trouble reaching DynamoDB. generally safe to retry with exponential back-off. Error: ${err.message}`);
|
|
577
|
+
break;
|
|
578
|
+
case "ThrottlingException":
|
|
579
|
+
console.error(`Request denied due to throttling, generally safe to retry with exponential back-off. Error: ${err.message}`);
|
|
580
|
+
break;
|
|
581
|
+
case "UnrecognizedClientException":
|
|
582
|
+
console.error("The request signature is incorrect most likely due to an invalid AWS access key ID or secret key, fix before retrying."
|
|
583
|
+
+ `Error: ${err.message}`);
|
|
584
|
+
break;
|
|
585
|
+
case "ValidationException":
|
|
586
|
+
console.error("The input fails to satisfy the constraints specified by DynamoDB, "
|
|
587
|
+
+ `fix input before retrying. Error: ${err.message}`);
|
|
588
|
+
break;
|
|
589
|
+
case "RequestLimitExceeded":
|
|
590
|
+
console.error("Throughput exceeds the current throughput limit for your account, "
|
|
591
|
+
+ `increase account level throughput before retrying. Error: ${err.message}`);
|
|
592
|
+
break;
|
|
593
|
+
default:
|
|
594
|
+
console.error(`An exception occurred, investigate and configure retry strategy. Error: ${err.message}`);
|
|
595
|
+
break;
|
|
596
|
+
}
|
|
597
|
+
// throw new DatabaseException( err.code );
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
*
|
|
601
|
+
* @param str
|
|
602
|
+
* @returns
|
|
603
|
+
*/
|
|
604
|
+
isComparator(str) {
|
|
605
|
+
return ['=', '<>', '<', '<=', '>', '>='].includes(str);
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
*
|
|
609
|
+
* @param item
|
|
610
|
+
* @param index
|
|
611
|
+
* @returns
|
|
612
|
+
*/
|
|
613
|
+
getArrayValue(item, index) {
|
|
614
|
+
return item.reduce((acc, key, idx) => {
|
|
615
|
+
acc[`:value${index}${idx}`] = key;
|
|
616
|
+
return acc;
|
|
617
|
+
}, {});
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
*
|
|
621
|
+
* @param item
|
|
622
|
+
* @param condition
|
|
623
|
+
* @param indexName
|
|
624
|
+
* @returns
|
|
625
|
+
*/
|
|
626
|
+
getKeyAndFilter(item, condition, indexName) {
|
|
627
|
+
try {
|
|
628
|
+
const itemKeys = Object.keys(item);
|
|
629
|
+
let Key, Filter;
|
|
630
|
+
if (!indexName) {
|
|
631
|
+
Key = `${itemKeys.map((k, index) => {
|
|
632
|
+
if (this.PRIMARY_KEY.length === 0 || this.PRIMARY_KEY.includes(k))
|
|
633
|
+
if (!this.isComparator(condition[index] || '=')) {
|
|
634
|
+
if (condition[index].toUpperCase() == 'BETWEEN')
|
|
635
|
+
return `#field${index} ${condition[index]} ${Object.keys(this.getArrayValue(item[k], index)).join(' and ')}`;
|
|
636
|
+
else if (condition[index].toUpperCase() == 'IN')
|
|
637
|
+
return `#field${index} ${condition[index]}(${Object.keys(this.getArrayValue(item[k], index)).toString()})`;
|
|
638
|
+
else
|
|
639
|
+
return `${condition[index]}(#field${index} ,:value${index})`;
|
|
640
|
+
}
|
|
641
|
+
else
|
|
642
|
+
return `#field${index} ${condition[index] || '='} :value${index}`;
|
|
643
|
+
}).filter(a => a).join(' and ')}`;
|
|
644
|
+
Filter = `${itemKeys.map((k, index) => {
|
|
645
|
+
if (!this.PRIMARY_KEY.includes(k))
|
|
646
|
+
if (!this.isComparator(condition[index] || '=')) {
|
|
647
|
+
if (condition[index].toUpperCase() == 'BETWEEN')
|
|
648
|
+
return `#field${index} ${condition[index]} ${Object.keys(this.getArrayValue(item[k], index)).join(' and ')}`;
|
|
649
|
+
else if (condition[index].toUpperCase() == 'IN')
|
|
650
|
+
return `#field${index} ${condition[index]}(${Object.keys(this.getArrayValue(item[k], index)).toString()})`;
|
|
651
|
+
else
|
|
652
|
+
return `${condition[index]}(#field${index} ,:value${index})`;
|
|
653
|
+
}
|
|
654
|
+
else
|
|
655
|
+
return `#field${index} ${condition[index] || '='} :value${index}`;
|
|
656
|
+
}).filter(a => a).join(' and ')}`;
|
|
657
|
+
}
|
|
658
|
+
else {
|
|
659
|
+
Key = `${itemKeys.map((k, index) => {
|
|
660
|
+
if (indexName.split('-').includes(k)) {
|
|
661
|
+
if (!this.isComparator(condition[index] || '=')) {
|
|
662
|
+
if (condition[index].toUpperCase() == 'BETWEEN')
|
|
663
|
+
return `#field${index} ${condition[index]} ${Object.keys(this.getArrayValue(item[k], index)).join(' and ')}`;
|
|
664
|
+
else if (condition[index].toUpperCase() == 'IN')
|
|
665
|
+
return `#field${index} ${condition[index]}(${Object.keys(this.getArrayValue(item[k], index)).toString()})`;
|
|
666
|
+
else
|
|
667
|
+
return `${condition[index]}(#field${index} ,:value${index})`;
|
|
668
|
+
}
|
|
669
|
+
else
|
|
670
|
+
return `#field${index} ${condition[index] || '='} :value${index}`;
|
|
671
|
+
}
|
|
672
|
+
}).filter(a => a).join(' and ')}`;
|
|
673
|
+
Filter = `${itemKeys.map((k, index) => {
|
|
674
|
+
if (!indexName.split('-').includes(k)) {
|
|
675
|
+
if (!this.isComparator(condition[index] || '=')) {
|
|
676
|
+
if (condition[index].toUpperCase() == 'BETWEEN')
|
|
677
|
+
return `#field${index} ${condition[index]} ${Object.keys(this.getArrayValue(item[k], index)).join(' and ')}`;
|
|
678
|
+
else if (condition[index].toUpperCase() == 'IN')
|
|
679
|
+
return `#field${index} ${condition[index]}(${Object.keys(this.getArrayValue(item[k], index)).toString()})`;
|
|
680
|
+
else
|
|
681
|
+
return `${condition[index]}(#field${index} ,:value${index})`;
|
|
682
|
+
}
|
|
683
|
+
else
|
|
684
|
+
return `#field${index} ${condition[index] || '='} :value${index}`;
|
|
685
|
+
}
|
|
686
|
+
}).filter(a => a).join(' and ')}`;
|
|
687
|
+
}
|
|
688
|
+
return [Key, Filter];
|
|
689
|
+
}
|
|
690
|
+
catch (error) {
|
|
691
|
+
throw error;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
exports.default = BaseDynamoDBRepository;
|
|
696
|
+
//# sourceMappingURL=dynamodb.js.map
|