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
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; // ES Modules import
|
|
2
11
|
import { DynamoDBDocumentClient, ScanCommand, QueryCommand, PutCommand, UpdateCommand, DeleteCommand, GetCommand, BatchWriteCommand } from "@aws-sdk/lib-dynamodb";
|
|
3
12
|
const awsRegion = process.env.AWS_DEFAULT_REGION || 'us-east-1';
|
|
@@ -18,49 +27,53 @@ export default class BaseDynamoDBRepository {
|
|
|
18
27
|
* Add item in DynamoDB table
|
|
19
28
|
* @param {object} item // Object containing add for target item
|
|
20
29
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
add(item) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
try {
|
|
33
|
+
item = this.parseDate(item);
|
|
34
|
+
var params = {
|
|
35
|
+
TableName: this.TABLE_NAME,
|
|
36
|
+
Item: Object.assign({}, item)
|
|
37
|
+
};
|
|
38
|
+
if (!("createdAt" in params.Item))
|
|
39
|
+
params.Item.createdAt = Number(Date.now());
|
|
40
|
+
if (!("updatedAt" in params.Item))
|
|
41
|
+
params.Item.updatedAt = Number(Date.now());
|
|
42
|
+
const response = yield this.documentClient.send(new PutCommand(params));
|
|
43
|
+
console.log('dbItem');
|
|
44
|
+
return response;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
this.handleError(error);
|
|
48
|
+
// // throw new DatabaseException( error.code );
|
|
49
|
+
}
|
|
50
|
+
});
|
|
40
51
|
}
|
|
41
52
|
/**
|
|
42
53
|
* Update item in DynamoDB table
|
|
43
54
|
* @param {object} key // Object containing target item key(s)
|
|
44
55
|
* @param {object} item // Object containing updates for target item
|
|
45
56
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
update(key, item) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
try {
|
|
60
|
+
const itemKeys = Object.keys(item).filter(k => k !== key);
|
|
61
|
+
const params = {
|
|
62
|
+
TableName: this.TABLE_NAME,
|
|
63
|
+
UpdateExpression: `SET ${itemKeys.map((k, index) => `#field${index} = :value${index}`).join(', ')}`,
|
|
64
|
+
ExpressionAttributeNames: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`#field${index}`]: k })), {}),
|
|
65
|
+
ExpressionAttributeValues: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`:value${index}`]: item[k] })), {}),
|
|
66
|
+
Key: {
|
|
67
|
+
[key]: item[key]
|
|
68
|
+
},
|
|
69
|
+
ReturnValues: 'ALL_NEW'
|
|
70
|
+
};
|
|
71
|
+
return yield this.documentClient.send(new UpdateCommand(params));
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
this.handleError(error);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
64
77
|
}
|
|
65
78
|
/**
|
|
66
79
|
* Update item in DynamoDB table
|
|
@@ -68,27 +81,29 @@ export default class BaseDynamoDBRepository {
|
|
|
68
81
|
* @param {object} item // Object containing updates for target item
|
|
69
82
|
* @returns
|
|
70
83
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
obj
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
84
|
+
updateByMutiple(keys, item) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
try {
|
|
87
|
+
// const itemKeys = Object.keys(item).filter(k => !key.includes(k));
|
|
88
|
+
const itemKeys = Object.keys(item).filter(k => !keys.includes(k));
|
|
89
|
+
const keyItem = Object.keys(item).filter(k => keys.includes(k));
|
|
90
|
+
const params = {
|
|
91
|
+
TableName: this.TABLE_NAME,
|
|
92
|
+
UpdateExpression: `SET ${itemKeys.map((k, index) => `#field${index} = :value${index}`).join(', ')}`,
|
|
93
|
+
ExpressionAttributeNames: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`#field${index}`]: k })), {}),
|
|
94
|
+
ExpressionAttributeValues: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`:value${index}`]: item[k] })), {}),
|
|
95
|
+
Key: keyItem.reduce((obj, key) => {
|
|
96
|
+
obj[key] = item[key];
|
|
97
|
+
return obj;
|
|
98
|
+
}, {}),
|
|
99
|
+
ReturnValues: 'ALL_NEW'
|
|
100
|
+
};
|
|
101
|
+
return yield this.documentClient.send(new UpdateCommand(params));
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
this.handleError(error);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
92
107
|
}
|
|
93
108
|
/**
|
|
94
109
|
*
|
|
@@ -128,27 +143,29 @@ export default class BaseDynamoDBRepository {
|
|
|
128
143
|
* @param {object} id // Object containing target item key(s)
|
|
129
144
|
* @param {object} version // Object containing updates for target item
|
|
130
145
|
*/
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
146
|
+
getById(key) {
|
|
147
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
console.info("Dynamo db Repository: getById Start");
|
|
149
|
+
var params = {
|
|
150
|
+
TableName: this.TABLE_NAME,
|
|
151
|
+
Key: key
|
|
152
|
+
};
|
|
153
|
+
try {
|
|
154
|
+
console.info("Dynamo db Repository: getById End");
|
|
155
|
+
const command = new GetCommand(params);
|
|
156
|
+
const response = yield this.documentClient.send(command);
|
|
157
|
+
if (response && response.Item) {
|
|
158
|
+
return this.unparseDate(response.Item);
|
|
159
|
+
}
|
|
160
|
+
return null;
|
|
143
161
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
console.error(`error occured while getting custom order log by primary keys - customOrderLog - ${error}`);
|
|
164
|
+
console.error("Dynamo db Repository: Error: ");
|
|
165
|
+
this.handleError(error);
|
|
166
|
+
// throw new DatabaseException( error.code );
|
|
167
|
+
}
|
|
168
|
+
});
|
|
152
169
|
}
|
|
153
170
|
/**
|
|
154
171
|
* Get item in DynamoDB table
|
|
@@ -166,198 +183,202 @@ export default class BaseDynamoDBRepository {
|
|
|
166
183
|
* Get items in DynamoDB table
|
|
167
184
|
* @param {object} item // Object containing target item key(s)
|
|
168
185
|
*/
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
return Object.assign(Object.assign({}, accumulator), { [`:value${index}`]: item[k] });
|
|
225
|
-
}, {}),
|
|
226
|
-
KeyConditionExpression: Key,
|
|
227
|
-
ScanIndexForward: scanIndexForward
|
|
228
|
-
};
|
|
229
|
-
if (exclusiveStartKey)
|
|
230
|
-
params = Object.assign(params, { ExclusiveStartKey: exclusiveStartKey });
|
|
231
|
-
if (indexName)
|
|
232
|
-
params = Object.assign(params, { IndexName: indexName });
|
|
233
|
-
if (projectionExpression)
|
|
234
|
-
params = Object.assign(params, { ProjectionExpression: projectionExpression });
|
|
235
|
-
if (Filter)
|
|
236
|
-
params = Object.assign(params, { FilterExpression: Filter });
|
|
237
|
-
// if (limit)
|
|
238
|
-
// params = Object.assign(params, { Limit:limit});
|
|
239
|
-
let response, acc = [];
|
|
240
|
-
do {
|
|
241
|
-
response = await this.documentClient.send(new QueryCommand(params));
|
|
242
|
-
console.info("Repository: query End");
|
|
243
|
-
params.ExclusiveStartKey = response.LastEvaluatedKey;
|
|
244
|
-
console.log("Last Evaluated Key");
|
|
245
|
-
if (limit) {
|
|
246
|
-
if (response && response.Items) {
|
|
247
|
-
if (response.Items.length <= limit - acc.length)
|
|
248
|
-
acc = [...acc, ...response.Items];
|
|
186
|
+
query(item, condition, indexName, projectionExpression, limit, scanIndexForward = true, exclusiveStartKey) {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
console.info("Dynamo db Repository: query Start");
|
|
189
|
+
try {
|
|
190
|
+
const itemKeys = Object.keys(item);
|
|
191
|
+
// let Key, Filter;
|
|
192
|
+
// if (!indexName) {
|
|
193
|
+
// Key = `${itemKeys.map((k, index) => {
|
|
194
|
+
// if (this.PRIMARY_KEY.length === 0 || this.PRIMARY_KEY.includes(k))
|
|
195
|
+
// if (!this.isComparator(condition![index] || '='))
|
|
196
|
+
// return `${condition![index]}(#field${index} ,:value${index})`
|
|
197
|
+
// else
|
|
198
|
+
// return `#field${index} ${condition![index] || '='} :value${index}`
|
|
199
|
+
// }).filter(a => a).join(' and ')}`;
|
|
200
|
+
// Filter = `${itemKeys.map((k, index) => {
|
|
201
|
+
// if (!this.PRIMARY_KEY.includes(k))
|
|
202
|
+
// if (!this.isComparator(condition![index] || '='))
|
|
203
|
+
// if(condition![index].toUpperCase() == 'IN')
|
|
204
|
+
// return `#field${index} ${condition![index]}(${Object.keys(this.getArrayValue(item[k],index)).toString()})`
|
|
205
|
+
// else
|
|
206
|
+
// return `${condition![index]}(#field${index} ,:value${index})`
|
|
207
|
+
// else
|
|
208
|
+
// return `#field${index} ${condition![index] || '='} :value${index}`
|
|
209
|
+
// }).filter(a => a).join(' and ')}`;
|
|
210
|
+
// }
|
|
211
|
+
// else {
|
|
212
|
+
// Key = `${itemKeys.map((k, index) => {
|
|
213
|
+
// if (indexName.split('-').includes(k)) {
|
|
214
|
+
// if (!this.isComparator(condition![index] || '='))
|
|
215
|
+
// return `${condition![index]}(#field${index} ,:value${index})`
|
|
216
|
+
// else
|
|
217
|
+
// return `#field${index} ${condition![index] || '='} :value${index}`
|
|
218
|
+
// }
|
|
219
|
+
// }).filter(a => a).join(' and ')}`;
|
|
220
|
+
// Filter = `${itemKeys.map((k, index) => {
|
|
221
|
+
// if (!indexName.split('-').includes(k)) {
|
|
222
|
+
// if (!this.isComparator(condition![index] || '='))
|
|
223
|
+
// if(condition![index].toUpperCase() == 'IN')
|
|
224
|
+
// return `#field${index} ${condition![index]}(${Object.keys(this.getArrayValue(item[k],index)).toString()})`
|
|
225
|
+
// else
|
|
226
|
+
// return `${condition![index]}(#field${index} ,:value${index})`
|
|
227
|
+
// else
|
|
228
|
+
// return `#field${index} ${condition![index] || '='} :value${index}`
|
|
229
|
+
// }
|
|
230
|
+
// }).filter(a => a).join(' and ')}`;
|
|
231
|
+
// }
|
|
232
|
+
let [Key, Filter] = yield this.getKeyAndFilter(item, condition, indexName);
|
|
233
|
+
let params = {
|
|
234
|
+
TableName: this.TABLE_NAME,
|
|
235
|
+
ExpressionAttributeNames: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`#field${index}`]: k })), {}),
|
|
236
|
+
ExpressionAttributeValues: itemKeys.reduce((accumulator, k, index) => {
|
|
237
|
+
if (Array.isArray(item[k])) {
|
|
238
|
+
let data = this.getArrayValue(item[k], index);
|
|
239
|
+
return Object.assign(Object.assign({}, accumulator), data);
|
|
240
|
+
}
|
|
249
241
|
else
|
|
250
|
-
|
|
242
|
+
return Object.assign(Object.assign({}, accumulator), { [`:value${index}`]: item[k] });
|
|
243
|
+
}, {}),
|
|
244
|
+
KeyConditionExpression: Key,
|
|
245
|
+
ScanIndexForward: scanIndexForward
|
|
246
|
+
};
|
|
247
|
+
if (exclusiveStartKey)
|
|
248
|
+
params = Object.assign(params, { ExclusiveStartKey: exclusiveStartKey });
|
|
249
|
+
if (indexName)
|
|
250
|
+
params = Object.assign(params, { IndexName: indexName });
|
|
251
|
+
if (projectionExpression)
|
|
252
|
+
params = Object.assign(params, { ProjectionExpression: projectionExpression });
|
|
253
|
+
if (Filter)
|
|
254
|
+
params = Object.assign(params, { FilterExpression: Filter });
|
|
255
|
+
// if (limit)
|
|
256
|
+
// params = Object.assign(params, { Limit:limit});
|
|
257
|
+
let response, acc = [];
|
|
258
|
+
do {
|
|
259
|
+
response = yield this.documentClient.send(new QueryCommand(params));
|
|
260
|
+
console.info("Repository: query End");
|
|
261
|
+
params.ExclusiveStartKey = response.LastEvaluatedKey;
|
|
262
|
+
console.log("Last Evaluated Key");
|
|
263
|
+
if (limit) {
|
|
264
|
+
if (response && response.Items) {
|
|
265
|
+
if (response.Items.length <= limit - acc.length)
|
|
266
|
+
acc = [...acc, ...response.Items];
|
|
267
|
+
else
|
|
268
|
+
acc = [...acc, ...response.Items.slice(0, limit - acc.length)];
|
|
269
|
+
}
|
|
251
270
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
271
|
+
else if (response && response.Items)
|
|
272
|
+
acc = [...acc, ...response.Items];
|
|
273
|
+
} while (response && response.Items && response.LastEvaluatedKey && (!limit || acc.length < limit));
|
|
274
|
+
if (acc.length > 0)
|
|
275
|
+
return this.unparseDate(acc);
|
|
276
|
+
else
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
this.handleError(error);
|
|
281
|
+
}
|
|
282
|
+
});
|
|
264
283
|
}
|
|
265
284
|
/**
|
|
266
285
|
* Get items in DynamoDB table with Pagination
|
|
267
286
|
* @param {object} item // Object containing target item key(s)
|
|
268
287
|
*/
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
params = Object.assign(params, { Limit: limit });
|
|
339
|
-
let response, acc = { exclusiveStartKey: "", data: [] };
|
|
340
|
-
do {
|
|
341
|
-
response = await this.documentClient.send(new QueryCommand(params));
|
|
342
|
-
console.info("Repository: query End");
|
|
343
|
-
params.ExclusiveStartKey = response.LastEvaluatedKey;
|
|
344
|
-
console.log("Last Evaluated Key");
|
|
345
|
-
acc.exclusiveStartKey = response.LastEvaluatedKey;
|
|
346
|
-
if (response && response.Items)
|
|
347
|
-
acc.data = [...acc.data, ...response.Items];
|
|
288
|
+
queryWithPagination(item, condition, indexName, projectionExpression, limit = 1000, scanIndexForward = true, exclusiveStartKey) {
|
|
289
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
290
|
+
console.info("Dynamo db Repository: query Start");
|
|
291
|
+
try {
|
|
292
|
+
const itemKeys = Object.keys(item);
|
|
293
|
+
// let Key, Filter;
|
|
294
|
+
// if (!indexName) {
|
|
295
|
+
// Key = `${itemKeys.map((k, index) => {
|
|
296
|
+
// if (this.PRIMARY_KEY.length === 0 || this.PRIMARY_KEY.includes(k))
|
|
297
|
+
// if (!this.isComparator(condition![index] || '='))
|
|
298
|
+
// return `${condition![index]}(#field${index} ,:value${index})`
|
|
299
|
+
// else
|
|
300
|
+
// return `#field${index} ${condition![index] || '='} :value${index}`
|
|
301
|
+
// }).filter(a => a).join(' and ')}`;
|
|
302
|
+
// Filter = `${itemKeys.map((k, index) => {
|
|
303
|
+
// if (!this.PRIMARY_KEY.includes(k))
|
|
304
|
+
// if (!this.isComparator(condition![index] || '='))
|
|
305
|
+
// if(condition![index].toUpperCase() == 'IN')
|
|
306
|
+
// return `#field${index} ${condition![index]}(${Object.keys(this.getArrayValue(item[k],index)).toString()})`
|
|
307
|
+
// else
|
|
308
|
+
// return `${condition![index]}(#field${index} ,:value${index})`
|
|
309
|
+
// else
|
|
310
|
+
// return `#field${index} ${condition![index] || '='} :value${index}`
|
|
311
|
+
// }).filter(a => a).join(' and ')}`;
|
|
312
|
+
// }
|
|
313
|
+
// else {
|
|
314
|
+
// Key = `${itemKeys.map((k, index) => {
|
|
315
|
+
// if (indexName.split('-').includes(k)) {
|
|
316
|
+
// if (!this.isComparator(condition![index] || '='))
|
|
317
|
+
// return `${condition![index]}(#field${index} ,:value${index})`
|
|
318
|
+
// else
|
|
319
|
+
// return `#field${index} ${condition![index] || '='} :value${index}`
|
|
320
|
+
// }
|
|
321
|
+
// }).filter(a => a).join(' and ')}`;
|
|
322
|
+
// Filter = `${itemKeys.map((k, index) => {
|
|
323
|
+
// if (!indexName.split('-').includes(k)) {
|
|
324
|
+
// if (!this.isComparator(condition![index] || '='))
|
|
325
|
+
// if(condition![index].toUpperCase() == 'IN')
|
|
326
|
+
// return `#field${index} ${condition![index]}(${Object.keys(this.getArrayValue(item[k],index)).toString()})`
|
|
327
|
+
// else
|
|
328
|
+
// return `${condition![index]}(#field${index} ,:value${index})`
|
|
329
|
+
// else
|
|
330
|
+
// return `#field${index} ${condition![index] || '='} :value${index}`
|
|
331
|
+
// }
|
|
332
|
+
// }).filter(a => a).join(' and ')}`;
|
|
333
|
+
// }
|
|
334
|
+
let [Key, Filter] = yield this.getKeyAndFilter(item, condition, indexName);
|
|
335
|
+
let params = {
|
|
336
|
+
TableName: this.TABLE_NAME,
|
|
337
|
+
ExpressionAttributeNames: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`#field${index}`]: k })), {}),
|
|
338
|
+
ExpressionAttributeValues: itemKeys.reduce((accumulator, k, index) => {
|
|
339
|
+
if (Array.isArray(item[k])) {
|
|
340
|
+
let data = this.getArrayValue(item[k], index);
|
|
341
|
+
return Object.assign(Object.assign({}, accumulator), data);
|
|
342
|
+
}
|
|
343
|
+
else
|
|
344
|
+
return Object.assign(Object.assign({}, accumulator), { [`:value${index}`]: item[k] });
|
|
345
|
+
}, {}),
|
|
346
|
+
KeyConditionExpression: Key,
|
|
347
|
+
ScanIndexForward: scanIndexForward
|
|
348
|
+
};
|
|
349
|
+
if (exclusiveStartKey)
|
|
350
|
+
params = Object.assign(params, { ExclusiveStartKey: exclusiveStartKey });
|
|
351
|
+
if (indexName)
|
|
352
|
+
params = Object.assign(params, { IndexName: indexName });
|
|
353
|
+
if (projectionExpression)
|
|
354
|
+
params = Object.assign(params, { ProjectionExpression: projectionExpression });
|
|
355
|
+
if (Filter)
|
|
356
|
+
params = Object.assign(params, { FilterExpression: Filter });
|
|
348
357
|
if (limit)
|
|
349
|
-
params.Limit
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
358
|
+
params = Object.assign(params, { Limit: limit });
|
|
359
|
+
let response, acc = { exclusiveStartKey: "", data: [] };
|
|
360
|
+
do {
|
|
361
|
+
response = yield this.documentClient.send(new QueryCommand(params));
|
|
362
|
+
console.info("Repository: query End");
|
|
363
|
+
params.ExclusiveStartKey = response.LastEvaluatedKey;
|
|
364
|
+
console.log("Last Evaluated Key");
|
|
365
|
+
acc.exclusiveStartKey = response.LastEvaluatedKey;
|
|
366
|
+
if (response && response.Items)
|
|
367
|
+
acc.data = [...acc.data, ...response.Items];
|
|
368
|
+
if (limit)
|
|
369
|
+
params.Limit = limit - acc.data.length;
|
|
370
|
+
} while (response && response.Items && response.LastEvaluatedKey && acc.data.length < limit);
|
|
371
|
+
if (acc.data.length > 0) {
|
|
372
|
+
acc.data = this.unparseDate(acc.data);
|
|
373
|
+
return acc;
|
|
374
|
+
}
|
|
375
|
+
else
|
|
376
|
+
return null;
|
|
354
377
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
this.handleError(error);
|
|
360
|
-
}
|
|
378
|
+
catch (error) {
|
|
379
|
+
this.handleError(error);
|
|
380
|
+
}
|
|
381
|
+
});
|
|
361
382
|
}
|
|
362
383
|
/**
|
|
363
384
|
* Get items in DynamoDB table
|
|
@@ -365,129 +386,137 @@ export default class BaseDynamoDBRepository {
|
|
|
365
386
|
* @param {Array} condition // Array containing target item key(s) condition
|
|
366
387
|
* @param {String} projectionExpression // if you want only selected filed should return
|
|
367
388
|
*/
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
389
|
+
scan(item, condition, projectionExpression, exclusiveStartKey) {
|
|
390
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
391
|
+
console.info("Dynamo db Repository: query Start");
|
|
392
|
+
try {
|
|
393
|
+
const itemKeys = Object.keys(item);
|
|
394
|
+
const Key = `${itemKeys.map((k, index) => `#field${index} ${condition[index]} :value${index}`).join(' and ')}`;
|
|
395
|
+
let params = {
|
|
396
|
+
TableName: this.TABLE_NAME,
|
|
397
|
+
ExpressionAttributeNames: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`#field${index}`]: k })), {}),
|
|
398
|
+
ExpressionAttributeValues: itemKeys.reduce((accumulator, k, index) => (Object.assign(Object.assign({}, accumulator), { [`:value${index}`]: item[k] })), {}),
|
|
399
|
+
FilterExpression: Key
|
|
400
|
+
};
|
|
401
|
+
if (projectionExpression)
|
|
402
|
+
params = Object.assign(params, { ProjectionExpression: projectionExpression });
|
|
403
|
+
if (exclusiveStartKey)
|
|
404
|
+
params = Object.assign(params, { ExclusiveStartKey: exclusiveStartKey });
|
|
405
|
+
let response, acc = [];
|
|
406
|
+
do {
|
|
407
|
+
response = yield this.documentClient.send(new ScanCommand(params));
|
|
408
|
+
console.info("Repository: query End");
|
|
409
|
+
params.ExclusiveStartKey = response.LastEvaluatedKey;
|
|
410
|
+
console.log("Last Evaluated Key");
|
|
411
|
+
if (response && response.Items)
|
|
412
|
+
acc = [...acc, ...response.Items];
|
|
413
|
+
} while (response && response.Items && response.LastEvaluatedKey);
|
|
414
|
+
if (acc.length > 0)
|
|
415
|
+
return this.unparseDate(acc);
|
|
416
|
+
else
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
catch (error) {
|
|
420
|
+
this.handleError(error);
|
|
421
|
+
}
|
|
422
|
+
});
|
|
400
423
|
}
|
|
401
424
|
/**
|
|
402
425
|
* Delete item in DynamoDB table
|
|
403
426
|
* @param {object} key // Object containing target item key(s)
|
|
404
427
|
*/
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
428
|
+
delete(key) {
|
|
429
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
430
|
+
console.info("Dynamo db Repository: delete Start");
|
|
431
|
+
var params = {
|
|
432
|
+
TableName: this.TABLE_NAME,
|
|
433
|
+
Key: key
|
|
434
|
+
};
|
|
435
|
+
try {
|
|
436
|
+
const command = new DeleteCommand(params);
|
|
437
|
+
const data = yield this.documentClient.send(command);
|
|
438
|
+
console.info("Dynamo db Repository: delete End");
|
|
439
|
+
}
|
|
440
|
+
catch (error) {
|
|
441
|
+
console.error(`error occured while deleting custom order log by primary keys - customOrderLog - ${error}`);
|
|
442
|
+
console.error("Dynamo db Repository: Error: ");
|
|
443
|
+
this.handleError(error);
|
|
444
|
+
// throw new DatabaseException( error.code );
|
|
445
|
+
}
|
|
446
|
+
});
|
|
422
447
|
}
|
|
423
448
|
/**
|
|
424
449
|
* Get All items in DynamoDB table
|
|
425
450
|
*/
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
451
|
+
getAll(exclusiveStartKey) {
|
|
452
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
453
|
+
var params = {
|
|
454
|
+
TableName: this.TABLE_NAME
|
|
455
|
+
};
|
|
456
|
+
try {
|
|
457
|
+
console.info("Dynamo Repository: getAll Start");
|
|
458
|
+
if (exclusiveStartKey)
|
|
459
|
+
params = Object.assign(params, { ExclusiveStartKey: exclusiveStartKey });
|
|
460
|
+
let response, acc = [];
|
|
461
|
+
do {
|
|
462
|
+
response = yield this.documentClient.send(new ScanCommand(params));
|
|
463
|
+
console.info("Repository: query End");
|
|
464
|
+
params.ExclusiveStartKey = response.LastEvaluatedKey;
|
|
465
|
+
console.log("Last Evaluated Key");
|
|
466
|
+
if (response && response.Items)
|
|
467
|
+
acc = [...acc, ...response.Items];
|
|
468
|
+
} while (response && response.Items && response.LastEvaluatedKey);
|
|
469
|
+
console.info("Dynamo db Repository: getAll End");
|
|
470
|
+
return this.unparseDate(acc);
|
|
471
|
+
}
|
|
472
|
+
catch (error) {
|
|
473
|
+
console.error(`error occured while get all custom order log by primary keys - customOrderLog - ${error}`);
|
|
474
|
+
console.error("Dynamo db Repository: Error: ");
|
|
475
|
+
this.handleError(error);
|
|
476
|
+
// throw new DatabaseException( error.code );
|
|
477
|
+
}
|
|
478
|
+
});
|
|
452
479
|
}
|
|
453
480
|
/**
|
|
454
481
|
* Bulk Upload item in DynamoDB table
|
|
455
482
|
* @param {object} item // Object containing add for target item
|
|
456
483
|
*/
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
const
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
484
|
+
bulkUpload(items) {
|
|
485
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
486
|
+
try {
|
|
487
|
+
let insertItem = yield Promise.all(items.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
488
|
+
item = this.parseDate(item);
|
|
489
|
+
return item;
|
|
490
|
+
// return {PutRequest:{Item:item}};
|
|
491
|
+
})));
|
|
492
|
+
// chunkArray is a local convenience function. It takes an array and returns
|
|
493
|
+
// a generator function. The generator function yields every N items.
|
|
494
|
+
const itemChunks = [...Array(Math.ceil(insertItem.length / 25))].map(_ => insertItem.splice(0, 25));
|
|
495
|
+
// For every chunk of 25 items, make one BatchWrite request.
|
|
496
|
+
for (const chunk of itemChunks) {
|
|
497
|
+
const putRequests = chunk.map((data) => ({
|
|
498
|
+
PutRequest: {
|
|
499
|
+
Item: data,
|
|
500
|
+
},
|
|
501
|
+
}));
|
|
502
|
+
const command = new BatchWriteCommand({
|
|
503
|
+
RequestItems: {
|
|
504
|
+
// An existing table is required. A composite key of 'title' and 'year' is recommended
|
|
505
|
+
// to account for duplicate titles.
|
|
506
|
+
[this.TABLE_NAME]: putRequests
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
const response = yield this.documentClient.send(command);
|
|
510
|
+
console.log('dbItem');
|
|
511
|
+
}
|
|
512
|
+
console.log("Upload Successfully");
|
|
513
|
+
return true;
|
|
483
514
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
// // throw new DatabaseException( error.code );
|
|
490
|
-
}
|
|
515
|
+
catch (error) {
|
|
516
|
+
this.handleError(error);
|
|
517
|
+
// // throw new DatabaseException( error.code );
|
|
518
|
+
}
|
|
519
|
+
});
|
|
491
520
|
}
|
|
492
521
|
/**
|
|
493
522
|
*
|