mocody 0.2.14 → 0.2.17
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/LICENSE +21 -21
- package/README.md +4 -4
- package/dist/core/base-schema.d.ts +13 -13
- package/dist/core/base-schema.js +11 -11
- package/dist/core/base-schema.js.map +1 -1
- package/dist/couch/couch-data-operation.d.ts +90 -90
- package/dist/couch/couch-data-operation.js +581 -581
- package/dist/couch/couch-data-operation.js.map +1 -1
- package/dist/couch/couch-filter-query-operation.d.ts +47 -47
- package/dist/couch/couch-filter-query-operation.js +438 -438
- package/dist/couch/couch-initializer.d.ts +45 -45
- package/dist/couch/couch-initializer.js +98 -98
- package/dist/couch/couch-initializer.js.map +1 -1
- package/dist/couch/couch-manage-table.d.ts +46 -46
- package/dist/couch/couch-manage-table.js +113 -113
- package/dist/dynamo/dynamo-data-operation.d.ts +97 -97
- package/dist/dynamo/dynamo-data-operation.js +788 -793
- package/dist/dynamo/dynamo-data-operation.js.map +1 -1
- package/dist/dynamo/dynamo-filter-query-operation.d.ts +29 -28
- package/dist/dynamo/dynamo-filter-query-operation.js +655 -627
- package/dist/dynamo/dynamo-filter-query-operation.js.map +1 -1
- package/dist/dynamo/dynamo-helper.d.ts +1 -1
- package/dist/dynamo/dynamo-helper.js +8 -15
- package/dist/dynamo/dynamo-helper.js.map +1 -1
- package/dist/dynamo/dynamo-initializer.d.ts +14 -8
- package/dist/dynamo/dynamo-initializer.js +58 -34
- package/dist/dynamo/dynamo-initializer.js.map +1 -1
- package/dist/dynamo/dynamo-manage-table.d.ts +33 -32
- package/dist/dynamo/dynamo-manage-table.js +419 -418
- package/dist/dynamo/dynamo-manage-table.js.map +1 -1
- package/dist/dynamo/dynamo-query-scan-processor.d.ts +25 -24
- package/dist/dynamo/dynamo-query-scan-processor.js +268 -266
- package/dist/dynamo/dynamo-query-scan-processor.js.map +1 -1
- package/dist/helpers/base-joi-helper.d.ts +2 -2
- package/dist/helpers/base-joi-helper.js +12 -12
- package/dist/helpers/constants.d.ts +3 -3
- package/dist/helpers/constants.js +6 -6
- package/dist/helpers/errors.d.ts +13 -13
- package/dist/helpers/errors.js +38 -38
- package/dist/helpers/logging-service.d.ts +8 -8
- package/dist/helpers/logging-service.js +44 -44
- package/dist/helpers/mocody-utils.d.ts +13 -15
- package/dist/helpers/mocody-utils.js +48 -48
- package/dist/helpers/query-validator.d.ts +20 -20
- package/dist/helpers/query-validator.js +96 -84
- package/dist/helpers/query-validator.js.map +1 -1
- package/dist/helpers/util-service.d.ts +29 -30
- package/dist/helpers/util-service.js +155 -167
- package/dist/helpers/util-service.js.map +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.js +19 -19
- package/dist/model/index.d.ts +40 -40
- package/dist/model/index.js +6 -6
- package/dist/mongo/mongo-data-operation.d.ts +88 -88
- package/dist/mongo/mongo-data-operation.js +597 -597
- package/dist/mongo/mongo-data-operation.js.map +1 -1
- package/dist/mongo/mongo-filter-query-operation.d.ts +47 -47
- package/dist/mongo/mongo-filter-query-operation.js +433 -433
- package/dist/mongo/mongo-initializer.d.ts +16 -16
- package/dist/mongo/mongo-initializer.js +47 -47
- package/dist/mongo/mongo-initializer.js.map +1 -1
- package/dist/mongo/mongo-table-manager.d.ts +31 -31
- package/dist/mongo/mongo-table-manager.js +104 -104
- package/dist/type/index.d.ts +108 -108
- package/dist/type/index.js +2 -2
- package/package.json +70 -71
|
@@ -1,794 +1,789 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DynamoDataOperation = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const util_service_1 = require("./../helpers/util-service");
|
|
6
|
-
const mocody_utils_1 = require("../helpers/mocody-utils");
|
|
7
|
-
const model_1 = require("../model");
|
|
8
|
-
const errors_1 = require("./../helpers/errors");
|
|
9
|
-
const joi_1 =
|
|
10
|
-
const base_joi_helper_1 = require("../helpers/base-joi-helper");
|
|
11
|
-
const base_schema_1 = require("../core/base-schema");
|
|
12
|
-
const dynamo_manage_table_1 = require("./dynamo-manage-table");
|
|
13
|
-
const logging_service_1 = require("../helpers/logging-service");
|
|
14
|
-
const dynamo_filter_query_operation_1 = require("./dynamo-filter-query-operation");
|
|
15
|
-
const dynamo_query_scan_processor_1 = require("./dynamo-query-scan-processor");
|
|
16
|
-
const lodash_1 =
|
|
17
|
-
const dynamo_helper_1 = require("./dynamo-helper");
|
|
18
|
-
class DynamoDataOperation extends model_1.RepoModel {
|
|
19
|
-
constructor({ schemaDef, dynamoDbInitializer, secondaryIndexOptions, featureEntityValue, baseTableName, strictRequiredFields, dataKeyGenerator, }) {
|
|
20
|
-
super();
|
|
21
|
-
Object.defineProperty(this, "_mocody_partitionKeyFieldName", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true,
|
|
25
|
-
value: "id"
|
|
26
|
-
});
|
|
27
|
-
Object.defineProperty(this, "_mocody_sortKeyFieldName", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
configurable: true,
|
|
30
|
-
writable: true,
|
|
31
|
-
value: "featureEntity"
|
|
32
|
-
});
|
|
33
|
-
Object.defineProperty(this, "_mocody_featureEntity_Key_Value", {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
configurable: true,
|
|
36
|
-
writable: true,
|
|
37
|
-
value: void 0
|
|
38
|
-
});
|
|
39
|
-
Object.defineProperty(this, "_mocody_dynamoDb", {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
configurable: true,
|
|
42
|
-
writable: true,
|
|
43
|
-
value: void 0
|
|
44
|
-
});
|
|
45
|
-
Object.defineProperty(this, "_mocody_dataKeyGenerator", {
|
|
46
|
-
enumerable: true,
|
|
47
|
-
configurable: true,
|
|
48
|
-
writable: true,
|
|
49
|
-
value: void 0
|
|
50
|
-
});
|
|
51
|
-
Object.defineProperty(this, "_mocody_schema", {
|
|
52
|
-
enumerable: true,
|
|
53
|
-
configurable: true,
|
|
54
|
-
writable: true,
|
|
55
|
-
value: void 0
|
|
56
|
-
});
|
|
57
|
-
Object.defineProperty(this, "_mocody_tableFullName", {
|
|
58
|
-
enumerable: true,
|
|
59
|
-
configurable: true,
|
|
60
|
-
writable: true,
|
|
61
|
-
value: void 0
|
|
62
|
-
});
|
|
63
|
-
Object.defineProperty(this, "_mocody_strictRequiredFields", {
|
|
64
|
-
enumerable: true,
|
|
65
|
-
configurable: true,
|
|
66
|
-
writable: true,
|
|
67
|
-
value: void 0
|
|
68
|
-
});
|
|
69
|
-
Object.defineProperty(this, "_mocody_featureEntityValue", {
|
|
70
|
-
enumerable: true,
|
|
71
|
-
configurable: true,
|
|
72
|
-
writable: true,
|
|
73
|
-
value: void 0
|
|
74
|
-
});
|
|
75
|
-
Object.defineProperty(this, "_mocody_secondaryIndexOptions", {
|
|
76
|
-
enumerable: true,
|
|
77
|
-
configurable: true,
|
|
78
|
-
writable: true,
|
|
79
|
-
value: void 0
|
|
80
|
-
});
|
|
81
|
-
Object.defineProperty(this, "_mocody_queryFilter", {
|
|
82
|
-
enumerable: true,
|
|
83
|
-
configurable: true,
|
|
84
|
-
writable: true,
|
|
85
|
-
value: void 0
|
|
86
|
-
});
|
|
87
|
-
Object.defineProperty(this, "_mocody_queryScanProcessor", {
|
|
88
|
-
enumerable: true,
|
|
89
|
-
configurable: true,
|
|
90
|
-
writable: true,
|
|
91
|
-
value: void 0
|
|
92
|
-
});
|
|
93
|
-
Object.defineProperty(this, "_mocody_errorHelper", {
|
|
94
|
-
enumerable: true,
|
|
95
|
-
configurable: true,
|
|
96
|
-
writable: true,
|
|
97
|
-
value: void 0
|
|
98
|
-
});
|
|
99
|
-
Object.defineProperty(this, "_mocody_entityFieldsKeySet", {
|
|
100
|
-
enumerable: true,
|
|
101
|
-
configurable: true,
|
|
102
|
-
writable: true,
|
|
103
|
-
value: void 0
|
|
104
|
-
});
|
|
105
|
-
Object.defineProperty(this, "_mocody_tableManager", {
|
|
106
|
-
enumerable: true,
|
|
107
|
-
configurable: true,
|
|
108
|
-
writable: true,
|
|
109
|
-
value: void 0
|
|
110
|
-
});
|
|
111
|
-
this._mocody_dynamoDb = dynamoDbInitializer;
|
|
112
|
-
this._mocody_dataKeyGenerator = dataKeyGenerator;
|
|
113
|
-
this._mocody_tableFullName = baseTableName;
|
|
114
|
-
this._mocody_featureEntityValue = featureEntityValue;
|
|
115
|
-
this._mocody_secondaryIndexOptions = secondaryIndexOptions;
|
|
116
|
-
this._mocody_strictRequiredFields = strictRequiredFields;
|
|
117
|
-
this._mocody_queryFilter = new dynamo_filter_query_operation_1.DynamoFilterQueryOperation();
|
|
118
|
-
this._mocody_queryScanProcessor = new dynamo_query_scan_processor_1.DynamoQueryScanProcessor();
|
|
119
|
-
this._mocody_errorHelper = new errors_1.MocodyErrorUtils();
|
|
120
|
-
this._mocody_featureEntity_Key_Value = { featureEntity: featureEntityValue };
|
|
121
|
-
this._mocody_entityFieldsKeySet = new Set();
|
|
122
|
-
const fullSchemaMapDef = {
|
|
123
|
-
...schemaDef,
|
|
124
|
-
...base_schema_1.coreSchemaDefinition,
|
|
125
|
-
};
|
|
126
|
-
Object.keys(fullSchemaMapDef).forEach((key) => {
|
|
127
|
-
this._mocody_entityFieldsKeySet.add(key);
|
|
128
|
-
});
|
|
129
|
-
this._mocody_schema = joi_1.default.object().keys(fullSchemaMapDef);
|
|
130
|
-
}
|
|
131
|
-
mocody_tableManager() {
|
|
132
|
-
if (!this._mocody_tableManager) {
|
|
133
|
-
this._mocody_tableManager = new dynamo_manage_table_1.DynamoManageTable({
|
|
134
|
-
dynamoDb: () => this.
|
|
135
|
-
secondaryIndexOptions: this._mocody_secondaryIndexOptions,
|
|
136
|
-
tableFullName: this._mocody_tableFullName,
|
|
137
|
-
partitionKeyFieldName: this._mocody_partitionKeyFieldName,
|
|
138
|
-
sortKeyFieldName: this._mocody_sortKeyFieldName,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
return this._mocody_tableManager;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return this._mocody_dynamoDb()
|
|
145
|
-
}
|
|
146
|
-
_mocody_generateDynamoTableKey() {
|
|
147
|
-
return this._mocody_dataKeyGenerator();
|
|
148
|
-
}
|
|
149
|
-
_mocody_getLocalVariables() {
|
|
150
|
-
return {
|
|
151
|
-
partitionKeyFieldName: this._mocody_partitionKeyFieldName,
|
|
152
|
-
sortKeyFieldName: this._mocody_sortKeyFieldName,
|
|
153
|
-
featureEntityValue: this._mocody_featureEntityValue,
|
|
154
|
-
tableFullName: this._mocody_tableFullName,
|
|
155
|
-
secondaryIndexOptions: this._mocody_secondaryIndexOptions,
|
|
156
|
-
strictRequiredFields: this._mocody_strictRequiredFields,
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
_mocody_getBaseObject({ dataId }) {
|
|
160
|
-
const { partitionKeyFieldName, sortKeyFieldName, featureEntityValue } = this._mocody_getLocalVariables();
|
|
161
|
-
const dataMust = {
|
|
162
|
-
[partitionKeyFieldName]: dataId,
|
|
163
|
-
[sortKeyFieldName]: featureEntityValue,
|
|
164
|
-
};
|
|
165
|
-
return dataMust;
|
|
166
|
-
}
|
|
167
|
-
_mocody_checkValidateMustBeAnObjectDataType(data) {
|
|
168
|
-
if (!data || typeof data !== "object") {
|
|
169
|
-
throw this._mocody_createGenericError(`Data MUST be valid object`);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
_mocody_checkValidateStrictRequiredFields(onDataObj) {
|
|
173
|
-
this._mocody_checkValidateMustBeAnObjectDataType(onDataObj);
|
|
174
|
-
const { strictRequiredFields } = this._mocody_getLocalVariables();
|
|
175
|
-
if (strictRequiredFields?.length) {
|
|
176
|
-
strictRequiredFields.forEach((field) => {
|
|
177
|
-
if (onDataObj[field] === null || onDataObj[field] === undefined) {
|
|
178
|
-
throw this._mocody_createGenericError(`Strict required field: '${field}', NOT defined`);
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
_mocody_createGenericError(error) {
|
|
184
|
-
return new errors_1.MocodyGenericError(error);
|
|
185
|
-
}
|
|
186
|
-
_mocody_withConditionPassed({ item, withCondition, }) {
|
|
187
|
-
if (item && typeof item === "object" && withCondition?.length) {
|
|
188
|
-
const isPassed = withCondition.every(({ field, equals }) => {
|
|
189
|
-
return item[field] !== undefined && item[field] === equals;
|
|
190
|
-
});
|
|
191
|
-
return isPassed;
|
|
192
|
-
}
|
|
193
|
-
return true;
|
|
194
|
-
}
|
|
195
|
-
_mocody_removeDuplicateString(strArray) {
|
|
196
|
-
return Array.from(new Set([...strArray]));
|
|
197
|
-
}
|
|
198
|
-
async _mocody_allHelpValidateGetValue(data) {
|
|
199
|
-
const { error, value } = this._mocody_schema.validate(data, {
|
|
200
|
-
stripUnknown: true,
|
|
201
|
-
});
|
|
202
|
-
if (error) {
|
|
203
|
-
const msg = (0, base_joi_helper_1.getJoiValidationErrors)(error) ?? "Validation error occured";
|
|
204
|
-
throw this._mocody_errorHelper.mocody_helper_createFriendlyError(msg);
|
|
205
|
-
}
|
|
206
|
-
return await Promise.resolve({ validatedData: value });
|
|
207
|
-
}
|
|
208
|
-
_mocody_formatTTL(fullData) {
|
|
209
|
-
if (fullData?.dangerouslyExpireAt) {
|
|
210
|
-
fullData.dangerouslyExpireAtTTL = util_service_1.UtilService.getEpochTime(fullData.dangerouslyExpireAt);
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
delete fullData.dangerouslyExpireAtTTL;
|
|
214
|
-
}
|
|
215
|
-
return fullData;
|
|
216
|
-
}
|
|
217
|
-
async mocody_createOne({ data }) {
|
|
218
|
-
const { tableFullName, partitionKeyFieldName } = this._mocody_getLocalVariables();
|
|
219
|
-
try {
|
|
220
|
-
const { marshalled, validatedData } = await this._mocody_validateReady({ data });
|
|
221
|
-
const query01 = {
|
|
222
|
-
[partitionKeyFieldName]: { $exists: false },
|
|
223
|
-
};
|
|
224
|
-
const { expressionAttributeNames, expressionAttributeValues, filterExpression, } = this._mocody_queryFilter.processQueryFilter({
|
|
225
|
-
queryDefs: query01,
|
|
226
|
-
projectionFields: undefined,
|
|
227
|
-
});
|
|
228
|
-
const params = {
|
|
229
|
-
TableName: tableFullName,
|
|
230
|
-
Item: marshalled,
|
|
231
|
-
ConditionExpression: filterExpression,
|
|
232
|
-
ExpressionAttributeNames: expressionAttributeNames,
|
|
233
|
-
ExpressionAttributeValues: expressionAttributeValues,
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
this.
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
[
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
...
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
const
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
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
|
-
|
|
400
|
-
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
const
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
const
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
const
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
const
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
const
|
|
631
|
-
if (!
|
|
632
|
-
throw this._mocody_createGenericError("Invalid
|
|
633
|
-
}
|
|
634
|
-
const
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
const
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
...
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
if (
|
|
737
|
-
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
});
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
const
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
}
|
|
790
|
-
return dataExist;
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
exports.DynamoDataOperation = DynamoDataOperation;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DynamoDataOperation = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const util_service_1 = require("./../helpers/util-service");
|
|
6
|
+
const mocody_utils_1 = require("../helpers/mocody-utils");
|
|
7
|
+
const model_1 = require("../model");
|
|
8
|
+
const errors_1 = require("./../helpers/errors");
|
|
9
|
+
const joi_1 = tslib_1.__importDefault(require("joi"));
|
|
10
|
+
const base_joi_helper_1 = require("../helpers/base-joi-helper");
|
|
11
|
+
const base_schema_1 = require("../core/base-schema");
|
|
12
|
+
const dynamo_manage_table_1 = require("./dynamo-manage-table");
|
|
13
|
+
const logging_service_1 = require("../helpers/logging-service");
|
|
14
|
+
const dynamo_filter_query_operation_1 = require("./dynamo-filter-query-operation");
|
|
15
|
+
const dynamo_query_scan_processor_1 = require("./dynamo-query-scan-processor");
|
|
16
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
17
|
+
const dynamo_helper_1 = require("./dynamo-helper");
|
|
18
|
+
class DynamoDataOperation extends model_1.RepoModel {
|
|
19
|
+
constructor({ schemaDef, dynamoDbInitializer, secondaryIndexOptions, featureEntityValue, baseTableName, strictRequiredFields, dataKeyGenerator, }) {
|
|
20
|
+
super();
|
|
21
|
+
Object.defineProperty(this, "_mocody_partitionKeyFieldName", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: "id"
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(this, "_mocody_sortKeyFieldName", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
value: "featureEntity"
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(this, "_mocody_featureEntity_Key_Value", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
value: void 0
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(this, "_mocody_dynamoDb", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: true,
|
|
42
|
+
writable: true,
|
|
43
|
+
value: void 0
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(this, "_mocody_dataKeyGenerator", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
writable: true,
|
|
49
|
+
value: void 0
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(this, "_mocody_schema", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
writable: true,
|
|
55
|
+
value: void 0
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(this, "_mocody_tableFullName", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
configurable: true,
|
|
60
|
+
writable: true,
|
|
61
|
+
value: void 0
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(this, "_mocody_strictRequiredFields", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
configurable: true,
|
|
66
|
+
writable: true,
|
|
67
|
+
value: void 0
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(this, "_mocody_featureEntityValue", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
configurable: true,
|
|
72
|
+
writable: true,
|
|
73
|
+
value: void 0
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(this, "_mocody_secondaryIndexOptions", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
configurable: true,
|
|
78
|
+
writable: true,
|
|
79
|
+
value: void 0
|
|
80
|
+
});
|
|
81
|
+
Object.defineProperty(this, "_mocody_queryFilter", {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
configurable: true,
|
|
84
|
+
writable: true,
|
|
85
|
+
value: void 0
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(this, "_mocody_queryScanProcessor", {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
configurable: true,
|
|
90
|
+
writable: true,
|
|
91
|
+
value: void 0
|
|
92
|
+
});
|
|
93
|
+
Object.defineProperty(this, "_mocody_errorHelper", {
|
|
94
|
+
enumerable: true,
|
|
95
|
+
configurable: true,
|
|
96
|
+
writable: true,
|
|
97
|
+
value: void 0
|
|
98
|
+
});
|
|
99
|
+
Object.defineProperty(this, "_mocody_entityFieldsKeySet", {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
configurable: true,
|
|
102
|
+
writable: true,
|
|
103
|
+
value: void 0
|
|
104
|
+
});
|
|
105
|
+
Object.defineProperty(this, "_mocody_tableManager", {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
configurable: true,
|
|
108
|
+
writable: true,
|
|
109
|
+
value: void 0
|
|
110
|
+
});
|
|
111
|
+
this._mocody_dynamoDb = dynamoDbInitializer;
|
|
112
|
+
this._mocody_dataKeyGenerator = dataKeyGenerator;
|
|
113
|
+
this._mocody_tableFullName = baseTableName;
|
|
114
|
+
this._mocody_featureEntityValue = featureEntityValue;
|
|
115
|
+
this._mocody_secondaryIndexOptions = secondaryIndexOptions;
|
|
116
|
+
this._mocody_strictRequiredFields = strictRequiredFields;
|
|
117
|
+
this._mocody_queryFilter = new dynamo_filter_query_operation_1.DynamoFilterQueryOperation();
|
|
118
|
+
this._mocody_queryScanProcessor = new dynamo_query_scan_processor_1.DynamoQueryScanProcessor();
|
|
119
|
+
this._mocody_errorHelper = new errors_1.MocodyErrorUtils();
|
|
120
|
+
this._mocody_featureEntity_Key_Value = { featureEntity: featureEntityValue };
|
|
121
|
+
this._mocody_entityFieldsKeySet = new Set();
|
|
122
|
+
const fullSchemaMapDef = {
|
|
123
|
+
...schemaDef,
|
|
124
|
+
...base_schema_1.coreSchemaDefinition,
|
|
125
|
+
};
|
|
126
|
+
Object.keys(fullSchemaMapDef).forEach((key) => {
|
|
127
|
+
this._mocody_entityFieldsKeySet.add(key);
|
|
128
|
+
});
|
|
129
|
+
this._mocody_schema = joi_1.default.object().keys(fullSchemaMapDef);
|
|
130
|
+
}
|
|
131
|
+
mocody_tableManager() {
|
|
132
|
+
if (!this._mocody_tableManager) {
|
|
133
|
+
this._mocody_tableManager = new dynamo_manage_table_1.DynamoManageTable({
|
|
134
|
+
dynamoDb: () => this._mocody_dynamoDb(),
|
|
135
|
+
secondaryIndexOptions: this._mocody_secondaryIndexOptions,
|
|
136
|
+
tableFullName: this._mocody_tableFullName,
|
|
137
|
+
partitionKeyFieldName: this._mocody_partitionKeyFieldName,
|
|
138
|
+
sortKeyFieldName: this._mocody_sortKeyFieldName,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return this._mocody_tableManager;
|
|
142
|
+
}
|
|
143
|
+
_mocody_dynamoInit() {
|
|
144
|
+
return this._mocody_dynamoDb();
|
|
145
|
+
}
|
|
146
|
+
_mocody_generateDynamoTableKey() {
|
|
147
|
+
return this._mocody_dataKeyGenerator();
|
|
148
|
+
}
|
|
149
|
+
_mocody_getLocalVariables() {
|
|
150
|
+
return {
|
|
151
|
+
partitionKeyFieldName: this._mocody_partitionKeyFieldName,
|
|
152
|
+
sortKeyFieldName: this._mocody_sortKeyFieldName,
|
|
153
|
+
featureEntityValue: this._mocody_featureEntityValue,
|
|
154
|
+
tableFullName: this._mocody_tableFullName,
|
|
155
|
+
secondaryIndexOptions: this._mocody_secondaryIndexOptions,
|
|
156
|
+
strictRequiredFields: this._mocody_strictRequiredFields,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
_mocody_getBaseObject({ dataId }) {
|
|
160
|
+
const { partitionKeyFieldName, sortKeyFieldName, featureEntityValue } = this._mocody_getLocalVariables();
|
|
161
|
+
const dataMust = {
|
|
162
|
+
[partitionKeyFieldName]: dataId,
|
|
163
|
+
[sortKeyFieldName]: featureEntityValue,
|
|
164
|
+
};
|
|
165
|
+
return dataMust;
|
|
166
|
+
}
|
|
167
|
+
_mocody_checkValidateMustBeAnObjectDataType(data) {
|
|
168
|
+
if (!data || typeof data !== "object") {
|
|
169
|
+
throw this._mocody_createGenericError(`Data MUST be valid object`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
_mocody_checkValidateStrictRequiredFields(onDataObj) {
|
|
173
|
+
this._mocody_checkValidateMustBeAnObjectDataType(onDataObj);
|
|
174
|
+
const { strictRequiredFields } = this._mocody_getLocalVariables();
|
|
175
|
+
if (strictRequiredFields?.length) {
|
|
176
|
+
strictRequiredFields.forEach((field) => {
|
|
177
|
+
if (onDataObj[field] === null || onDataObj[field] === undefined) {
|
|
178
|
+
throw this._mocody_createGenericError(`Strict required field: '${field}', NOT defined`);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
_mocody_createGenericError(error) {
|
|
184
|
+
return new errors_1.MocodyGenericError(error);
|
|
185
|
+
}
|
|
186
|
+
_mocody_withConditionPassed({ item, withCondition, }) {
|
|
187
|
+
if (item && typeof item === "object" && withCondition?.length) {
|
|
188
|
+
const isPassed = withCondition.every(({ field, equals }) => {
|
|
189
|
+
return item[field] !== undefined && item[field] === equals;
|
|
190
|
+
});
|
|
191
|
+
return isPassed;
|
|
192
|
+
}
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
_mocody_removeDuplicateString(strArray) {
|
|
196
|
+
return Array.from(new Set([...strArray]));
|
|
197
|
+
}
|
|
198
|
+
async _mocody_allHelpValidateGetValue(data) {
|
|
199
|
+
const { error, value } = this._mocody_schema.validate(data, {
|
|
200
|
+
stripUnknown: true,
|
|
201
|
+
});
|
|
202
|
+
if (error) {
|
|
203
|
+
const msg = (0, base_joi_helper_1.getJoiValidationErrors)(error) ?? "Validation error occured";
|
|
204
|
+
throw this._mocody_errorHelper.mocody_helper_createFriendlyError(msg);
|
|
205
|
+
}
|
|
206
|
+
return await Promise.resolve({ validatedData: value });
|
|
207
|
+
}
|
|
208
|
+
_mocody_formatTTL(fullData) {
|
|
209
|
+
if (fullData?.dangerouslyExpireAt) {
|
|
210
|
+
fullData.dangerouslyExpireAtTTL = util_service_1.UtilService.getEpochTime(fullData.dangerouslyExpireAt);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
delete fullData.dangerouslyExpireAtTTL;
|
|
214
|
+
}
|
|
215
|
+
return fullData;
|
|
216
|
+
}
|
|
217
|
+
async mocody_createOne({ data }) {
|
|
218
|
+
const { tableFullName, partitionKeyFieldName } = this._mocody_getLocalVariables();
|
|
219
|
+
try {
|
|
220
|
+
const { marshalled, validatedData } = await this._mocody_validateReady({ data });
|
|
221
|
+
const query01 = {
|
|
222
|
+
[partitionKeyFieldName]: { $exists: false },
|
|
223
|
+
};
|
|
224
|
+
const { expressionAttributeNames, expressionAttributeValues, filterExpression, } = this._mocody_queryFilter.processQueryFilter({
|
|
225
|
+
queryDefs: query01,
|
|
226
|
+
projectionFields: undefined,
|
|
227
|
+
});
|
|
228
|
+
const params = {
|
|
229
|
+
TableName: tableFullName,
|
|
230
|
+
Item: marshalled,
|
|
231
|
+
ConditionExpression: filterExpression,
|
|
232
|
+
ExpressionAttributeNames: expressionAttributeNames,
|
|
233
|
+
ExpressionAttributeValues: expressionAttributeValues,
|
|
234
|
+
};
|
|
235
|
+
await this._mocody_dynamoInit().putItem(params);
|
|
236
|
+
const result = { ...validatedData };
|
|
237
|
+
return result;
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
if (error?.name === "ConditionalCheckFailedException") {
|
|
241
|
+
throw this._mocody_errorHelper.mocody_helper_createFriendlyError(`Field, ${partitionKeyFieldName} already exists`);
|
|
242
|
+
}
|
|
243
|
+
throw error;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
async mocody_validateFormatData({ data }) {
|
|
247
|
+
const { marshalled } = await this._mocody_validateReady({ data });
|
|
248
|
+
return JSON.stringify(marshalled);
|
|
249
|
+
}
|
|
250
|
+
async mocody_formatForDump({ dataList }) {
|
|
251
|
+
const bulkData = [];
|
|
252
|
+
for (const data of dataList) {
|
|
253
|
+
const data01b = await this.mocody_validateFormatData({ data });
|
|
254
|
+
bulkData.push(`{"PutRequest":{"Item":${data01b}}}`);
|
|
255
|
+
}
|
|
256
|
+
return bulkData;
|
|
257
|
+
}
|
|
258
|
+
async _mocody_validateReady({ data }) {
|
|
259
|
+
const { partitionKeyFieldName, featureEntityValue } = this._mocody_getLocalVariables();
|
|
260
|
+
let dataId = data[partitionKeyFieldName];
|
|
261
|
+
if (!dataId) {
|
|
262
|
+
dataId = this._mocody_generateDynamoTableKey();
|
|
263
|
+
}
|
|
264
|
+
if (!(dataId && typeof dataId === "string")) {
|
|
265
|
+
throw this._mocody_createGenericError("Invalid dataId generation");
|
|
266
|
+
}
|
|
267
|
+
const dataMust = this._mocody_getBaseObject({ dataId });
|
|
268
|
+
const fullData = { ...data, ...dataMust };
|
|
269
|
+
if (fullData.featureEntity !== featureEntityValue) {
|
|
270
|
+
throw this._mocody_createGenericError("FeatureEntity mismatched");
|
|
271
|
+
}
|
|
272
|
+
const { validatedData } = await this._mocody_allHelpValidateGetValue(fullData);
|
|
273
|
+
this._mocody_checkValidateStrictRequiredFields(validatedData);
|
|
274
|
+
const validatedDataTTL = this._mocody_formatTTL(validatedData);
|
|
275
|
+
const ready = {
|
|
276
|
+
validatedData,
|
|
277
|
+
marshalled: mocody_utils_1.MocodyUtil.marshallFromJson(validatedDataTTL),
|
|
278
|
+
};
|
|
279
|
+
return ready;
|
|
280
|
+
}
|
|
281
|
+
async mocody_getOneById({ dataId, withCondition, }) {
|
|
282
|
+
const { partitionKeyFieldName, sortKeyFieldName, featureEntityValue, tableFullName, } = this._mocody_getLocalVariables();
|
|
283
|
+
this._mocody_errorHelper.mocody_helper_validateRequiredString({
|
|
284
|
+
QueryGetOnePartitionKey: dataId,
|
|
285
|
+
QueryGetOneSortKey: featureEntityValue,
|
|
286
|
+
});
|
|
287
|
+
const params = {
|
|
288
|
+
TableName: tableFullName,
|
|
289
|
+
Key: {
|
|
290
|
+
[partitionKeyFieldName]: { S: dataId },
|
|
291
|
+
[sortKeyFieldName]: { S: featureEntityValue },
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
const result = await this._mocody_dynamoInit().getItem(params);
|
|
295
|
+
const item01 = result.Item;
|
|
296
|
+
if (!item01) {
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
const item = mocody_utils_1.MocodyUtil.unmarshallToJson(item01);
|
|
300
|
+
const isPassed = this._mocody_withConditionPassed({ withCondition, item });
|
|
301
|
+
if (!isPassed) {
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
return item;
|
|
305
|
+
}
|
|
306
|
+
async mocody_updateOne({ dataId, updateData, withCondition, }) {
|
|
307
|
+
const { tableFullName, partitionKeyFieldName, sortKeyFieldName } = this._mocody_getLocalVariables();
|
|
308
|
+
this._mocody_errorHelper.mocody_helper_validateRequiredString({ Update1DataId: dataId });
|
|
309
|
+
const dataInDb = await this.mocody_getOneById({ dataId });
|
|
310
|
+
if (!dataInDb?.[partitionKeyFieldName]) {
|
|
311
|
+
throw this._mocody_errorHelper.mocody_helper_createFriendlyError("Data does NOT exists");
|
|
312
|
+
}
|
|
313
|
+
if (dataInDb?.[sortKeyFieldName] !== this._mocody_featureEntityValue) {
|
|
314
|
+
throw this._mocody_createGenericError("Record does not exists");
|
|
315
|
+
}
|
|
316
|
+
const isPassed = this._mocody_withConditionPassed({
|
|
317
|
+
withCondition,
|
|
318
|
+
item: dataInDb,
|
|
319
|
+
});
|
|
320
|
+
if (!isPassed) {
|
|
321
|
+
throw this._mocody_createGenericError("Update condition failed");
|
|
322
|
+
}
|
|
323
|
+
const dataMust = this._mocody_getBaseObject({ dataId });
|
|
324
|
+
const fullData = {
|
|
325
|
+
...dataInDb,
|
|
326
|
+
...updateData,
|
|
327
|
+
...dataMust,
|
|
328
|
+
};
|
|
329
|
+
const { validatedData } = await this._mocody_allHelpValidateGetValue(fullData);
|
|
330
|
+
this._mocody_checkValidateStrictRequiredFields(validatedData);
|
|
331
|
+
const validatedData01 = this._mocody_formatTTL(validatedData);
|
|
332
|
+
const query01 = {
|
|
333
|
+
[partitionKeyFieldName]: { $exists: true },
|
|
334
|
+
};
|
|
335
|
+
const { expressionAttributeNames, expressionAttributeValues, filterExpression, } = this._mocody_queryFilter.processQueryFilter({
|
|
336
|
+
queryDefs: query01,
|
|
337
|
+
projectionFields: undefined,
|
|
338
|
+
});
|
|
339
|
+
const params = {
|
|
340
|
+
TableName: tableFullName,
|
|
341
|
+
Item: mocody_utils_1.MocodyUtil.marshallFromJson(validatedData01),
|
|
342
|
+
ConditionExpression: filterExpression,
|
|
343
|
+
ExpressionAttributeNames: expressionAttributeNames,
|
|
344
|
+
ExpressionAttributeValues: expressionAttributeValues,
|
|
345
|
+
};
|
|
346
|
+
await this._mocody_dynamoInit().putItem(params);
|
|
347
|
+
const result = validatedData;
|
|
348
|
+
return result;
|
|
349
|
+
}
|
|
350
|
+
async mocody_prepareTransaction({ transactPrepareInfo, }) {
|
|
351
|
+
const { tableFullName, partitionKeyFieldName, sortKeyFieldName, featureEntityValue, } = this._mocody_getLocalVariables();
|
|
352
|
+
const prepareTransactData = [];
|
|
353
|
+
for (const transactInfoItem of transactPrepareInfo) {
|
|
354
|
+
if (transactInfoItem.kind === "create") {
|
|
355
|
+
const { marshalled } = await this._mocody_validateReady({ data: transactInfoItem.data });
|
|
356
|
+
prepareTransactData.push({
|
|
357
|
+
kind: transactInfoItem.kind,
|
|
358
|
+
tableName: tableFullName,
|
|
359
|
+
data: marshalled,
|
|
360
|
+
partitionKeyFieldName,
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
else if (transactInfoItem.kind === "update") {
|
|
364
|
+
const dataMust = this._mocody_getBaseObject({ dataId: transactInfoItem.dataId });
|
|
365
|
+
const fullData = {
|
|
366
|
+
...transactInfoItem.data,
|
|
367
|
+
...dataMust,
|
|
368
|
+
};
|
|
369
|
+
const { validatedData } = await this._mocody_allHelpValidateGetValue(fullData);
|
|
370
|
+
this._mocody_checkValidateStrictRequiredFields(validatedData);
|
|
371
|
+
const validatedData01 = this._mocody_formatTTL(validatedData);
|
|
372
|
+
prepareTransactData.push({
|
|
373
|
+
partitionKeyFieldName,
|
|
374
|
+
kind: transactInfoItem.kind,
|
|
375
|
+
tableName: tableFullName,
|
|
376
|
+
data: mocody_utils_1.MocodyUtil.marshallFromJson(validatedData01),
|
|
377
|
+
keyQuery: {
|
|
378
|
+
[partitionKeyFieldName]: { S: transactInfoItem.dataId },
|
|
379
|
+
[sortKeyFieldName]: { S: featureEntityValue },
|
|
380
|
+
},
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
else if (transactInfoItem.kind === "delete") {
|
|
384
|
+
prepareTransactData.push({
|
|
385
|
+
partitionKeyFieldName,
|
|
386
|
+
kind: transactInfoItem.kind,
|
|
387
|
+
tableName: tableFullName,
|
|
388
|
+
keyQuery: {
|
|
389
|
+
[partitionKeyFieldName]: { S: transactInfoItem.dataId },
|
|
390
|
+
[sortKeyFieldName]: { S: featureEntityValue },
|
|
391
|
+
},
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return Promise.resolve(prepareTransactData);
|
|
396
|
+
}
|
|
397
|
+
async mocody_executeTransaction({ transactInfo }) {
|
|
398
|
+
const transactData = {
|
|
399
|
+
TransactItems: [],
|
|
400
|
+
};
|
|
401
|
+
for (const item of transactInfo) {
|
|
402
|
+
if (item.kind === "create") {
|
|
403
|
+
const query01 = {
|
|
404
|
+
[item.partitionKeyFieldName]: { $exists: false },
|
|
405
|
+
};
|
|
406
|
+
const { expressionAttributeNames, expressionAttributeValues, filterExpression, } = this._mocody_queryFilter.processQueryFilter({
|
|
407
|
+
queryDefs: query01,
|
|
408
|
+
projectionFields: undefined,
|
|
409
|
+
});
|
|
410
|
+
transactData.TransactItems?.push({
|
|
411
|
+
Put: {
|
|
412
|
+
TableName: item.tableName,
|
|
413
|
+
Item: item.data,
|
|
414
|
+
ConditionExpression: filterExpression,
|
|
415
|
+
ExpressionAttributeNames: expressionAttributeNames,
|
|
416
|
+
ExpressionAttributeValues: expressionAttributeValues,
|
|
417
|
+
},
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
else if (item.kind === "update") {
|
|
421
|
+
const query01 = {
|
|
422
|
+
[item.partitionKeyFieldName]: { $exists: true },
|
|
423
|
+
};
|
|
424
|
+
const { expressionAttributeNames, expressionAttributeValues, filterExpression, } = this._mocody_queryFilter.processQueryFilter({
|
|
425
|
+
queryDefs: query01,
|
|
426
|
+
projectionFields: undefined,
|
|
427
|
+
});
|
|
428
|
+
transactData.TransactItems?.push({
|
|
429
|
+
Put: {
|
|
430
|
+
TableName: item.tableName,
|
|
431
|
+
Item: item.data,
|
|
432
|
+
ConditionExpression: filterExpression,
|
|
433
|
+
ExpressionAttributeNames: expressionAttributeNames,
|
|
434
|
+
ExpressionAttributeValues: expressionAttributeValues,
|
|
435
|
+
},
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
else if (item.kind === "delete") {
|
|
439
|
+
const query01 = {
|
|
440
|
+
[item.partitionKeyFieldName]: { $exists: true },
|
|
441
|
+
};
|
|
442
|
+
const { expressionAttributeNames, expressionAttributeValues, filterExpression, } = this._mocody_queryFilter.processQueryFilter({
|
|
443
|
+
queryDefs: query01,
|
|
444
|
+
projectionFields: undefined,
|
|
445
|
+
});
|
|
446
|
+
transactData.TransactItems?.push({
|
|
447
|
+
Delete: {
|
|
448
|
+
TableName: item.tableName,
|
|
449
|
+
Key: item.keyQuery,
|
|
450
|
+
ConditionExpression: filterExpression,
|
|
451
|
+
ExpressionAttributeNames: expressionAttributeNames,
|
|
452
|
+
ExpressionAttributeValues: expressionAttributeValues,
|
|
453
|
+
},
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
await this._mocody_dynamoInit().transactWriteItems(transactData);
|
|
458
|
+
}
|
|
459
|
+
_mocody_getProjectionFields({ excludeFields, fields, }) {
|
|
460
|
+
return mocody_utils_1.MocodyUtil.getProjectionFields({
|
|
461
|
+
excludeFields,
|
|
462
|
+
fields,
|
|
463
|
+
entityFields: Array.from(this._mocody_entityFieldsKeySet),
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
async mocody_getManyByIds({ dataIds, fields, excludeFields, withCondition, }) {
|
|
467
|
+
dataIds.forEach((dataId) => {
|
|
468
|
+
this._mocody_errorHelper.mocody_helper_validateRequiredString({
|
|
469
|
+
BatchGetDataId: dataId,
|
|
470
|
+
});
|
|
471
|
+
});
|
|
472
|
+
const originalIds = this._mocody_removeDuplicateString(dataIds);
|
|
473
|
+
const BATCH_SIZE = 80;
|
|
474
|
+
const batchIds = lodash_1.default.chunk(originalIds, BATCH_SIZE);
|
|
475
|
+
logging_service_1.LoggingService.log({
|
|
476
|
+
batchIds,
|
|
477
|
+
"@mocody_getManyByIds batchIds": batchIds.length,
|
|
478
|
+
});
|
|
479
|
+
let resultAll = [];
|
|
480
|
+
const fieldKeys = this._mocody_getProjectionFields({ fields, excludeFields });
|
|
481
|
+
for (const batch of batchIds) {
|
|
482
|
+
const callByIds = await this.mocody_batchGetManyByIdsBasePrivate({
|
|
483
|
+
dataIds: batch,
|
|
484
|
+
fields: fieldKeys,
|
|
485
|
+
withCondition,
|
|
486
|
+
});
|
|
487
|
+
resultAll = [...resultAll, ...callByIds];
|
|
488
|
+
}
|
|
489
|
+
logging_service_1.LoggingService.log("@mocody_getManyByIds batchIds result Out: ", resultAll.length);
|
|
490
|
+
return resultAll;
|
|
491
|
+
}
|
|
492
|
+
async mocody_batchGetManyByIdsBasePrivate({ dataIds, fields, excludeFields, withCondition, }) {
|
|
493
|
+
const { tableFullName, partitionKeyFieldName, sortKeyFieldName, featureEntityValue, } = this._mocody_getLocalVariables();
|
|
494
|
+
const dataIdsNoDup = this._mocody_removeDuplicateString(dataIds);
|
|
495
|
+
let projectionExpression;
|
|
496
|
+
let expressionAttributeNames;
|
|
497
|
+
const fields01 = this._mocody_getProjectionFields({ fields, excludeFields });
|
|
498
|
+
if (fields01?.length) {
|
|
499
|
+
const fieldKeys = new Set(fields01);
|
|
500
|
+
if (withCondition?.length) {
|
|
501
|
+
withCondition.forEach((condition) => {
|
|
502
|
+
fieldKeys.add(condition.field);
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
expressionAttributeNames = {};
|
|
506
|
+
fieldKeys.forEach((fieldName) => {
|
|
507
|
+
if (typeof fieldName === "string") {
|
|
508
|
+
if (expressionAttributeNames) {
|
|
509
|
+
const attrKeyHash = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)("#");
|
|
510
|
+
expressionAttributeNames[attrKeyHash] = fieldName;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
if (Object.keys(expressionAttributeNames)?.length) {
|
|
515
|
+
projectionExpression = Object.keys(expressionAttributeNames).join(",");
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
projectionExpression = undefined;
|
|
519
|
+
expressionAttributeNames = undefined;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
const getArray = dataIdsNoDup.map((dataId) => {
|
|
523
|
+
const params01 = {
|
|
524
|
+
[partitionKeyFieldName]: { S: dataId },
|
|
525
|
+
[sortKeyFieldName]: { S: featureEntityValue },
|
|
526
|
+
};
|
|
527
|
+
return params01;
|
|
528
|
+
});
|
|
529
|
+
const params = {
|
|
530
|
+
RequestItems: {
|
|
531
|
+
[tableFullName]: {
|
|
532
|
+
Keys: [...getArray],
|
|
533
|
+
ConsistentRead: true,
|
|
534
|
+
ProjectionExpression: projectionExpression,
|
|
535
|
+
ExpressionAttributeNames: expressionAttributeNames,
|
|
536
|
+
},
|
|
537
|
+
},
|
|
538
|
+
};
|
|
539
|
+
logging_service_1.LoggingService.log({ batchGetItemParams: params });
|
|
540
|
+
let hasNext = true;
|
|
541
|
+
let params01 = { ...params };
|
|
542
|
+
let returnedItems = [];
|
|
543
|
+
const dynamo = this._mocody_dynamoInit();
|
|
544
|
+
logging_service_1.LoggingService.log({ fetchForDataIds: dataIds });
|
|
545
|
+
while (hasNext) {
|
|
546
|
+
try {
|
|
547
|
+
const { Responses, UnprocessedKeys } = await dynamo.batchGetItem(params01);
|
|
548
|
+
if (Responses) {
|
|
549
|
+
const itemListRaw = Responses[tableFullName];
|
|
550
|
+
if (itemListRaw?.length) {
|
|
551
|
+
const itemList = itemListRaw.map((item) => mocody_utils_1.MocodyUtil.unmarshallToJson(item));
|
|
552
|
+
returnedItems = [...returnedItems, ...itemList];
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
if (UnprocessedKeys && Object.keys(UnprocessedKeys).length) {
|
|
556
|
+
params01 = {
|
|
557
|
+
RequestItems: UnprocessedKeys,
|
|
558
|
+
};
|
|
559
|
+
logging_service_1.LoggingService.log({ dynamoBatchGetParams: params01 });
|
|
560
|
+
}
|
|
561
|
+
else {
|
|
562
|
+
hasNext = false;
|
|
563
|
+
break;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
catch (error) {
|
|
567
|
+
hasNext = false;
|
|
568
|
+
logging_service_1.LoggingService.error(error);
|
|
569
|
+
if (!returnedItems?.length) {
|
|
570
|
+
throw error;
|
|
571
|
+
}
|
|
572
|
+
else {
|
|
573
|
+
break;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
if (returnedItems?.length && withCondition?.length) {
|
|
578
|
+
const returnedItems01 = [];
|
|
579
|
+
returnedItems.forEach((item) => {
|
|
580
|
+
const canInclude = withCondition.every((condition) => item[condition.field] === condition.equals);
|
|
581
|
+
if (canInclude) {
|
|
582
|
+
returnedItems01.push(item);
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
return returnedItems01;
|
|
586
|
+
}
|
|
587
|
+
return returnedItems;
|
|
588
|
+
}
|
|
589
|
+
async mocody_getManyByIndex(paramOption) {
|
|
590
|
+
const result = await this._mocody_getManyBySecondaryIndexPaginateBase({
|
|
591
|
+
paramOption,
|
|
592
|
+
canPaginate: false,
|
|
593
|
+
enableRelationFetch: false,
|
|
594
|
+
});
|
|
595
|
+
if (result?.paginationResults) {
|
|
596
|
+
return result.paginationResults;
|
|
597
|
+
}
|
|
598
|
+
return [];
|
|
599
|
+
}
|
|
600
|
+
async mocody_getManyByIndexPaginate(paramOption) {
|
|
601
|
+
return this._mocody_getManyBySecondaryIndexPaginateBase({
|
|
602
|
+
paramOption,
|
|
603
|
+
canPaginate: true,
|
|
604
|
+
enableRelationFetch: false,
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
async mocody_getManyWithRelation(paramOption) {
|
|
608
|
+
const result = await this._mocody_getManyBySecondaryIndexPaginateBase({
|
|
609
|
+
paramOption,
|
|
610
|
+
canPaginate: false,
|
|
611
|
+
enableRelationFetch: true,
|
|
612
|
+
});
|
|
613
|
+
if (result?.paginationResults) {
|
|
614
|
+
return result.paginationResults;
|
|
615
|
+
}
|
|
616
|
+
return [];
|
|
617
|
+
}
|
|
618
|
+
async mocody_getManyWithRelationPaginate(paramOption) {
|
|
619
|
+
return this._mocody_getManyBySecondaryIndexPaginateBase({
|
|
620
|
+
paramOption,
|
|
621
|
+
canPaginate: true,
|
|
622
|
+
enableRelationFetch: true,
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
async _mocody_getManyBySecondaryIndexPaginateBase({ paramOption, canPaginate, enableRelationFetch, }) {
|
|
626
|
+
const { tableFullName, secondaryIndexOptions, partitionKeyFieldName, sortKeyFieldName, featureEntityValue } = this._mocody_getLocalVariables();
|
|
627
|
+
if (!secondaryIndexOptions?.length) {
|
|
628
|
+
throw this._mocody_createGenericError("Invalid secondary index definitions");
|
|
629
|
+
}
|
|
630
|
+
const paramOption01 = { ...paramOption };
|
|
631
|
+
if (!paramOption01?.indexName) {
|
|
632
|
+
throw this._mocody_createGenericError("Invalid index name input");
|
|
633
|
+
}
|
|
634
|
+
const secondaryIndex = secondaryIndexOptions.find((item) => {
|
|
635
|
+
return item.indexName === paramOption01.indexName;
|
|
636
|
+
});
|
|
637
|
+
if (!secondaryIndex) {
|
|
638
|
+
throw this._mocody_createGenericError("Secondary index not named/defined");
|
|
639
|
+
}
|
|
640
|
+
let projectionFields;
|
|
641
|
+
const fields01 = this._mocody_getProjectionFields({
|
|
642
|
+
fields: paramOption01.fields,
|
|
643
|
+
excludeFields: paramOption01.excludeFields,
|
|
644
|
+
});
|
|
645
|
+
if (canPaginate && fields01?.length) {
|
|
646
|
+
const fieldSet01 = new Set(fields01);
|
|
647
|
+
fieldSet01.add(partitionKeyFieldName);
|
|
648
|
+
projectionFields = Array.from(fieldSet01);
|
|
649
|
+
}
|
|
650
|
+
else {
|
|
651
|
+
projectionFields = fields01;
|
|
652
|
+
}
|
|
653
|
+
let evaluationLimit01;
|
|
654
|
+
let resultLimit01;
|
|
655
|
+
if (paramOption01.limit && util_service_1.UtilService.isNumericInteger(paramOption01.limit)) {
|
|
656
|
+
resultLimit01 = Number(paramOption01.limit);
|
|
657
|
+
}
|
|
658
|
+
if (paramOption01?.pagingParams?.evaluationLimit) {
|
|
659
|
+
evaluationLimit01 = paramOption01?.pagingParams?.evaluationLimit;
|
|
660
|
+
}
|
|
661
|
+
else if (!paramOption01.query && resultLimit01) {
|
|
662
|
+
evaluationLimit01 = resultLimit01;
|
|
663
|
+
}
|
|
664
|
+
const index_PartitionKeyFieldName = secondaryIndex.partitionKeyFieldName;
|
|
665
|
+
const index_SortKeyFieldName = secondaryIndex.sortKeyFieldName;
|
|
666
|
+
const main_partitionAndSortKey = [partitionKeyFieldName, sortKeyFieldName];
|
|
667
|
+
const index_partitionAndSortKey = [index_PartitionKeyFieldName, index_SortKeyFieldName];
|
|
668
|
+
const partitionSortKeyQuery = paramOption01.sortKeyQuery
|
|
669
|
+
? {
|
|
670
|
+
...{ [index_SortKeyFieldName]: paramOption01.sortKeyQuery },
|
|
671
|
+
...{ [index_PartitionKeyFieldName]: paramOption01.partitionKeyValue },
|
|
672
|
+
}
|
|
673
|
+
: { [index_PartitionKeyFieldName]: paramOption01.partitionKeyValue };
|
|
674
|
+
if (!enableRelationFetch) {
|
|
675
|
+
const localVariables = this._mocody_getLocalVariables();
|
|
676
|
+
const hasFeatureEntity = [
|
|
677
|
+
index_PartitionKeyFieldName,
|
|
678
|
+
index_SortKeyFieldName,
|
|
679
|
+
].includes(localVariables.sortKeyFieldName);
|
|
680
|
+
if (!hasFeatureEntity) {
|
|
681
|
+
paramOption01.query = (paramOption01.query || {});
|
|
682
|
+
paramOption01.query = {
|
|
683
|
+
...paramOption01.query,
|
|
684
|
+
...this._mocody_featureEntity_Key_Value,
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
else if (index_PartitionKeyFieldName !== localVariables.sortKeyFieldName) {
|
|
688
|
+
if (localVariables.sortKeyFieldName === index_SortKeyFieldName) {
|
|
689
|
+
partitionSortKeyQuery[index_SortKeyFieldName] = { $eq: localVariables.featureEntityValue };
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
const mainFilter = this._mocody_queryFilter.processQueryFilter({
|
|
694
|
+
queryDefs: partitionSortKeyQuery,
|
|
695
|
+
projectionFields,
|
|
696
|
+
});
|
|
697
|
+
let otherFilterExpression;
|
|
698
|
+
let otherExpressionAttributeValues;
|
|
699
|
+
let otherExpressionAttributeNames;
|
|
700
|
+
if (paramOption01.query) {
|
|
701
|
+
const otherFilter = this._mocody_queryFilter.processQueryFilter({
|
|
702
|
+
queryDefs: paramOption01.query,
|
|
703
|
+
projectionFields: null,
|
|
704
|
+
});
|
|
705
|
+
otherExpressionAttributeValues = otherFilter.expressionAttributeValues;
|
|
706
|
+
otherExpressionAttributeNames = otherFilter.expressionAttributeNames;
|
|
707
|
+
if (otherFilter?.filterExpression?.length && otherFilter?.filterExpression.length > 1) {
|
|
708
|
+
otherFilterExpression = otherFilter.filterExpression;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
const params = {
|
|
712
|
+
TableName: tableFullName,
|
|
713
|
+
IndexName: paramOption01.indexName,
|
|
714
|
+
KeyConditionExpression: mainFilter.filterExpression,
|
|
715
|
+
ExpressionAttributeValues: {
|
|
716
|
+
...otherExpressionAttributeValues,
|
|
717
|
+
...mainFilter.expressionAttributeValues,
|
|
718
|
+
},
|
|
719
|
+
FilterExpression: otherFilterExpression ?? undefined,
|
|
720
|
+
ExpressionAttributeNames: {
|
|
721
|
+
...otherExpressionAttributeNames,
|
|
722
|
+
...mainFilter.expressionAttributeNames,
|
|
723
|
+
},
|
|
724
|
+
};
|
|
725
|
+
const orderDesc = paramOption01?.sort === "desc";
|
|
726
|
+
if (orderDesc) {
|
|
727
|
+
params.ScanIndexForward = false;
|
|
728
|
+
}
|
|
729
|
+
else {
|
|
730
|
+
params.ScanIndexForward = true;
|
|
731
|
+
}
|
|
732
|
+
if (mainFilter.projectionExpressionAttr) {
|
|
733
|
+
params.ProjectionExpression = mainFilter.projectionExpressionAttr;
|
|
734
|
+
}
|
|
735
|
+
let nextPageHash01 = paramOption01?.pagingParams?.nextPageHash;
|
|
736
|
+
if (nextPageHash01 === "undefined") {
|
|
737
|
+
nextPageHash01 = undefined;
|
|
738
|
+
}
|
|
739
|
+
if (nextPageHash01 === "null") {
|
|
740
|
+
nextPageHash01 = undefined;
|
|
741
|
+
}
|
|
742
|
+
const result = await this._mocody_queryScanProcessor.mocody__helperDynamoQueryProcessor({
|
|
743
|
+
dynamoDb: () => this._mocody_dynamoInit(),
|
|
744
|
+
params,
|
|
745
|
+
orderDesc,
|
|
746
|
+
canPaginate,
|
|
747
|
+
tableFullName,
|
|
748
|
+
featureEntityValue,
|
|
749
|
+
main_partitionAndSortKey,
|
|
750
|
+
index_partitionAndSortKey,
|
|
751
|
+
evaluationLimit: evaluationLimit01,
|
|
752
|
+
nextPageHash: nextPageHash01,
|
|
753
|
+
resultLimit: resultLimit01,
|
|
754
|
+
});
|
|
755
|
+
return result;
|
|
756
|
+
}
|
|
757
|
+
async mocody_deleteById({ dataId, withCondition, }) {
|
|
758
|
+
this._mocody_errorHelper.mocody_helper_validateRequiredString({ Del1SortKey: dataId });
|
|
759
|
+
const { tableFullName, partitionKeyFieldName, sortKeyFieldName, featureEntityValue } = this._mocody_getLocalVariables();
|
|
760
|
+
const dataExist = await this.mocody_getOneById({ dataId, withCondition });
|
|
761
|
+
if (!(dataExist && dataExist[partitionKeyFieldName])) {
|
|
762
|
+
throw this._mocody_errorHelper.mocody_helper_createFriendlyError("Record does NOT exists");
|
|
763
|
+
}
|
|
764
|
+
const params = {
|
|
765
|
+
TableName: tableFullName,
|
|
766
|
+
Key: {
|
|
767
|
+
[partitionKeyFieldName]: { S: dataId },
|
|
768
|
+
[sortKeyFieldName]: { S: featureEntityValue },
|
|
769
|
+
},
|
|
770
|
+
};
|
|
771
|
+
try {
|
|
772
|
+
await this._mocody_dynamoInit().deleteItem(params);
|
|
773
|
+
}
|
|
774
|
+
catch (err) {
|
|
775
|
+
if (err && err.code === "ResourceNotFoundException") {
|
|
776
|
+
throw this._mocody_errorHelper.mocody_helper_createFriendlyError("Table not found");
|
|
777
|
+
}
|
|
778
|
+
else if (err && err.code === "ResourceInUseException") {
|
|
779
|
+
throw this._mocody_errorHelper.mocody_helper_createFriendlyError("Table in use");
|
|
780
|
+
}
|
|
781
|
+
else {
|
|
782
|
+
throw err;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
return dataExist;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
exports.DynamoDataOperation = DynamoDataOperation;
|
|
794
789
|
//# sourceMappingURL=dynamo-data-operation.js.map
|