mocody 0.6.8 → 0.7.0
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/index.cjs +393 -362
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +2 -0
- package/package.json +2 -7
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,47 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
CouchDataOperation: () => CouchDataOperation,
|
|
34
|
+
DynamoDataOperation: () => DynamoDataOperation,
|
|
35
|
+
MocodyGenericError: () => MocodyGenericError,
|
|
36
|
+
MocodyInitializerCouch: () => MocodyInitializerCouch,
|
|
37
|
+
MocodyInitializerDynamo: () => MocodyInitializerDynamo,
|
|
38
|
+
MocodyInitializerMongo: () => MocodyInitializerMongo,
|
|
39
|
+
MocodyUtil: () => MocodyUtil,
|
|
40
|
+
MongoDataOperation: () => MongoDataOperation
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(index_exports);
|
|
43
|
+
|
|
44
|
+
// src/helpers/errors.ts
|
|
2
45
|
var MocodyGenericError = class extends Error {
|
|
3
46
|
constructor(message) {
|
|
4
47
|
super(message);
|
|
@@ -34,11 +77,11 @@ var MocodyErrorUtilsServiceBase = class {
|
|
|
34
77
|
var MocodyErrorUtilsService = new MocodyErrorUtilsServiceBase();
|
|
35
78
|
|
|
36
79
|
// src/helpers/mocody-utils.ts
|
|
37
|
-
var
|
|
80
|
+
var import_util_dynamodb = require("@aws-sdk/util-dynamodb");
|
|
38
81
|
|
|
39
82
|
// src/helpers/util-service.ts
|
|
40
|
-
var
|
|
41
|
-
var
|
|
83
|
+
var import_node_crypto = require("crypto");
|
|
84
|
+
var import_nanoid = require("nanoid");
|
|
42
85
|
var UtilServiceBase = class {
|
|
43
86
|
convertHexadecimalToNumber(hexString) {
|
|
44
87
|
return parseInt(hexString, 16);
|
|
@@ -60,7 +103,7 @@ var UtilServiceBase = class {
|
|
|
60
103
|
}
|
|
61
104
|
getRandomString(count) {
|
|
62
105
|
const alphabet = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
63
|
-
const nanoid01 =
|
|
106
|
+
const nanoid01 = (0, import_nanoid.customAlphabet)(alphabet, count);
|
|
64
107
|
return nanoid01();
|
|
65
108
|
}
|
|
66
109
|
camelCaseToSentenceCase(text) {
|
|
@@ -143,7 +186,7 @@ var UtilServiceBase = class {
|
|
|
143
186
|
`${_now.getMinutes()}`.padStart(2, "0"),
|
|
144
187
|
`${_now.getSeconds()}`.padStart(2, "0"),
|
|
145
188
|
"-",
|
|
146
|
-
|
|
189
|
+
(0, import_node_crypto.randomUUID)()
|
|
147
190
|
];
|
|
148
191
|
return key.join("");
|
|
149
192
|
}
|
|
@@ -190,7 +233,7 @@ var UtilServiceBase = class {
|
|
|
190
233
|
}
|
|
191
234
|
groupOneBy(dataList, fn) {
|
|
192
235
|
const aggr = {};
|
|
193
|
-
if (
|
|
236
|
+
if (dataList?.length) {
|
|
194
237
|
dataList.forEach((data) => {
|
|
195
238
|
const groupId = fn(data);
|
|
196
239
|
if (aggr[groupId] === void 0) {
|
|
@@ -202,13 +245,13 @@ var UtilServiceBase = class {
|
|
|
202
245
|
}
|
|
203
246
|
groupBy(dataList, fn) {
|
|
204
247
|
const aggr = {};
|
|
205
|
-
if (
|
|
248
|
+
if (dataList?.length) {
|
|
206
249
|
dataList.forEach((data) => {
|
|
207
250
|
const groupId = fn(data);
|
|
208
251
|
if (!aggr[groupId]) {
|
|
209
252
|
aggr[groupId] = [];
|
|
210
253
|
}
|
|
211
|
-
|
|
254
|
+
aggr[groupId]?.push(data);
|
|
212
255
|
});
|
|
213
256
|
}
|
|
214
257
|
return aggr;
|
|
@@ -274,7 +317,7 @@ var UtilService = new UtilServiceBase();
|
|
|
274
317
|
// src/helpers/mocody-utils.ts
|
|
275
318
|
var MocodyUtilBase = class {
|
|
276
319
|
marshallFromJson(jsonData) {
|
|
277
|
-
const marshalled =
|
|
320
|
+
const marshalled = (0, import_util_dynamodb.marshall)(jsonData, {
|
|
278
321
|
convertClassInstanceToMap: true,
|
|
279
322
|
convertEmptyValues: true,
|
|
280
323
|
removeUndefinedValues: true
|
|
@@ -282,18 +325,18 @@ var MocodyUtilBase = class {
|
|
|
282
325
|
return marshalled;
|
|
283
326
|
}
|
|
284
327
|
unmarshallToJson(dynamoData) {
|
|
285
|
-
return
|
|
328
|
+
return (0, import_util_dynamodb.unmarshall)(dynamoData);
|
|
286
329
|
}
|
|
287
330
|
getProjectionFields({
|
|
288
331
|
excludeFields,
|
|
289
332
|
fields,
|
|
290
333
|
entityFields
|
|
291
334
|
}) {
|
|
292
|
-
if (!
|
|
335
|
+
if (!fields?.length && !excludeFields?.length) {
|
|
293
336
|
return void 0;
|
|
294
337
|
}
|
|
295
|
-
const fields01 =
|
|
296
|
-
const excludeFields01 =
|
|
338
|
+
const fields01 = fields?.length ? Array.from(/* @__PURE__ */ new Set([...fields])) : [];
|
|
339
|
+
const excludeFields01 = excludeFields?.length ? Array.from(/* @__PURE__ */ new Set([...excludeFields])) : [];
|
|
297
340
|
if (!excludeFields01.length) {
|
|
298
341
|
if (fields01.length) {
|
|
299
342
|
return fields01;
|
|
@@ -322,7 +365,7 @@ var MocodyUtilBase = class {
|
|
|
322
365
|
fieldAliases,
|
|
323
366
|
featureEntity
|
|
324
367
|
}) {
|
|
325
|
-
if (
|
|
368
|
+
if (fieldAliases?.length && data && typeof data === "object" && Object.keys(data).length && featureEntity) {
|
|
326
369
|
const data01 = UtilService.convertObjectPlainObject(data);
|
|
327
370
|
fieldAliases.forEach(({ source, dest }) => {
|
|
328
371
|
if (data01[source] !== data01[dest]) {
|
|
@@ -338,7 +381,7 @@ var MocodyUtilBase = class {
|
|
|
338
381
|
fieldAliases,
|
|
339
382
|
featureEntity
|
|
340
383
|
}) {
|
|
341
|
-
if (
|
|
384
|
+
if (fieldAliases?.length && typeof data === "object" && Object.keys(data).length && featureEntity) {
|
|
342
385
|
const data01 = UtilService.convertObjectPlainObject(data);
|
|
343
386
|
fieldAliases.forEach(({ source, dest }) => {
|
|
344
387
|
if (data01[source] !== data01[dest]) {
|
|
@@ -353,21 +396,13 @@ var MocodyUtilBase = class {
|
|
|
353
396
|
var MocodyUtil = new MocodyUtilBase();
|
|
354
397
|
|
|
355
398
|
// src/dynamo/dynamo-initializer.ts
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
var _clientdynamodb = require('@aws-sdk/client-dynamodb');
|
|
365
|
-
var _libdynamodb = require('@aws-sdk/lib-dynamodb');
|
|
366
|
-
var _throat = require('throat'); var _throat2 = _interopRequireDefault(_throat);
|
|
367
|
-
var concurrency = _throat2.default.call(void 0, 1);
|
|
399
|
+
var import_client_dynamodb = require("@aws-sdk/client-dynamodb");
|
|
400
|
+
var import_lib_dynamodb = require("@aws-sdk/lib-dynamodb");
|
|
401
|
+
var import_throat = __toESM(require("throat"), 1);
|
|
402
|
+
var concurrency = (0, import_throat.default)(1);
|
|
368
403
|
var MocodyInitializerDynamo = class {
|
|
369
|
-
|
|
370
|
-
|
|
404
|
+
client;
|
|
405
|
+
_config;
|
|
371
406
|
constructor(inits) {
|
|
372
407
|
this._config = inits;
|
|
373
408
|
}
|
|
@@ -376,38 +411,38 @@ var MocodyInitializerDynamo = class {
|
|
|
376
411
|
}
|
|
377
412
|
async executeStatement(param) {
|
|
378
413
|
const client = await this.getInstance();
|
|
379
|
-
const docClient =
|
|
380
|
-
const command = new
|
|
414
|
+
const docClient = import_lib_dynamodb.DynamoDBDocumentClient.from(client);
|
|
415
|
+
const command = new import_lib_dynamodb.ExecuteStatementCommand(param);
|
|
381
416
|
const response = await docClient.send(command);
|
|
382
417
|
return response;
|
|
383
418
|
}
|
|
384
419
|
async putItem(params) {
|
|
385
420
|
const client = await this.getInstance();
|
|
386
|
-
return await client.send(new
|
|
421
|
+
return await client.send(new import_client_dynamodb.PutItemCommand(params));
|
|
387
422
|
}
|
|
388
423
|
async getItem(params) {
|
|
389
424
|
const client = await this.getInstance();
|
|
390
|
-
return await client.send(new
|
|
425
|
+
return await client.send(new import_client_dynamodb.GetItemCommand(params));
|
|
391
426
|
}
|
|
392
427
|
async transactWriteItems(params) {
|
|
393
428
|
const client = await this.getInstance();
|
|
394
|
-
return await client.send(new
|
|
429
|
+
return await client.send(new import_client_dynamodb.TransactWriteItemsCommand(params));
|
|
395
430
|
}
|
|
396
431
|
async batchWriteItem(params) {
|
|
397
432
|
const client = await this.getInstance();
|
|
398
|
-
return await client.send(new
|
|
433
|
+
return await client.send(new import_client_dynamodb.BatchWriteItemCommand(params));
|
|
399
434
|
}
|
|
400
435
|
async batchGetItem(params) {
|
|
401
436
|
const client = await this.getInstance();
|
|
402
|
-
return await client.send(new
|
|
437
|
+
return await client.send(new import_client_dynamodb.BatchGetItemCommand(params));
|
|
403
438
|
}
|
|
404
439
|
async deleteItem(params) {
|
|
405
440
|
const client = await this.getInstance();
|
|
406
|
-
return await client.send(new
|
|
441
|
+
return await client.send(new import_client_dynamodb.DeleteItemCommand(params));
|
|
407
442
|
}
|
|
408
443
|
async getInstanceBase() {
|
|
409
444
|
if (!this.client) {
|
|
410
|
-
this.client = new
|
|
445
|
+
this.client = new import_client_dynamodb.DynamoDBClient(this._config);
|
|
411
446
|
}
|
|
412
447
|
return await Promise.resolve(this.client);
|
|
413
448
|
}
|
|
@@ -418,11 +453,11 @@ var RepoModel = class {
|
|
|
418
453
|
};
|
|
419
454
|
|
|
420
455
|
// src/dynamo/dynamo-data-operation.ts
|
|
421
|
-
var
|
|
456
|
+
var import_joi2 = __toESM(require("joi"), 1);
|
|
422
457
|
|
|
423
458
|
// src/helpers/base-joi-helper.ts
|
|
424
459
|
function getJoiValidationErrors(err) {
|
|
425
|
-
if (
|
|
460
|
+
if (err?.details?.length) {
|
|
426
461
|
const details = JSON.parse(JSON.stringify(err.details));
|
|
427
462
|
const joiData = details.map((x) => x.message.replace(new RegExp('"', "g"), ""));
|
|
428
463
|
return joiData.join("; ");
|
|
@@ -431,17 +466,17 @@ function getJoiValidationErrors(err) {
|
|
|
431
466
|
}
|
|
432
467
|
|
|
433
468
|
// src/core/base-schema.ts
|
|
434
|
-
|
|
469
|
+
var import_joi = __toESM(require("joi"), 1);
|
|
435
470
|
var coreSchemaDefinition = {
|
|
436
|
-
id:
|
|
437
|
-
featureEntity:
|
|
438
|
-
dangerouslyExpireAt: [
|
|
439
|
-
dangerouslyExpireAtTTL:
|
|
471
|
+
id: import_joi.default.string().required().min(5).max(512),
|
|
472
|
+
featureEntity: import_joi.default.string().required().min(2).max(256),
|
|
473
|
+
dangerouslyExpireAt: [import_joi.default.string().isoDate().strict(false), import_joi.default.any().strip()],
|
|
474
|
+
dangerouslyExpireAtTTL: import_joi.default.any().strip()
|
|
440
475
|
};
|
|
441
476
|
|
|
442
477
|
// src/helpers/logging-service.ts
|
|
443
478
|
var LoggingServiceBase = class {
|
|
444
|
-
|
|
479
|
+
mode;
|
|
445
480
|
constructor() {
|
|
446
481
|
const mode = process.env.MOCODY_DEBUG_MODE || "";
|
|
447
482
|
if (String(mode) === "true") {
|
|
@@ -461,7 +496,7 @@ var LoggingServiceBase = class {
|
|
|
461
496
|
log(message, ...optionalParams) {
|
|
462
497
|
try {
|
|
463
498
|
if (this.mode) {
|
|
464
|
-
if (
|
|
499
|
+
if (optionalParams?.length) {
|
|
465
500
|
console.log(message, optionalParams);
|
|
466
501
|
} else {
|
|
467
502
|
console.log(message);
|
|
@@ -482,20 +517,13 @@ var LoggingServiceBase = class {
|
|
|
482
517
|
var LoggingService = new LoggingServiceBase();
|
|
483
518
|
|
|
484
519
|
// src/dynamo/dynamo-manage-table.ts
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
520
|
+
var import_client_dynamodb2 = require("@aws-sdk/client-dynamodb");
|
|
493
521
|
var DynamoManageTable = class {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
522
|
+
partitionKeyFieldName;
|
|
523
|
+
sortKeyFieldName;
|
|
524
|
+
dynamoDb;
|
|
525
|
+
tableFullName;
|
|
526
|
+
secondaryIndexOptions;
|
|
499
527
|
constructor({ dynamoDb, secondaryIndexOptions, tableFullName, partitionKeyFieldName, sortKeyFieldName }) {
|
|
500
528
|
this.dynamoDb = dynamoDb;
|
|
501
529
|
this.tableFullName = tableFullName;
|
|
@@ -520,8 +548,8 @@ var DynamoManageTable = class {
|
|
|
520
548
|
Limit: 99
|
|
521
549
|
};
|
|
522
550
|
const dynamo = await this._tbl_dynamoDb().getInstance();
|
|
523
|
-
const listOfTables = await dynamo.send(new
|
|
524
|
-
return
|
|
551
|
+
const listOfTables = await dynamo.send(new import_client_dynamodb2.ListTablesCommand(params));
|
|
552
|
+
return listOfTables?.TableNames;
|
|
525
553
|
}
|
|
526
554
|
async mocody_updateTTL({ isEnabled }) {
|
|
527
555
|
const { tableFullName } = this._tbl_getLocalVariables();
|
|
@@ -534,8 +562,8 @@ var DynamoManageTable = class {
|
|
|
534
562
|
}
|
|
535
563
|
};
|
|
536
564
|
const dynamo = await this._tbl_dynamoDb().getInstance();
|
|
537
|
-
const result = await dynamo.send(new
|
|
538
|
-
if (
|
|
565
|
+
const result = await dynamo.send(new import_client_dynamodb2.UpdateTimeToLiveCommand(params));
|
|
566
|
+
if (result?.TimeToLiveSpecification) {
|
|
539
567
|
return result.TimeToLiveSpecification;
|
|
540
568
|
}
|
|
541
569
|
return null;
|
|
@@ -547,13 +575,13 @@ var DynamoManageTable = class {
|
|
|
547
575
|
TableName: tableFullName
|
|
548
576
|
};
|
|
549
577
|
const dynamo = await this._tbl_dynamoDb().getInstance();
|
|
550
|
-
const result = await dynamo.send(new
|
|
551
|
-
if (
|
|
578
|
+
const result = await dynamo.send(new import_client_dynamodb2.DescribeTableCommand(params));
|
|
579
|
+
if (result?.Table?.TableName === tableFullName) {
|
|
552
580
|
return result.Table;
|
|
553
581
|
}
|
|
554
582
|
return null;
|
|
555
583
|
} catch (error) {
|
|
556
|
-
LoggingService.log({ "@allGetTableInfoBase": "", error:
|
|
584
|
+
LoggingService.log({ "@allGetTableInfoBase": "", error: error?.message });
|
|
557
585
|
return null;
|
|
558
586
|
}
|
|
559
587
|
}
|
|
@@ -562,7 +590,7 @@ var DynamoManageTable = class {
|
|
|
562
590
|
if (!result) {
|
|
563
591
|
return false;
|
|
564
592
|
}
|
|
565
|
-
if (
|
|
593
|
+
if (result?.GlobalSecondaryIndexes) {
|
|
566
594
|
}
|
|
567
595
|
return true;
|
|
568
596
|
}
|
|
@@ -576,20 +604,20 @@ var DynamoManageTable = class {
|
|
|
576
604
|
const allIndexNames = [];
|
|
577
605
|
const newSecondaryIndexOptions = [];
|
|
578
606
|
const updateResults = [];
|
|
579
|
-
if (
|
|
580
|
-
|
|
607
|
+
if (existingTableInfo?.GlobalSecondaryIndexes?.length) {
|
|
608
|
+
existingTableInfo?.GlobalSecondaryIndexes.forEach((indexInfo) => {
|
|
581
609
|
if (indexInfo.IndexName) {
|
|
582
610
|
existingIndexNames.push(indexInfo.IndexName);
|
|
583
611
|
}
|
|
584
|
-
})
|
|
612
|
+
});
|
|
585
613
|
}
|
|
586
|
-
|
|
614
|
+
secondaryIndexOptions?.forEach((newIndexInfo) => {
|
|
587
615
|
allIndexNames.push(newIndexInfo.indexName);
|
|
588
616
|
const indexExists = existingIndexNames.includes(newIndexInfo.indexName);
|
|
589
617
|
if (!indexExists) {
|
|
590
618
|
newSecondaryIndexOptions.push(newIndexInfo);
|
|
591
619
|
}
|
|
592
|
-
})
|
|
620
|
+
});
|
|
593
621
|
existingIndexNames.forEach((indexName) => {
|
|
594
622
|
const existsInList = allIndexNames.includes(indexName);
|
|
595
623
|
if (!existsInList) {
|
|
@@ -622,16 +650,16 @@ var DynamoManageTable = class {
|
|
|
622
650
|
const indexName = creationParams.xGlobalSecondaryIndex[0].IndexName;
|
|
623
651
|
params.AttributeDefinitions = [...creationParams.xAttributeDefinitions];
|
|
624
652
|
creationParams.xGlobalSecondaryIndex.forEach((gsi) => {
|
|
625
|
-
|
|
653
|
+
params.GlobalSecondaryIndexUpdates?.push({
|
|
626
654
|
Create: {
|
|
627
655
|
...gsi
|
|
628
656
|
}
|
|
629
|
-
})
|
|
657
|
+
});
|
|
630
658
|
});
|
|
631
659
|
const dynamo = await this._tbl_dynamoDb().getInstance();
|
|
632
|
-
const result = await dynamo.send(new
|
|
633
|
-
if (
|
|
634
|
-
updateResults.push(
|
|
660
|
+
const result = await dynamo.send(new import_client_dynamodb2.UpdateTableCommand(params));
|
|
661
|
+
if (result?.TableDescription) {
|
|
662
|
+
updateResults.push(result?.TableDescription);
|
|
635
663
|
}
|
|
636
664
|
LoggingService.log(
|
|
637
665
|
[
|
|
@@ -658,15 +686,15 @@ var DynamoManageTable = class {
|
|
|
658
686
|
GlobalSecondaryIndexUpdates: []
|
|
659
687
|
};
|
|
660
688
|
indexCount++;
|
|
661
|
-
|
|
689
|
+
params.GlobalSecondaryIndexUpdates?.push({
|
|
662
690
|
Delete: {
|
|
663
691
|
IndexName: indexName
|
|
664
692
|
}
|
|
665
|
-
})
|
|
693
|
+
});
|
|
666
694
|
const dynamo = await this._tbl_dynamoDb().getInstance();
|
|
667
|
-
const result = await dynamo.send(new
|
|
668
|
-
if (
|
|
669
|
-
updateResults.push(
|
|
695
|
+
const result = await dynamo.send(new import_client_dynamodb2.UpdateTableCommand(params));
|
|
696
|
+
if (result?.TableDescription) {
|
|
697
|
+
updateResults.push(result?.TableDescription);
|
|
670
698
|
}
|
|
671
699
|
LoggingService.log(
|
|
672
700
|
[
|
|
@@ -695,7 +723,7 @@ var DynamoManageTable = class {
|
|
|
695
723
|
} catch (error) {
|
|
696
724
|
LoggingService.log({
|
|
697
725
|
"@allCreateGlobalSecondaryIndexBase": "",
|
|
698
|
-
error:
|
|
726
|
+
error: error?.message
|
|
699
727
|
});
|
|
700
728
|
return null;
|
|
701
729
|
}
|
|
@@ -704,7 +732,7 @@ var DynamoManageTable = class {
|
|
|
704
732
|
const { secondaryIndexOptions } = this._tbl_getLocalVariables();
|
|
705
733
|
const existingTableInfo = await this.mocody_tbl_getTableInfo();
|
|
706
734
|
if (existingTableInfo) {
|
|
707
|
-
if (
|
|
735
|
+
if (secondaryIndexOptions?.length) {
|
|
708
736
|
const result01 = await this._allUpdateGlobalSecondaryIndexBase({
|
|
709
737
|
secondaryIndexOptions,
|
|
710
738
|
existingTableInfo
|
|
@@ -720,12 +748,12 @@ var DynamoManageTable = class {
|
|
|
720
748
|
const { secondaryIndexOptions } = this._tbl_getLocalVariables();
|
|
721
749
|
const existingTableInfo = await this.mocody_tbl_getTableInfo();
|
|
722
750
|
if (existingTableInfo) {
|
|
723
|
-
if (
|
|
751
|
+
if (secondaryIndexOptions?.length) {
|
|
724
752
|
await this._allUpdateGlobalSecondaryIndexBase({
|
|
725
753
|
secondaryIndexOptions,
|
|
726
754
|
existingTableInfo
|
|
727
755
|
});
|
|
728
|
-
} else if (
|
|
756
|
+
} else if (existingTableInfo.GlobalSecondaryIndexes?.length) {
|
|
729
757
|
await this._allUpdateGlobalSecondaryIndexBase({
|
|
730
758
|
secondaryIndexOptions: [],
|
|
731
759
|
existingTableInfo
|
|
@@ -753,35 +781,35 @@ var DynamoManageTable = class {
|
|
|
753
781
|
const sortKeyFieldName01 = sortKeyFieldName;
|
|
754
782
|
if (!attributeDefinitionsNameList.includes(partitionKeyFieldName01)) {
|
|
755
783
|
attributeDefinitionsNameList.push(partitionKeyFieldName01);
|
|
756
|
-
|
|
784
|
+
params?.AttributeDefinitions?.push({
|
|
757
785
|
AttributeName: partitionKeyFieldName01,
|
|
758
786
|
AttributeType: dataTypes.partitionKeyDataType
|
|
759
|
-
})
|
|
787
|
+
});
|
|
760
788
|
}
|
|
761
789
|
if (!attributeDefinitionsNameList.includes(sortKeyFieldName01)) {
|
|
762
790
|
attributeDefinitionsNameList.push(sortKeyFieldName01);
|
|
763
|
-
|
|
791
|
+
params?.AttributeDefinitions?.push({
|
|
764
792
|
AttributeName: sortKeyFieldName01,
|
|
765
793
|
AttributeType: dataTypes.sortKeyDataType
|
|
766
|
-
})
|
|
794
|
+
});
|
|
767
795
|
}
|
|
768
796
|
let projectionFields = projectionFieldsInclude || [];
|
|
769
|
-
let projectionType =
|
|
770
|
-
if (
|
|
797
|
+
let projectionType = import_client_dynamodb2.ProjectionType.ALL;
|
|
798
|
+
if (projectionFields?.length) {
|
|
771
799
|
projectionFields = projectionFields.filter((field) => {
|
|
772
800
|
return field !== partitionKeyFieldName01 && field !== sortKeyFieldName01;
|
|
773
801
|
});
|
|
774
802
|
if (projectionFields.length === 0) {
|
|
775
|
-
projectionType =
|
|
803
|
+
projectionType = import_client_dynamodb2.ProjectionType.KEYS_ONLY;
|
|
776
804
|
} else {
|
|
777
|
-
projectionType =
|
|
805
|
+
projectionType = import_client_dynamodb2.ProjectionType.INCLUDE;
|
|
778
806
|
}
|
|
779
807
|
}
|
|
780
|
-
|
|
808
|
+
params.GlobalSecondaryIndexes?.push({
|
|
781
809
|
IndexName: indexName,
|
|
782
810
|
Projection: {
|
|
783
811
|
ProjectionType: projectionType,
|
|
784
|
-
NonKeyAttributes: projectionType ===
|
|
812
|
+
NonKeyAttributes: projectionType === import_client_dynamodb2.ProjectionType.INCLUDE ? projectionFields : void 0
|
|
785
813
|
},
|
|
786
814
|
KeySchema: [
|
|
787
815
|
{
|
|
@@ -793,7 +821,7 @@ var DynamoManageTable = class {
|
|
|
793
821
|
KeyType: "RANGE"
|
|
794
822
|
}
|
|
795
823
|
]
|
|
796
|
-
})
|
|
824
|
+
});
|
|
797
825
|
});
|
|
798
826
|
return {
|
|
799
827
|
xAttributeDefinitions: params.AttributeDefinitions || [],
|
|
@@ -836,16 +864,16 @@ var DynamoManageTable = class {
|
|
|
836
864
|
Value: tableFullName
|
|
837
865
|
}
|
|
838
866
|
];
|
|
839
|
-
if (
|
|
867
|
+
if (secondaryIndexOptions?.length) {
|
|
840
868
|
const creationParams = this._getGlobalSecondaryIndexCreationParams({
|
|
841
869
|
secondaryIndexOptions
|
|
842
870
|
});
|
|
843
|
-
if (
|
|
844
|
-
const existAttrDefNames =
|
|
871
|
+
if (creationParams.xAttributeDefinitions?.length) {
|
|
872
|
+
const existAttrDefNames = params.AttributeDefinitions?.map((def) => def.AttributeName);
|
|
845
873
|
creationParams.xAttributeDefinitions.forEach((def) => {
|
|
846
|
-
const alreadyDefined =
|
|
874
|
+
const alreadyDefined = existAttrDefNames?.includes(def.AttributeName);
|
|
847
875
|
if (!alreadyDefined) {
|
|
848
|
-
|
|
876
|
+
params.AttributeDefinitions?.push(def);
|
|
849
877
|
}
|
|
850
878
|
});
|
|
851
879
|
}
|
|
@@ -855,12 +883,12 @@ var DynamoManageTable = class {
|
|
|
855
883
|
"@allCreateTableBase, table: ": tableFullName
|
|
856
884
|
});
|
|
857
885
|
const dynamo = await this._tbl_dynamoDb().getInstance();
|
|
858
|
-
const result = await dynamo.send(new
|
|
859
|
-
if (
|
|
886
|
+
const result = await dynamo.send(new import_client_dynamodb2.CreateTableCommand(params));
|
|
887
|
+
if (result?.TableDescription) {
|
|
860
888
|
LoggingService.log(
|
|
861
|
-
[`@allCreateTableBase,`, `Created table: '${
|
|
889
|
+
[`@allCreateTableBase,`, `Created table: '${result?.TableDescription.TableName}'`, (/* @__PURE__ */ new Date()).toTimeString()].join(" ")
|
|
862
890
|
);
|
|
863
|
-
return
|
|
891
|
+
return result.TableDescription?.TableName;
|
|
864
892
|
}
|
|
865
893
|
return null;
|
|
866
894
|
}
|
|
@@ -877,9 +905,9 @@ var DynamoManageTable = class {
|
|
|
877
905
|
]
|
|
878
906
|
};
|
|
879
907
|
const dynamo = await this._tbl_dynamoDb().getInstance();
|
|
880
|
-
const result = await dynamo.send(new
|
|
881
|
-
if (
|
|
882
|
-
return
|
|
908
|
+
const result = await dynamo.send(new import_client_dynamodb2.UpdateTableCommand(params));
|
|
909
|
+
if (result?.TableDescription) {
|
|
910
|
+
return result.TableDescription?.TableName;
|
|
883
911
|
}
|
|
884
912
|
return null;
|
|
885
913
|
}
|
|
@@ -936,7 +964,7 @@ var QueryValidatorCheckBase = class {
|
|
|
936
964
|
if (!(conditionValue && typeof conditionValue === "object")) {
|
|
937
965
|
this.queryErrorThrowChecks({ conditionValue, queryType: "$elemMatch" });
|
|
938
966
|
}
|
|
939
|
-
if (!(
|
|
967
|
+
if (!(conditionValue?.$in?.length && Array.isArray(conditionValue.$in))) {
|
|
940
968
|
throw MocodyErrorUtilsService.mocody_helper_createFriendlyError(
|
|
941
969
|
"$elemMatch must have a valid $in query and must be an array of non-zero length"
|
|
942
970
|
);
|
|
@@ -994,10 +1022,10 @@ function getDynamoRandomKeyOrHash(prefix) {
|
|
|
994
1022
|
return [prefix, UtilService.getRandomString(6)].join("").toLowerCase();
|
|
995
1023
|
}
|
|
996
1024
|
var QueryConditionBuilder = class {
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1025
|
+
expressAttrVal;
|
|
1026
|
+
expressAttrName;
|
|
1027
|
+
expressAttrNameInverse;
|
|
1028
|
+
filterExpressionValue01;
|
|
1001
1029
|
constructor() {
|
|
1002
1030
|
this.expressAttrVal = {};
|
|
1003
1031
|
this.expressAttrName = {};
|
|
@@ -1411,7 +1439,7 @@ var DynamoFilterQueryOperation = class {
|
|
|
1411
1439
|
fieldName,
|
|
1412
1440
|
attrValues: conditionValue
|
|
1413
1441
|
});
|
|
1414
|
-
if (
|
|
1442
|
+
if (elemMatchConditions?.length) {
|
|
1415
1443
|
elemMatchConditions.forEach((cond) => {
|
|
1416
1444
|
orConditions.push(cond);
|
|
1417
1445
|
});
|
|
@@ -1492,7 +1520,7 @@ var DynamoFilterQueryOperation = class {
|
|
|
1492
1520
|
queryObject: orQueryObjectOrValue
|
|
1493
1521
|
});
|
|
1494
1522
|
LoggingService.logAsString({ hasMultiField, orQueryCond01 });
|
|
1495
|
-
if (
|
|
1523
|
+
if (orQueryCond01?.queryConditions?.length) {
|
|
1496
1524
|
if (hasMultiField) {
|
|
1497
1525
|
OR_queryMultiConditionsPrivate.push(...orQueryCond01.queryConditions);
|
|
1498
1526
|
} else {
|
|
@@ -1606,25 +1634,25 @@ var DynamoFilterQueryOperation = class {
|
|
|
1606
1634
|
});
|
|
1607
1635
|
let _andfilterExpression = "";
|
|
1608
1636
|
let _orfilterExpression = "";
|
|
1609
|
-
if (
|
|
1637
|
+
if (AND_FilterExpressionArray?.length) {
|
|
1610
1638
|
_andfilterExpression = AND_FilterExpressionArray.join(" AND ").trim();
|
|
1611
1639
|
}
|
|
1612
|
-
if (
|
|
1640
|
+
if (OR_FilterExpressionMultiFieldsArray?.length) {
|
|
1613
1641
|
const subQuery = [];
|
|
1614
1642
|
OR_FilterExpressionMultiFieldsArray.forEach((item01) => {
|
|
1615
1643
|
const val = item01.join(" AND ").trim();
|
|
1616
1644
|
subQuery.push(`(${val})`);
|
|
1617
1645
|
});
|
|
1618
1646
|
_orfilterExpression = [...OR_FilterExpressionArray, ...subQuery].join(" OR ").trim();
|
|
1619
|
-
} else if (
|
|
1647
|
+
} else if (OR_FilterExpressionArray?.length) {
|
|
1620
1648
|
_orfilterExpression = OR_FilterExpressionArray.join(" OR ").trim();
|
|
1621
1649
|
}
|
|
1622
1650
|
let allFilters = [_andfilterExpression, _orfilterExpression].filter((f) => f);
|
|
1623
|
-
if (
|
|
1651
|
+
if (allFilters?.length && allFilters.length > 1) {
|
|
1624
1652
|
allFilters = allFilters.map((f) => `(${f})`);
|
|
1625
1653
|
}
|
|
1626
1654
|
const _filterExpression = allFilters.join(" AND ");
|
|
1627
|
-
if (
|
|
1655
|
+
if (projectionFields?.length && Array.isArray(projectionFields)) {
|
|
1628
1656
|
const _projection_expressionAttributeNames = {};
|
|
1629
1657
|
projectionFields.forEach((field) => {
|
|
1630
1658
|
if (field && typeof field === "string") {
|
|
@@ -1652,8 +1680,8 @@ var DynamoFilterQueryOperation = class {
|
|
|
1652
1680
|
};
|
|
1653
1681
|
|
|
1654
1682
|
// src/dynamo/dynamo-query-scan-processor.ts
|
|
1655
|
-
|
|
1656
|
-
|
|
1683
|
+
var import_client_dynamodb3 = require("@aws-sdk/client-dynamodb");
|
|
1684
|
+
var import_util_dynamodb2 = require("@aws-sdk/util-dynamodb");
|
|
1657
1685
|
var DynamoQueryScanProcessor = class {
|
|
1658
1686
|
//
|
|
1659
1687
|
async mocody__helperDynamoQueryProcessor({
|
|
@@ -1669,8 +1697,8 @@ var DynamoQueryScanProcessor = class {
|
|
|
1669
1697
|
featureEntityValue,
|
|
1670
1698
|
tableFullName
|
|
1671
1699
|
}) {
|
|
1672
|
-
if (
|
|
1673
|
-
const marshalled =
|
|
1700
|
+
if (params?.ExpressionAttributeValues) {
|
|
1701
|
+
const marshalled = (0, import_util_dynamodb2.marshall)(params.ExpressionAttributeValues, {
|
|
1674
1702
|
convertEmptyValues: false,
|
|
1675
1703
|
removeUndefinedValues: true
|
|
1676
1704
|
});
|
|
@@ -1767,10 +1795,10 @@ var DynamoQueryScanProcessor = class {
|
|
|
1767
1795
|
LoggingService.logAsString({ query_start: params01 });
|
|
1768
1796
|
while (hasNext) {
|
|
1769
1797
|
try {
|
|
1770
|
-
const { Items, LastEvaluatedKey } = await dynamoClient.send(new
|
|
1798
|
+
const { Items, LastEvaluatedKey } = await dynamoClient.send(new import_client_dynamodb3.QueryCommand(params01));
|
|
1771
1799
|
params01.ExclusiveStartKey = void 0;
|
|
1772
|
-
itemsLoopedOrderedLength.push(
|
|
1773
|
-
if (
|
|
1800
|
+
itemsLoopedOrderedLength.push(Items?.length || 0);
|
|
1801
|
+
if (Items?.length) {
|
|
1774
1802
|
returnedItems = [...returnedItems, ...Items];
|
|
1775
1803
|
}
|
|
1776
1804
|
LoggingService.log({
|
|
@@ -1825,7 +1853,7 @@ var DynamoQueryScanProcessor = class {
|
|
|
1825
1853
|
break;
|
|
1826
1854
|
}
|
|
1827
1855
|
} catch (error) {
|
|
1828
|
-
if (
|
|
1856
|
+
if (returnedItems?.length) {
|
|
1829
1857
|
outResult.paginationResults = [...returnedItems];
|
|
1830
1858
|
outResult.nextPageHash = void 0;
|
|
1831
1859
|
} else {
|
|
@@ -1849,7 +1877,7 @@ var DynamoQueryScanProcessor = class {
|
|
|
1849
1877
|
return { ...outResult };
|
|
1850
1878
|
}
|
|
1851
1879
|
__unmarshallToJson(items) {
|
|
1852
|
-
if (
|
|
1880
|
+
if (items?.length) {
|
|
1853
1881
|
return items.map((item) => MocodyUtil.unmarshallToJson(item));
|
|
1854
1882
|
}
|
|
1855
1883
|
return items;
|
|
@@ -1885,7 +1913,7 @@ var DynamoQueryScanProcessor = class {
|
|
|
1885
1913
|
return obj;
|
|
1886
1914
|
}
|
|
1887
1915
|
const itemJson = MocodyUtil.unmarshallToJson(lastKeyRawObject);
|
|
1888
|
-
const dataId =
|
|
1916
|
+
const dataId = itemJson?.[partitionKeyFieldName];
|
|
1889
1917
|
if (!dataId) {
|
|
1890
1918
|
return null;
|
|
1891
1919
|
}
|
|
@@ -1994,7 +2022,7 @@ var DynamoQueryPartiqlProcessor = class {
|
|
|
1994
2022
|
}
|
|
1995
2023
|
}
|
|
1996
2024
|
const projectionField01 = (() => {
|
|
1997
|
-
if (
|
|
2025
|
+
if (projectionFields?.length) {
|
|
1998
2026
|
return projectionFields.map((f) => JSON.stringify(f)).join(",").trim();
|
|
1999
2027
|
}
|
|
2000
2028
|
return "*";
|
|
@@ -2004,7 +2032,7 @@ var DynamoQueryPartiqlProcessor = class {
|
|
|
2004
2032
|
if (current_PartitionKeyFieldName) {
|
|
2005
2033
|
}
|
|
2006
2034
|
const statementText = [`SELECT ${projectionField01} FROM ${tableName} WHERE ${current_PartitionKeyFieldName}=?`];
|
|
2007
|
-
if (
|
|
2035
|
+
if (params.subStatement?.length) {
|
|
2008
2036
|
if (!params.subStatement[0].trim().startsWith("AND")) {
|
|
2009
2037
|
statementText.push("AND");
|
|
2010
2038
|
}
|
|
@@ -2041,8 +2069,8 @@ var DynamoQueryPartiqlProcessor = class {
|
|
|
2041
2069
|
try {
|
|
2042
2070
|
const { Items, LastEvaluatedKey, NextToken } = await dynamo.executeStatement(params01);
|
|
2043
2071
|
params01.NextToken = void 0;
|
|
2044
|
-
itemsLoopedOrderedLength.push(
|
|
2045
|
-
if (
|
|
2072
|
+
itemsLoopedOrderedLength.push(Items?.length || 0);
|
|
2073
|
+
if (Items?.length) {
|
|
2046
2074
|
returnedItems = [...returnedItems, ...Items];
|
|
2047
2075
|
}
|
|
2048
2076
|
LoggingService.log({
|
|
@@ -2082,7 +2110,7 @@ var DynamoQueryPartiqlProcessor = class {
|
|
|
2082
2110
|
break;
|
|
2083
2111
|
}
|
|
2084
2112
|
} catch (error) {
|
|
2085
|
-
if (
|
|
2113
|
+
if (returnedItems?.length) {
|
|
2086
2114
|
outResult.paginationResults = [...returnedItems];
|
|
2087
2115
|
outResult.nextPageHash = void 0;
|
|
2088
2116
|
} else {
|
|
@@ -2136,7 +2164,7 @@ var DynamoQueryPartiqlProcessor = class {
|
|
|
2136
2164
|
if (Object.keys(obj).length === fields.length) {
|
|
2137
2165
|
return obj;
|
|
2138
2166
|
}
|
|
2139
|
-
const dataId =
|
|
2167
|
+
const dataId = lastKeyRawObject?.[partitionKeyFieldName];
|
|
2140
2168
|
if (!dataId) {
|
|
2141
2169
|
return null;
|
|
2142
2170
|
}
|
|
@@ -2386,7 +2414,7 @@ var DynamoFilterQueryPartiQlOperation = class {
|
|
|
2386
2414
|
fieldName,
|
|
2387
2415
|
attrParams
|
|
2388
2416
|
}) {
|
|
2389
|
-
if (!(typeof
|
|
2417
|
+
if (!(typeof attrParams?.query === "object" && typeof attrParams?.index === "number" && attrParams?.index >= 0 && attrParams?.path?.length && Array.isArray(attrParams.path))) {
|
|
2390
2418
|
throw MocodyErrorUtilsService.mocody_helper_createFriendlyError(`Invalid attrParams @ filterNestedMatch`);
|
|
2391
2419
|
}
|
|
2392
2420
|
const queryList = [];
|
|
@@ -2513,7 +2541,7 @@ var DynamoFilterQueryPartiQlOperation = class {
|
|
|
2513
2541
|
fieldName,
|
|
2514
2542
|
attrValues: conditionValue
|
|
2515
2543
|
});
|
|
2516
|
-
if (
|
|
2544
|
+
if (elemMatchConditions?.length) {
|
|
2517
2545
|
elemMatchConditions.forEach((cond) => {
|
|
2518
2546
|
orConditions.push(cond);
|
|
2519
2547
|
});
|
|
@@ -2524,7 +2552,7 @@ var DynamoFilterQueryPartiQlOperation = class {
|
|
|
2524
2552
|
fieldName,
|
|
2525
2553
|
attrValues: conditionValue
|
|
2526
2554
|
});
|
|
2527
|
-
if (
|
|
2555
|
+
if (nestedMatchConditions?.length) {
|
|
2528
2556
|
queryConditions.push(...nestedMatchConditions);
|
|
2529
2557
|
}
|
|
2530
2558
|
} else if (conditionKey === "$nestedArrayMatch") {
|
|
@@ -2533,7 +2561,7 @@ var DynamoFilterQueryPartiQlOperation = class {
|
|
|
2533
2561
|
fieldName,
|
|
2534
2562
|
attrParams: conditionValue
|
|
2535
2563
|
});
|
|
2536
|
-
if (
|
|
2564
|
+
if (nestedMatchConditions?.length) {
|
|
2537
2565
|
queryConditions.push(...nestedMatchConditions);
|
|
2538
2566
|
}
|
|
2539
2567
|
} else if (conditionKey === "$notContains") {
|
|
@@ -2607,7 +2635,7 @@ var DynamoFilterQueryPartiQlOperation = class {
|
|
|
2607
2635
|
fieldName,
|
|
2608
2636
|
queryObject: orQueryObjectOrValue
|
|
2609
2637
|
});
|
|
2610
|
-
if (
|
|
2638
|
+
if (orQueryCond01?.queryConditions?.length) {
|
|
2611
2639
|
if (hasMultiField) {
|
|
2612
2640
|
OR_queryMultiConditionsPrivate.push(...orQueryCond01.queryConditions);
|
|
2613
2641
|
} else {
|
|
@@ -2679,7 +2707,7 @@ var DynamoFilterQueryPartiQlOperation = class {
|
|
|
2679
2707
|
LoggingService.logAsString({ out01 });
|
|
2680
2708
|
const subStatement = [];
|
|
2681
2709
|
const subParameter = [];
|
|
2682
|
-
if (
|
|
2710
|
+
if (AND_queryConditions?.length) {
|
|
2683
2711
|
AND_queryConditions.forEach((f, i) => {
|
|
2684
2712
|
if (i !== 0) {
|
|
2685
2713
|
subStatement.push(" AND ");
|
|
@@ -2688,7 +2716,7 @@ var DynamoFilterQueryPartiQlOperation = class {
|
|
|
2688
2716
|
subParameter.push(...f.subParameters);
|
|
2689
2717
|
});
|
|
2690
2718
|
}
|
|
2691
|
-
if (
|
|
2719
|
+
if (OR_queryConditions?.length) {
|
|
2692
2720
|
if (subStatement.length) {
|
|
2693
2721
|
subStatement.push(" AND ");
|
|
2694
2722
|
}
|
|
@@ -2707,7 +2735,7 @@ var DynamoFilterQueryPartiQlOperation = class {
|
|
|
2707
2735
|
subStatement.push(")");
|
|
2708
2736
|
}
|
|
2709
2737
|
}
|
|
2710
|
-
if (
|
|
2738
|
+
if (OR_queryConditions_multiFields?.length) {
|
|
2711
2739
|
subStatement.push("(");
|
|
2712
2740
|
OR_queryConditions_multiFields.forEach((qItem, i) => {
|
|
2713
2741
|
if (i !== 0) {
|
|
@@ -2731,28 +2759,28 @@ var DynamoFilterQueryPartiQlOperation = class {
|
|
|
2731
2759
|
};
|
|
2732
2760
|
|
|
2733
2761
|
// src/dynamo/dynamo-data-operation.ts
|
|
2734
|
-
var DynamoDataOperation =
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2762
|
+
var DynamoDataOperation = class extends RepoModel {
|
|
2763
|
+
_mocody_partitionKeyFieldName = "id";
|
|
2764
|
+
_mocody_sortKeyFieldName = "featureEntity";
|
|
2765
|
+
_mocody_featureEntity_Key_Value;
|
|
2738
2766
|
//
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2767
|
+
_mocody_dynamoDb;
|
|
2768
|
+
_mocody_dataKeyGenerator;
|
|
2769
|
+
_mocody_schema;
|
|
2770
|
+
_mocody_tableFullName;
|
|
2771
|
+
_mocody_strictRequiredFields;
|
|
2772
|
+
_mocody_featureEntityValue;
|
|
2773
|
+
_mocody_secondaryIndexOptions;
|
|
2774
|
+
_mocody_queryFilter;
|
|
2775
|
+
_mocody_queryPartiQlFilter;
|
|
2748
2776
|
//
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2777
|
+
_mocody_queryScanProcessor;
|
|
2778
|
+
_mocody_queryPartiQlProcessor;
|
|
2779
|
+
_mocody_entityFieldsKeySet;
|
|
2752
2780
|
//
|
|
2753
|
-
|
|
2781
|
+
_mocody_fieldAliases;
|
|
2754
2782
|
//
|
|
2755
|
-
|
|
2783
|
+
_mocody_tableManager;
|
|
2756
2784
|
constructor({
|
|
2757
2785
|
schemaDef,
|
|
2758
2786
|
dynamoDbInitializer,
|
|
@@ -2763,7 +2791,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
2763
2791
|
dataKeyGenerator,
|
|
2764
2792
|
fieldAliases
|
|
2765
2793
|
}) {
|
|
2766
|
-
super();
|
|
2794
|
+
super();
|
|
2767
2795
|
this._mocody_dynamoDb = dynamoDbInitializer;
|
|
2768
2796
|
this._mocody_dataKeyGenerator = dataKeyGenerator;
|
|
2769
2797
|
this._mocody_tableFullName = baseTableName;
|
|
@@ -2784,7 +2812,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
2784
2812
|
Object.keys(fullSchemaMapDef).forEach((key) => {
|
|
2785
2813
|
this._mocody_entityFieldsKeySet.add(key);
|
|
2786
2814
|
});
|
|
2787
|
-
this._mocody_schema =
|
|
2815
|
+
this._mocody_schema = import_joi2.default.object().keys(fullSchemaMapDef);
|
|
2788
2816
|
}
|
|
2789
2817
|
mocody_tableManager() {
|
|
2790
2818
|
if (!this._mocody_tableManager) {
|
|
@@ -2832,7 +2860,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
2832
2860
|
_mocody_checkValidateStrictRequiredFields(onDataObj) {
|
|
2833
2861
|
this._mocody_checkValidateMustBeAnObjectDataType(onDataObj);
|
|
2834
2862
|
const { strictRequiredFields } = this._mocody_getLocalVariables();
|
|
2835
|
-
if (
|
|
2863
|
+
if (strictRequiredFields?.length) {
|
|
2836
2864
|
strictRequiredFields.forEach((field) => {
|
|
2837
2865
|
if (onDataObj[field] === null || onDataObj[field] === void 0) {
|
|
2838
2866
|
throw this._mocody_createGenericError(`Strict required field: '${field}', NOT defined`);
|
|
@@ -2847,7 +2875,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
2847
2875
|
item,
|
|
2848
2876
|
withCondition
|
|
2849
2877
|
}) {
|
|
2850
|
-
if (item && typeof item === "object" &&
|
|
2878
|
+
if (item && typeof item === "object" && withCondition?.length) {
|
|
2851
2879
|
const isPassed = withCondition.every(({ field, equals }) => {
|
|
2852
2880
|
return item[field] !== void 0 && item[field] === equals;
|
|
2853
2881
|
});
|
|
@@ -2863,7 +2891,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
2863
2891
|
stripUnknown: true
|
|
2864
2892
|
});
|
|
2865
2893
|
if (error) {
|
|
2866
|
-
const msg =
|
|
2894
|
+
const msg = getJoiValidationErrors(error) ?? "Validation error occured";
|
|
2867
2895
|
throw MocodyErrorUtilsService.mocody_helper_createFriendlyError(msg);
|
|
2868
2896
|
}
|
|
2869
2897
|
const validatedData = MocodyUtil.alignFormatFieldAlias({
|
|
@@ -2879,7 +2907,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
2879
2907
|
return await Promise.resolve({ validatedData });
|
|
2880
2908
|
}
|
|
2881
2909
|
_mocody_formatTTL(fullData) {
|
|
2882
|
-
if (
|
|
2910
|
+
if (fullData?.dangerouslyExpireAt) {
|
|
2883
2911
|
fullData.dangerouslyExpireAtTTL = UtilService.getEpochTime(fullData.dangerouslyExpireAt);
|
|
2884
2912
|
} else {
|
|
2885
2913
|
delete fullData.dangerouslyExpireAtTTL;
|
|
@@ -2913,7 +2941,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
2913
2941
|
const result = { ...validatedData };
|
|
2914
2942
|
return result;
|
|
2915
2943
|
} catch (error) {
|
|
2916
|
-
if (
|
|
2944
|
+
if (error?.name === "ConditionalCheckFailedException") {
|
|
2917
2945
|
throw MocodyErrorUtilsService.mocody_helper_createFriendlyError(`Field, ${partitionKeyFieldName} already exists`);
|
|
2918
2946
|
}
|
|
2919
2947
|
throw error;
|
|
@@ -3002,10 +3030,10 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3002
3030
|
} = this._mocody_getLocalVariables();
|
|
3003
3031
|
MocodyErrorUtilsService.mocody_helper_validateRequiredString({ Update1DataId: dataId });
|
|
3004
3032
|
const dataInDb = await this.mocody_getOneById({ dataId });
|
|
3005
|
-
if (!
|
|
3033
|
+
if (!dataInDb?.[partitionKeyFieldName]) {
|
|
3006
3034
|
throw MocodyErrorUtilsService.mocody_helper_createFriendlyError("Data does NOT exists");
|
|
3007
3035
|
}
|
|
3008
|
-
if (
|
|
3036
|
+
if (dataInDb?.[sortKeyFieldName] !== featureEntityValue) {
|
|
3009
3037
|
throw this._mocody_createGenericError("Record does not exists");
|
|
3010
3038
|
}
|
|
3011
3039
|
const isPassed = this._mocody_withConditionPassed({
|
|
@@ -3118,7 +3146,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3118
3146
|
queryDefs: query01,
|
|
3119
3147
|
projectionFields: void 0
|
|
3120
3148
|
});
|
|
3121
|
-
|
|
3149
|
+
transactData.TransactItems?.push({
|
|
3122
3150
|
Put: {
|
|
3123
3151
|
TableName: item.tableName,
|
|
3124
3152
|
Item: item.data,
|
|
@@ -3126,7 +3154,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3126
3154
|
ExpressionAttributeNames: expressionAttributeNames,
|
|
3127
3155
|
ExpressionAttributeValues: expressionAttributeValues
|
|
3128
3156
|
}
|
|
3129
|
-
})
|
|
3157
|
+
});
|
|
3130
3158
|
} else if (item.kind === "update") {
|
|
3131
3159
|
const query01 = {
|
|
3132
3160
|
[item.partitionKeyFieldName]: { $exists: true }
|
|
@@ -3140,7 +3168,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3140
3168
|
queryDefs: query01,
|
|
3141
3169
|
projectionFields: void 0
|
|
3142
3170
|
});
|
|
3143
|
-
|
|
3171
|
+
transactData.TransactItems?.push({
|
|
3144
3172
|
Put: {
|
|
3145
3173
|
TableName: item.tableName,
|
|
3146
3174
|
Item: item.data,
|
|
@@ -3148,7 +3176,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3148
3176
|
ExpressionAttributeNames: expressionAttributeNames,
|
|
3149
3177
|
ExpressionAttributeValues: expressionAttributeValues
|
|
3150
3178
|
}
|
|
3151
|
-
})
|
|
3179
|
+
});
|
|
3152
3180
|
} else if (item.kind === "delete") {
|
|
3153
3181
|
const query01 = {
|
|
3154
3182
|
[item.partitionKeyFieldName]: { $exists: true }
|
|
@@ -3162,7 +3190,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3162
3190
|
queryDefs: query01,
|
|
3163
3191
|
projectionFields: void 0
|
|
3164
3192
|
});
|
|
3165
|
-
|
|
3193
|
+
transactData.TransactItems?.push({
|
|
3166
3194
|
Delete: {
|
|
3167
3195
|
TableName: item.tableName,
|
|
3168
3196
|
Key: item.keyQuery,
|
|
@@ -3170,7 +3198,9 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3170
3198
|
ExpressionAttributeNames: expressionAttributeNames,
|
|
3171
3199
|
ExpressionAttributeValues: expressionAttributeValues
|
|
3172
3200
|
}
|
|
3173
|
-
})
|
|
3201
|
+
});
|
|
3202
|
+
} else {
|
|
3203
|
+
throw this._mocody_createGenericError("Invalid transaction kind");
|
|
3174
3204
|
}
|
|
3175
3205
|
}
|
|
3176
3206
|
await this._mocody_dynamoInit().transactWriteItems(transactData);
|
|
@@ -3192,20 +3222,20 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3192
3222
|
withCondition
|
|
3193
3223
|
}) {
|
|
3194
3224
|
const dataList = [];
|
|
3195
|
-
if (!
|
|
3225
|
+
if (!dataIds?.length) {
|
|
3196
3226
|
return dataList;
|
|
3197
3227
|
}
|
|
3198
3228
|
dataIds.forEach((dataId) => {
|
|
3199
3229
|
MocodyErrorUtilsService.mocody_helper_validateRequiredString({ BatchGetDataId: dataId });
|
|
3200
3230
|
});
|
|
3201
3231
|
const originalIds = this._mocody_removeDuplicateString(dataIds);
|
|
3202
|
-
if (
|
|
3232
|
+
if (originalIds?.length === 1) {
|
|
3203
3233
|
const result = await this.mocody_getOneById({
|
|
3204
3234
|
dataId: originalIds[0],
|
|
3205
3235
|
withCondition
|
|
3206
3236
|
});
|
|
3207
3237
|
if (result) {
|
|
3208
|
-
if (
|
|
3238
|
+
if (fields?.length) {
|
|
3209
3239
|
const result01 = UtilService.pickFromObject({ dataObject: result, pickKeys: fields });
|
|
3210
3240
|
dataList.push(result01);
|
|
3211
3241
|
} else {
|
|
@@ -3249,9 +3279,9 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3249
3279
|
let projectionExpression;
|
|
3250
3280
|
let expressionAttributeNames;
|
|
3251
3281
|
const fields01 = this._mocody_getProjectionFields({ fields, excludeFields });
|
|
3252
|
-
if (
|
|
3282
|
+
if (fields01?.length) {
|
|
3253
3283
|
const fieldKeys = new Set(fields01);
|
|
3254
|
-
if (
|
|
3284
|
+
if (withCondition?.length) {
|
|
3255
3285
|
withCondition.forEach((condition) => {
|
|
3256
3286
|
fieldKeys.add(condition.field);
|
|
3257
3287
|
});
|
|
@@ -3265,7 +3295,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3265
3295
|
}
|
|
3266
3296
|
}
|
|
3267
3297
|
});
|
|
3268
|
-
if (
|
|
3298
|
+
if (Object.keys(expressionAttributeNames)?.length) {
|
|
3269
3299
|
projectionExpression = Object.keys(expressionAttributeNames).join(",");
|
|
3270
3300
|
} else {
|
|
3271
3301
|
projectionExpression = void 0;
|
|
@@ -3299,7 +3329,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3299
3329
|
const { Responses, UnprocessedKeys } = await dynamo.batchGetItem(params01);
|
|
3300
3330
|
if (Responses) {
|
|
3301
3331
|
const itemListRaw = Responses[tableFullName];
|
|
3302
|
-
if (
|
|
3332
|
+
if (itemListRaw?.length) {
|
|
3303
3333
|
const itemList = itemListRaw.map((item) => MocodyUtil.unmarshallToJson(item));
|
|
3304
3334
|
returnedItems = [...returnedItems, ...itemList];
|
|
3305
3335
|
}
|
|
@@ -3316,14 +3346,14 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3316
3346
|
} catch (error) {
|
|
3317
3347
|
hasNext = false;
|
|
3318
3348
|
LoggingService.error(error);
|
|
3319
|
-
if (!
|
|
3349
|
+
if (!returnedItems?.length) {
|
|
3320
3350
|
throw error;
|
|
3321
3351
|
} else {
|
|
3322
3352
|
break;
|
|
3323
3353
|
}
|
|
3324
3354
|
}
|
|
3325
3355
|
}
|
|
3326
|
-
if (
|
|
3356
|
+
if (returnedItems?.length && withCondition?.length) {
|
|
3327
3357
|
const returnedItems01 = [];
|
|
3328
3358
|
returnedItems.forEach((item) => {
|
|
3329
3359
|
const canInclude = withCondition.every((condition) => item[condition.field] === condition.equals);
|
|
@@ -3341,7 +3371,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3341
3371
|
canPaginate: false,
|
|
3342
3372
|
enableRelationFetch: false
|
|
3343
3373
|
});
|
|
3344
|
-
if (
|
|
3374
|
+
if (result?.paginationResults) {
|
|
3345
3375
|
return result.paginationResults;
|
|
3346
3376
|
}
|
|
3347
3377
|
return [];
|
|
@@ -3359,7 +3389,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3359
3389
|
canPaginate: false,
|
|
3360
3390
|
enableRelationFetch: true
|
|
3361
3391
|
});
|
|
3362
|
-
if (
|
|
3392
|
+
if (result?.paginationResults) {
|
|
3363
3393
|
return result.paginationResults;
|
|
3364
3394
|
}
|
|
3365
3395
|
return [];
|
|
@@ -3394,11 +3424,11 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3394
3424
|
sortKeyFieldName,
|
|
3395
3425
|
featureEntityValue
|
|
3396
3426
|
} = this._mocody_getLocalVariables();
|
|
3397
|
-
if (!
|
|
3427
|
+
if (!secondaryIndexOptions?.length) {
|
|
3398
3428
|
throw this._mocody_createGenericError("Invalid secondary index definitions");
|
|
3399
3429
|
}
|
|
3400
3430
|
const paramOption01 = { ...paramOption };
|
|
3401
|
-
if (!
|
|
3431
|
+
if (!paramOption01?.indexName) {
|
|
3402
3432
|
throw this._mocody_createGenericError("Invalid index name input");
|
|
3403
3433
|
}
|
|
3404
3434
|
const secondaryIndex = secondaryIndexOptions.find((item) => {
|
|
@@ -3414,7 +3444,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3414
3444
|
fields: paramOption01.fields,
|
|
3415
3445
|
excludeFields: paramOption01.excludeFields
|
|
3416
3446
|
});
|
|
3417
|
-
if (canPaginate &&
|
|
3447
|
+
if (canPaginate && fields01?.length) {
|
|
3418
3448
|
const fieldSet01 = new Set(fields01);
|
|
3419
3449
|
fieldSet01.add(partitionKeyFieldName);
|
|
3420
3450
|
projectionFields = Array.from(fieldSet01);
|
|
@@ -3426,8 +3456,8 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3426
3456
|
if (paramOption01.limit && UtilService.isNumericInteger(paramOption01.limit)) {
|
|
3427
3457
|
resultLimit01 = Number(paramOption01.limit);
|
|
3428
3458
|
}
|
|
3429
|
-
if (
|
|
3430
|
-
evaluationLimit01 =
|
|
3459
|
+
if (paramOption01?.pagingParams?.evaluationLimit) {
|
|
3460
|
+
evaluationLimit01 = paramOption01?.pagingParams?.evaluationLimit;
|
|
3431
3461
|
} else if (!paramOption01.query && resultLimit01) {
|
|
3432
3462
|
evaluationLimit01 = resultLimit01;
|
|
3433
3463
|
}
|
|
@@ -3472,7 +3502,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3472
3502
|
});
|
|
3473
3503
|
otherExpressionAttributeValues = otherFilter.expressionAttributeValues;
|
|
3474
3504
|
otherExpressionAttributeNames = otherFilter.expressionAttributeNames;
|
|
3475
|
-
if (
|
|
3505
|
+
if (otherFilter?.filterExpression?.length && otherFilter?.filterExpression.length > 1) {
|
|
3476
3506
|
otherFilterExpression = otherFilter.filterExpression;
|
|
3477
3507
|
}
|
|
3478
3508
|
}
|
|
@@ -3480,7 +3510,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3480
3510
|
TableName: tableFullName,
|
|
3481
3511
|
IndexName: paramOption01.indexName,
|
|
3482
3512
|
KeyConditionExpression: mainFilter.filterExpression,
|
|
3483
|
-
FilterExpression:
|
|
3513
|
+
FilterExpression: otherFilterExpression ?? void 0,
|
|
3484
3514
|
ExpressionAttributeValues: {
|
|
3485
3515
|
...otherExpressionAttributeValues,
|
|
3486
3516
|
...mainFilter.expressionAttributeValues
|
|
@@ -3490,7 +3520,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3490
3520
|
...mainFilter.expressionAttributeNames
|
|
3491
3521
|
}
|
|
3492
3522
|
};
|
|
3493
|
-
const orderDesc =
|
|
3523
|
+
const orderDesc = paramOption01?.sort === "desc";
|
|
3494
3524
|
if (orderDesc) {
|
|
3495
3525
|
params.ScanIndexForward = false;
|
|
3496
3526
|
} else {
|
|
@@ -3499,7 +3529,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3499
3529
|
if (mainFilter.projectionExpressionAttr) {
|
|
3500
3530
|
params.ProjectionExpression = mainFilter.projectionExpressionAttr;
|
|
3501
3531
|
}
|
|
3502
|
-
let nextPageHash01 =
|
|
3532
|
+
let nextPageHash01 = paramOption01?.pagingParams?.nextPageHash;
|
|
3503
3533
|
if (nextPageHash01 === "undefined") {
|
|
3504
3534
|
nextPageHash01 = void 0;
|
|
3505
3535
|
}
|
|
@@ -3534,11 +3564,11 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3534
3564
|
sortKeyFieldName,
|
|
3535
3565
|
featureEntityValue
|
|
3536
3566
|
} = this._mocody_getLocalVariables();
|
|
3537
|
-
if (!
|
|
3567
|
+
if (!secondaryIndexOptions?.length) {
|
|
3538
3568
|
throw this._mocody_createGenericError("Invalid secondary index definitions");
|
|
3539
3569
|
}
|
|
3540
3570
|
const paramOption01 = { ...paramOption };
|
|
3541
|
-
if (!
|
|
3571
|
+
if (!paramOption01?.indexName) {
|
|
3542
3572
|
throw this._mocody_createGenericError("Invalid index name input");
|
|
3543
3573
|
}
|
|
3544
3574
|
const secondaryIndex = secondaryIndexOptions.find((item) => {
|
|
@@ -3554,7 +3584,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3554
3584
|
fields: paramOption01.fields,
|
|
3555
3585
|
excludeFields: paramOption01.excludeFields
|
|
3556
3586
|
});
|
|
3557
|
-
if (canPaginate &&
|
|
3587
|
+
if (canPaginate && fields01?.length) {
|
|
3558
3588
|
const fieldSet01 = new Set(fields01);
|
|
3559
3589
|
fieldSet01.add(partitionKeyFieldName);
|
|
3560
3590
|
projectionFields = Array.from(fieldSet01);
|
|
@@ -3566,8 +3596,8 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3566
3596
|
if (paramOption01.limit && UtilService.isNumericInteger(paramOption01.limit)) {
|
|
3567
3597
|
resultLimit01 = Number(paramOption01.limit);
|
|
3568
3598
|
}
|
|
3569
|
-
if (
|
|
3570
|
-
evaluationLimit01 =
|
|
3599
|
+
if (paramOption01?.pagingParams?.evaluationLimit) {
|
|
3600
|
+
evaluationLimit01 = paramOption01?.pagingParams?.evaluationLimit;
|
|
3571
3601
|
} else if (!paramOption01.query && resultLimit01) {
|
|
3572
3602
|
evaluationLimit01 = resultLimit01;
|
|
3573
3603
|
}
|
|
@@ -3601,7 +3631,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3601
3631
|
queryDefs: partitionSortKeyQuery
|
|
3602
3632
|
});
|
|
3603
3633
|
LoggingService.logAsString({ sortFilter });
|
|
3604
|
-
if (
|
|
3634
|
+
if (sortFilter?.subStatement) {
|
|
3605
3635
|
subStatement.push(sortFilter.subStatement);
|
|
3606
3636
|
subParameter.push(...sortFilter.subParameter);
|
|
3607
3637
|
}
|
|
@@ -3616,7 +3646,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3616
3646
|
subParameter.push(...otherFilter.subParameter);
|
|
3617
3647
|
}
|
|
3618
3648
|
}
|
|
3619
|
-
let nextPageHash01 =
|
|
3649
|
+
let nextPageHash01 = paramOption01?.pagingParams?.nextPageHash;
|
|
3620
3650
|
if (nextPageHash01 === "undefined") {
|
|
3621
3651
|
nextPageHash01 = void 0;
|
|
3622
3652
|
}
|
|
@@ -3626,7 +3656,7 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3626
3656
|
LoggingService.logAsString({ subStatement, subParameter });
|
|
3627
3657
|
const result = await this._mocody_queryPartiQlProcessor.mocody__helperDynamoQueryProcessor({
|
|
3628
3658
|
dynamoDb: () => this._mocody_dynamoInit(),
|
|
3629
|
-
sortOrder:
|
|
3659
|
+
sortOrder: paramOption01?.sort,
|
|
3630
3660
|
indexName: paramOption01.indexName,
|
|
3631
3661
|
current_partitionValue: paramOption01.partitionKeyValue,
|
|
3632
3662
|
params: { subStatement, subParameter },
|
|
@@ -3675,16 +3705,16 @@ var DynamoDataOperation = (_class = class extends RepoModel {
|
|
|
3675
3705
|
}
|
|
3676
3706
|
return dataExist;
|
|
3677
3707
|
}
|
|
3678
|
-
}
|
|
3708
|
+
};
|
|
3679
3709
|
|
|
3680
3710
|
// src/couch/couch-initializer.ts
|
|
3681
|
-
var
|
|
3682
|
-
|
|
3683
|
-
var concurrency2 =
|
|
3711
|
+
var import_nano = __toESM(require("nano"), 1);
|
|
3712
|
+
var import_throat2 = __toESM(require("throat"), 1);
|
|
3713
|
+
var concurrency2 = (0, import_throat2.default)(1);
|
|
3684
3714
|
var MocodyInitializerCouch = class {
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3715
|
+
_databaseInstance;
|
|
3716
|
+
_documentScope;
|
|
3717
|
+
baseConfig;
|
|
3688
3718
|
constructor(baseConfig) {
|
|
3689
3719
|
this.baseConfig = baseConfig;
|
|
3690
3720
|
}
|
|
@@ -3716,7 +3746,7 @@ var MocodyInitializerCouch = class {
|
|
|
3716
3746
|
selector: { ...selector },
|
|
3717
3747
|
fields,
|
|
3718
3748
|
use_index,
|
|
3719
|
-
sort:
|
|
3749
|
+
sort: sort?.length ? sort : void 0,
|
|
3720
3750
|
limit,
|
|
3721
3751
|
skip
|
|
3722
3752
|
// bookmark: paramOption?.pagingParams?.nextPageHash,
|
|
@@ -3728,7 +3758,7 @@ var MocodyInitializerCouch = class {
|
|
|
3728
3758
|
return await db01.get(nativeId);
|
|
3729
3759
|
} catch (error) {
|
|
3730
3760
|
const error01 = error;
|
|
3731
|
-
if (
|
|
3761
|
+
if (error01?.error === "not_found" || error01?.statusCode === 404) {
|
|
3732
3762
|
return null;
|
|
3733
3763
|
}
|
|
3734
3764
|
LoggingService.error(error);
|
|
@@ -3758,8 +3788,8 @@ var MocodyInitializerCouch = class {
|
|
|
3758
3788
|
startkey: featureEntity,
|
|
3759
3789
|
endkey: `${featureEntity}\uFFF0`,
|
|
3760
3790
|
inclusive_end: true,
|
|
3761
|
-
limit:
|
|
3762
|
-
skip:
|
|
3791
|
+
limit: size ?? void 0,
|
|
3792
|
+
skip: skip ?? void 0
|
|
3763
3793
|
});
|
|
3764
3794
|
return data;
|
|
3765
3795
|
}
|
|
@@ -3772,7 +3802,7 @@ var MocodyInitializerCouch = class {
|
|
|
3772
3802
|
const serverScope = await this.getInstance();
|
|
3773
3803
|
const db = serverScope.db.use(this.baseConfig.couchConfig.databaseName);
|
|
3774
3804
|
try {
|
|
3775
|
-
if (
|
|
3805
|
+
if (this.baseConfig?.indexes?.length) {
|
|
3776
3806
|
for (const indexItem of this.baseConfig.indexes) {
|
|
3777
3807
|
await this.createIndex({ ...indexItem, dbx: db });
|
|
3778
3808
|
}
|
|
@@ -3830,18 +3860,18 @@ var MocodyInitializerCouch = class {
|
|
|
3830
3860
|
const pw = encodeURIComponent(password);
|
|
3831
3861
|
const uname = encodeURIComponent(username);
|
|
3832
3862
|
const url = `${protocol}://${uname}:${pw}@${host}:${port}`;
|
|
3833
|
-
this._databaseInstance =
|
|
3863
|
+
this._databaseInstance = (0, import_nano.default)({ url });
|
|
3834
3864
|
} else if (this.baseConfig.authType === "proxy") {
|
|
3835
3865
|
const proxyHeaders = this.baseConfig.couchConfig.proxyHeaders;
|
|
3836
3866
|
const url = `${protocol}://${host}:${port}`;
|
|
3837
|
-
this._databaseInstance =
|
|
3867
|
+
this._databaseInstance = (0, import_nano.default)({
|
|
3838
3868
|
url,
|
|
3839
3869
|
// requestDefaults: { headers: proxyHeaders },
|
|
3840
3870
|
headers: proxyHeaders
|
|
3841
3871
|
});
|
|
3842
3872
|
} else if (this.baseConfig.authType === "cookie") {
|
|
3843
3873
|
const url = `${protocol}://${host}:${port}`;
|
|
3844
|
-
this._databaseInstance =
|
|
3874
|
+
this._databaseInstance = (0, import_nano.default)({ url, cookie: this.baseConfig.couchConfig.cookie });
|
|
3845
3875
|
} else {
|
|
3846
3876
|
throw new MocodyGenericError("Invalid auth type definition");
|
|
3847
3877
|
}
|
|
@@ -3856,7 +3886,7 @@ var SettingDefaults = {
|
|
|
3856
3886
|
};
|
|
3857
3887
|
|
|
3858
3888
|
// src/couch/couch-data-operation.ts
|
|
3859
|
-
|
|
3889
|
+
var import_joi3 = __toESM(require("joi"), 1);
|
|
3860
3890
|
|
|
3861
3891
|
// src/couch/couch-filter-query-operation.ts
|
|
3862
3892
|
var KEY_CONDITION_MAP3 = {
|
|
@@ -4082,7 +4112,7 @@ var CouchFilterQueryOperation = class {
|
|
|
4082
4112
|
fieldName,
|
|
4083
4113
|
attrValues: conditionValue
|
|
4084
4114
|
});
|
|
4085
|
-
if (
|
|
4115
|
+
if (nestedMatchConditions?.length) {
|
|
4086
4116
|
nestedMatchConditions.forEach((_queryCondition) => {
|
|
4087
4117
|
queryConditions.push(_queryCondition);
|
|
4088
4118
|
});
|
|
@@ -4205,17 +4235,17 @@ var CouchFilterQueryOperation = class {
|
|
|
4205
4235
|
}
|
|
4206
4236
|
});
|
|
4207
4237
|
let queryAllConditions = {};
|
|
4208
|
-
if (
|
|
4238
|
+
if (queryMainConditions?.length) {
|
|
4209
4239
|
queryMainConditions.forEach((item1) => {
|
|
4210
4240
|
if (item1) {
|
|
4211
4241
|
queryAllConditions = { ...queryAllConditions, ...item1 };
|
|
4212
4242
|
}
|
|
4213
4243
|
});
|
|
4214
4244
|
}
|
|
4215
|
-
if (
|
|
4245
|
+
if (queryAndConditions?.length) {
|
|
4216
4246
|
queryAllConditions.$and = queryAndConditions;
|
|
4217
4247
|
}
|
|
4218
|
-
if (
|
|
4248
|
+
if (queryOrConditions?.length) {
|
|
4219
4249
|
queryAllConditions.$or = queryOrConditions;
|
|
4220
4250
|
}
|
|
4221
4251
|
return queryAllConditions;
|
|
@@ -4224,11 +4254,11 @@ var CouchFilterQueryOperation = class {
|
|
|
4224
4254
|
|
|
4225
4255
|
// src/couch/couch-manage-table.ts
|
|
4226
4256
|
var CouchManageTable = class {
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4257
|
+
partitionKeyFieldName;
|
|
4258
|
+
sortKeyFieldName;
|
|
4259
|
+
couchDb;
|
|
4260
|
+
tableFullName;
|
|
4261
|
+
secondaryIndexOptions;
|
|
4232
4262
|
constructor({ couchDb, secondaryIndexOptions, tableFullName, partitionKeyFieldName, sortKeyFieldName }) {
|
|
4233
4263
|
this.couchDb = couchDb;
|
|
4234
4264
|
this.tableFullName = tableFullName;
|
|
@@ -4254,10 +4284,10 @@ var CouchManageTable = class {
|
|
|
4254
4284
|
async mocody_clearAllIndexes() {
|
|
4255
4285
|
const indexes = await this._mocody_getInstance().getIndexes();
|
|
4256
4286
|
LoggingService.log({ indexes });
|
|
4257
|
-
if (
|
|
4287
|
+
if (indexes?.indexes?.length) {
|
|
4258
4288
|
const deletedIndexes = [];
|
|
4259
4289
|
for (const index of indexes.indexes) {
|
|
4260
|
-
if (
|
|
4290
|
+
if (index?.type !== "special") {
|
|
4261
4291
|
deletedIndexes.push(index);
|
|
4262
4292
|
await this._mocody_getInstance().deleteIndex({
|
|
4263
4293
|
ddoc: index.ddoc,
|
|
@@ -4281,9 +4311,9 @@ var CouchManageTable = class {
|
|
|
4281
4311
|
}
|
|
4282
4312
|
async mocody_createDefinedIndexes() {
|
|
4283
4313
|
const results = [];
|
|
4284
|
-
if (
|
|
4314
|
+
if (this.secondaryIndexOptions?.length) {
|
|
4285
4315
|
for (const indexOption of this.secondaryIndexOptions) {
|
|
4286
|
-
if (
|
|
4316
|
+
if (indexOption?.indexName) {
|
|
4287
4317
|
const resultData = await this.mocody_createIndex({
|
|
4288
4318
|
fields: [indexOption.partitionKeyFieldName, indexOption.sortKeyFieldName],
|
|
4289
4319
|
indexName: indexOption.indexName
|
|
@@ -4298,24 +4328,24 @@ var CouchManageTable = class {
|
|
|
4298
4328
|
};
|
|
4299
4329
|
|
|
4300
4330
|
// src/couch/couch-data-operation.ts
|
|
4301
|
-
var CouchDataOperation =
|
|
4302
|
-
|
|
4303
|
-
|
|
4331
|
+
var CouchDataOperation = class extends RepoModel {
|
|
4332
|
+
_mocody_partitionKeyFieldName = "id";
|
|
4333
|
+
_mocody_sortKeyFieldName = "featureEntity";
|
|
4304
4334
|
//
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4335
|
+
_mocody_operationNotSuccessful = "Operation Not Successful";
|
|
4336
|
+
_mocody_entityFieldsKeySet;
|
|
4337
|
+
_mocody_couchDb;
|
|
4338
|
+
_mocody_dataKeyGenerator;
|
|
4339
|
+
_mocody_schema;
|
|
4340
|
+
_mocody_tableFullName;
|
|
4341
|
+
_mocody_strictRequiredFields;
|
|
4342
|
+
_mocody_featureEntityValue;
|
|
4343
|
+
_mocody_secondaryIndexOptions;
|
|
4344
|
+
_mocody_filterQueryOperation = new CouchFilterQueryOperation();
|
|
4315
4345
|
//
|
|
4316
|
-
|
|
4346
|
+
_mocody_fieldAliases;
|
|
4317
4347
|
//
|
|
4318
|
-
|
|
4348
|
+
_mocody_tableManager;
|
|
4319
4349
|
constructor({
|
|
4320
4350
|
schemaDef,
|
|
4321
4351
|
couchDbInitializer,
|
|
@@ -4326,7 +4356,7 @@ var CouchDataOperation = (_class2 = class extends RepoModel {
|
|
|
4326
4356
|
dataKeyGenerator,
|
|
4327
4357
|
fieldAliases
|
|
4328
4358
|
}) {
|
|
4329
|
-
super();
|
|
4359
|
+
super();
|
|
4330
4360
|
this._mocody_couchDb = couchDbInitializer;
|
|
4331
4361
|
this._mocody_dataKeyGenerator = dataKeyGenerator;
|
|
4332
4362
|
this._mocody_tableFullName = baseTableName;
|
|
@@ -4342,9 +4372,9 @@ var CouchDataOperation = (_class2 = class extends RepoModel {
|
|
|
4342
4372
|
Object.keys(fullSchemaMapDef).forEach((key) => {
|
|
4343
4373
|
this._mocody_entityFieldsKeySet.add(key);
|
|
4344
4374
|
});
|
|
4345
|
-
this._mocody_schema =
|
|
4375
|
+
this._mocody_schema = import_joi3.default.object().keys({
|
|
4346
4376
|
...fullSchemaMapDef,
|
|
4347
|
-
_id:
|
|
4377
|
+
_id: import_joi3.default.string().required().min(5).max(512)
|
|
4348
4378
|
});
|
|
4349
4379
|
}
|
|
4350
4380
|
mocody_tableManager() {
|
|
@@ -4394,7 +4424,7 @@ var CouchDataOperation = (_class2 = class extends RepoModel {
|
|
|
4394
4424
|
if (dataObj && typeof dataObj === "object" && this._mocody_entityFieldsKeySet.size > 0) {
|
|
4395
4425
|
Object.entries({ ...dataObj }).forEach(([key, value]) => {
|
|
4396
4426
|
if (this._mocody_entityFieldsKeySet.has(key)) {
|
|
4397
|
-
if (
|
|
4427
|
+
if (excludeFields?.length) {
|
|
4398
4428
|
if (!excludeFields.includes(key)) {
|
|
4399
4429
|
returnData[key] = value;
|
|
4400
4430
|
}
|
|
@@ -4422,7 +4452,7 @@ var CouchDataOperation = (_class2 = class extends RepoModel {
|
|
|
4422
4452
|
item,
|
|
4423
4453
|
withCondition
|
|
4424
4454
|
}) {
|
|
4425
|
-
if (item && typeof item === "object" &&
|
|
4455
|
+
if (item && typeof item === "object" && withCondition?.length) {
|
|
4426
4456
|
const isPassed = withCondition.every(({ field, equals }) => {
|
|
4427
4457
|
return item[field] !== void 0 && item[field] === equals;
|
|
4428
4458
|
});
|
|
@@ -4438,7 +4468,7 @@ var CouchDataOperation = (_class2 = class extends RepoModel {
|
|
|
4438
4468
|
_mocody_checkValidateStrictRequiredFields(onDataObj) {
|
|
4439
4469
|
this._mocody_checkValidateMustBeAnObjectDataType(onDataObj);
|
|
4440
4470
|
const { strictRequiredFields } = this._mocody_getLocalVariables();
|
|
4441
|
-
if (
|
|
4471
|
+
if (strictRequiredFields?.length) {
|
|
4442
4472
|
strictRequiredFields.forEach((field) => {
|
|
4443
4473
|
if (onDataObj[field] === null || onDataObj[field] === void 0) {
|
|
4444
4474
|
throw this._mocody_createGenericError(`Strict required field: '${field}', NOT defined`);
|
|
@@ -4454,7 +4484,7 @@ var CouchDataOperation = (_class2 = class extends RepoModel {
|
|
|
4454
4484
|
stripUnknown: true
|
|
4455
4485
|
});
|
|
4456
4486
|
if (error) {
|
|
4457
|
-
const msg =
|
|
4487
|
+
const msg = getJoiValidationErrors(error) ?? "Validation error occured";
|
|
4458
4488
|
throw MocodyErrorUtilsService.mocody_helper_createFriendlyError(msg);
|
|
4459
4489
|
}
|
|
4460
4490
|
const validatedData = MocodyUtil.alignFormatFieldAlias({
|
|
@@ -4523,12 +4553,12 @@ var CouchDataOperation = (_class2 = class extends RepoModel {
|
|
|
4523
4553
|
skip
|
|
4524
4554
|
});
|
|
4525
4555
|
const dataList = [];
|
|
4526
|
-
|
|
4527
|
-
if (
|
|
4556
|
+
data?.rows?.forEach((item) => {
|
|
4557
|
+
if (item?.doc?.featureEntity === this._mocody_featureEntityValue) {
|
|
4528
4558
|
const doc = this._mocody_stripNonRequiredOutputData({ dataObj: item.doc });
|
|
4529
4559
|
dataList.push(doc);
|
|
4530
4560
|
}
|
|
4531
|
-
})
|
|
4561
|
+
});
|
|
4532
4562
|
return dataList;
|
|
4533
4563
|
}
|
|
4534
4564
|
async mocody_getOneById({
|
|
@@ -4538,7 +4568,7 @@ var CouchDataOperation = (_class2 = class extends RepoModel {
|
|
|
4538
4568
|
MocodyErrorUtilsService.mocody_helper_validateRequiredString({ dataId });
|
|
4539
4569
|
const nativeId = this._mocody_getNativePouchId(dataId);
|
|
4540
4570
|
const dataInDb = await this._mocody_couchDbInstance().getById({ nativeId });
|
|
4541
|
-
if (!(
|
|
4571
|
+
if (!(dataInDb?.id === dataId && dataInDb.featureEntity === this._mocody_featureEntityValue)) {
|
|
4542
4572
|
return null;
|
|
4543
4573
|
}
|
|
4544
4574
|
const passed = this._mocody_withConditionPassed({ item: dataInDb, withCondition });
|
|
@@ -4555,7 +4585,7 @@ var CouchDataOperation = (_class2 = class extends RepoModel {
|
|
|
4555
4585
|
MocodyErrorUtilsService.mocody_helper_validateRequiredString({ dataId });
|
|
4556
4586
|
const nativeId = this._mocody_getNativePouchId(dataId);
|
|
4557
4587
|
const dataInDb = await this._mocody_couchDbInstance().getById({ nativeId });
|
|
4558
|
-
if (!(
|
|
4588
|
+
if (!(dataInDb?.id === dataId && dataInDb.featureEntity === this._mocody_featureEntityValue && dataInDb._rev)) {
|
|
4559
4589
|
throw this._mocody_createGenericError("Record does not exists");
|
|
4560
4590
|
}
|
|
4561
4591
|
const passed = this._mocody_withConditionPassed({ item: dataInDb, withCondition });
|
|
@@ -4603,20 +4633,20 @@ var CouchDataOperation = (_class2 = class extends RepoModel {
|
|
|
4603
4633
|
withCondition
|
|
4604
4634
|
}) {
|
|
4605
4635
|
const dataList = [];
|
|
4606
|
-
if (!
|
|
4636
|
+
if (!dataIds?.length) {
|
|
4607
4637
|
return dataList;
|
|
4608
4638
|
}
|
|
4609
4639
|
dataIds.forEach((dataId) => {
|
|
4610
4640
|
MocodyErrorUtilsService.mocody_helper_validateRequiredString({ BatchGetDataId: dataId });
|
|
4611
4641
|
});
|
|
4612
4642
|
const uniqueIds = this._mocody_removeDuplicateString(dataIds);
|
|
4613
|
-
if (
|
|
4643
|
+
if (uniqueIds?.length === 1) {
|
|
4614
4644
|
const result = await this.mocody_getOneById({
|
|
4615
4645
|
dataId: uniqueIds[0],
|
|
4616
4646
|
withCondition
|
|
4617
4647
|
});
|
|
4618
4648
|
if (result) {
|
|
4619
|
-
if (
|
|
4649
|
+
if (fields?.length) {
|
|
4620
4650
|
const result01 = UtilService.pickFromObject({ dataObject: result, pickKeys: fields });
|
|
4621
4651
|
dataList.push(result01);
|
|
4622
4652
|
} else {
|
|
@@ -4628,9 +4658,9 @@ var CouchDataOperation = (_class2 = class extends RepoModel {
|
|
|
4628
4658
|
const nativeIds = uniqueIds.map((id) => this._mocody_getNativePouchId(id));
|
|
4629
4659
|
const data = await this._mocody_couchDbInstance().getManyByIds({ nativeIds });
|
|
4630
4660
|
const fieldKeys = this._mocody_getProjectionFields({ fields, excludeFields });
|
|
4631
|
-
if (
|
|
4632
|
-
|
|
4633
|
-
if (
|
|
4661
|
+
if (withCondition?.length) {
|
|
4662
|
+
data?.rows?.forEach((item) => {
|
|
4663
|
+
if (item?.doc?.featureEntity === this._mocody_featureEntityValue) {
|
|
4634
4664
|
const passed = this._mocody_withConditionPassed({ item: item.doc, withCondition });
|
|
4635
4665
|
if (passed) {
|
|
4636
4666
|
const k = this._mocody_stripNonRequiredOutputData({
|
|
@@ -4640,17 +4670,17 @@ var CouchDataOperation = (_class2 = class extends RepoModel {
|
|
|
4640
4670
|
dataList.push(k);
|
|
4641
4671
|
}
|
|
4642
4672
|
}
|
|
4643
|
-
})
|
|
4673
|
+
});
|
|
4644
4674
|
} else {
|
|
4645
|
-
|
|
4646
|
-
if (
|
|
4675
|
+
data?.rows?.forEach((item) => {
|
|
4676
|
+
if (item?.doc?.featureEntity === this._mocody_featureEntityValue) {
|
|
4647
4677
|
const k = this._mocody_stripNonRequiredOutputData({
|
|
4648
4678
|
dataObj: item.doc,
|
|
4649
4679
|
excludeFields: fieldKeys
|
|
4650
4680
|
});
|
|
4651
4681
|
dataList.push(k);
|
|
4652
4682
|
}
|
|
4653
|
-
})
|
|
4683
|
+
});
|
|
4654
4684
|
}
|
|
4655
4685
|
return dataList;
|
|
4656
4686
|
}
|
|
@@ -4660,7 +4690,7 @@ var CouchDataOperation = (_class2 = class extends RepoModel {
|
|
|
4660
4690
|
canPaginate: false,
|
|
4661
4691
|
enableRelationFetch: false
|
|
4662
4692
|
});
|
|
4663
|
-
if (
|
|
4693
|
+
if (result?.paginationResults?.length) {
|
|
4664
4694
|
return result.paginationResults;
|
|
4665
4695
|
}
|
|
4666
4696
|
return [];
|
|
@@ -4678,7 +4708,7 @@ var CouchDataOperation = (_class2 = class extends RepoModel {
|
|
|
4678
4708
|
canPaginate: false,
|
|
4679
4709
|
enableRelationFetch: true
|
|
4680
4710
|
});
|
|
4681
|
-
if (
|
|
4711
|
+
if (result?.paginationResults) {
|
|
4682
4712
|
return result.paginationResults;
|
|
4683
4713
|
}
|
|
4684
4714
|
return [];
|
|
@@ -4696,10 +4726,10 @@ var CouchDataOperation = (_class2 = class extends RepoModel {
|
|
|
4696
4726
|
enableRelationFetch
|
|
4697
4727
|
}) {
|
|
4698
4728
|
const { secondaryIndexOptions } = this._mocody_getLocalVariables();
|
|
4699
|
-
if (!
|
|
4729
|
+
if (!secondaryIndexOptions?.length) {
|
|
4700
4730
|
throw this._mocody_createGenericError("Invalid secondary index definitions");
|
|
4701
4731
|
}
|
|
4702
|
-
if (!
|
|
4732
|
+
if (!paramOption?.indexName) {
|
|
4703
4733
|
throw this._mocody_createGenericError("Invalid index name input");
|
|
4704
4734
|
}
|
|
4705
4735
|
const secondaryIndex = secondaryIndexOptions.find((item) => {
|
|
@@ -4769,7 +4799,7 @@ var CouchDataOperation = (_class2 = class extends RepoModel {
|
|
|
4769
4799
|
fields: paramOption.fields,
|
|
4770
4800
|
excludeFields: paramOption.excludeFields
|
|
4771
4801
|
});
|
|
4772
|
-
if (
|
|
4802
|
+
if (fieldKeys?.length) {
|
|
4773
4803
|
projection = this._mocody_removeDuplicateString(fieldKeys);
|
|
4774
4804
|
}
|
|
4775
4805
|
let nextPageHash;
|
|
@@ -4786,7 +4816,7 @@ var CouchDataOperation = (_class2 = class extends RepoModel {
|
|
|
4786
4816
|
pagingOptions.limit = Number(paramOption.limit);
|
|
4787
4817
|
}
|
|
4788
4818
|
try {
|
|
4789
|
-
const nextPageHash01 =
|
|
4819
|
+
const nextPageHash01 = paramOption?.pagingParams?.nextPageHash;
|
|
4790
4820
|
if (nextPageHash01) {
|
|
4791
4821
|
const param01 = JSON.parse(UtilService.decodeStringFromBase64(nextPageHash01));
|
|
4792
4822
|
if (param01.limit) {
|
|
@@ -4797,7 +4827,7 @@ var CouchDataOperation = (_class2 = class extends RepoModel {
|
|
|
4797
4827
|
}
|
|
4798
4828
|
}
|
|
4799
4829
|
} catch (error) {
|
|
4800
|
-
LoggingService.log(
|
|
4830
|
+
LoggingService.log(error?.message);
|
|
4801
4831
|
}
|
|
4802
4832
|
moreFindOption.limit = pagingOptions.limit;
|
|
4803
4833
|
const skipValue = pagingOptions.limit * (pagingOptions.pageNo || 0);
|
|
@@ -4814,13 +4844,13 @@ var CouchDataOperation = (_class2 = class extends RepoModel {
|
|
|
4814
4844
|
selector: { ...queryDefDataOrdered },
|
|
4815
4845
|
fields: projection,
|
|
4816
4846
|
use_index: paramOption.indexName,
|
|
4817
|
-
sort:
|
|
4847
|
+
sort: sort01?.length ? sort01 : void 0,
|
|
4818
4848
|
limit: moreFindOption.limit,
|
|
4819
4849
|
skip: moreFindOption.skip
|
|
4820
4850
|
});
|
|
4821
|
-
const results =
|
|
4851
|
+
const results = data?.docs?.map((item) => {
|
|
4822
4852
|
return this._mocody_stripNonRequiredOutputData({ dataObj: item });
|
|
4823
|
-
})
|
|
4853
|
+
});
|
|
4824
4854
|
if (canPaginate && results.length && moreFindOption.limit && results.length >= moreFindOption.limit) {
|
|
4825
4855
|
pagingOptions.pageNo = pagingOptions.pageNo + 1;
|
|
4826
4856
|
nextPageHash = UtilService.encodeStringToBase64(JSON.stringify(pagingOptions));
|
|
@@ -4836,7 +4866,7 @@ var CouchDataOperation = (_class2 = class extends RepoModel {
|
|
|
4836
4866
|
}) {
|
|
4837
4867
|
const nativeId = this._mocody_getNativePouchId(dataId);
|
|
4838
4868
|
const dataInDb = await this._mocody_couchDbInstance().getById({ nativeId });
|
|
4839
|
-
if (!(
|
|
4869
|
+
if (!(dataInDb?.id === dataId && dataInDb.featureEntity === this._mocody_featureEntityValue)) {
|
|
4840
4870
|
throw this._mocody_createGenericError("Record does not exists");
|
|
4841
4871
|
}
|
|
4842
4872
|
const passed = this._mocody_withConditionPassed({ item: dataInDb, withCondition });
|
|
@@ -4849,21 +4879,21 @@ var CouchDataOperation = (_class2 = class extends RepoModel {
|
|
|
4849
4879
|
}
|
|
4850
4880
|
return this._mocody_stripNonRequiredOutputData({ dataObj: dataInDb });
|
|
4851
4881
|
}
|
|
4852
|
-
}
|
|
4882
|
+
};
|
|
4853
4883
|
|
|
4854
4884
|
// src/mongo/mongo-initializer.ts
|
|
4855
|
-
var
|
|
4856
|
-
|
|
4857
|
-
var concurrency3 =
|
|
4885
|
+
var import_mongodb = require("mongodb");
|
|
4886
|
+
var import_throat3 = __toESM(require("throat"), 1);
|
|
4887
|
+
var concurrency3 = (0, import_throat3.default)(1);
|
|
4858
4888
|
var MocodyInitializerMongo = class {
|
|
4859
|
-
|
|
4860
|
-
|
|
4889
|
+
_mongoClient;
|
|
4890
|
+
_inits;
|
|
4861
4891
|
constructor(inits) {
|
|
4862
4892
|
this._inits = inits;
|
|
4863
4893
|
}
|
|
4864
4894
|
async getInstance() {
|
|
4865
4895
|
if (!this._mongoClient) {
|
|
4866
|
-
this._mongoClient = new
|
|
4896
|
+
this._mongoClient = new import_mongodb.MongoClient(this._inits.uri, this._inits.options);
|
|
4867
4897
|
await this._mongoClient.connect();
|
|
4868
4898
|
}
|
|
4869
4899
|
return this._mongoClient;
|
|
@@ -4886,7 +4916,7 @@ var MocodyInitializerMongo = class {
|
|
|
4886
4916
|
};
|
|
4887
4917
|
|
|
4888
4918
|
// src/mongo/mongo-data-operation.ts
|
|
4889
|
-
|
|
4919
|
+
var import_joi4 = __toESM(require("joi"), 1);
|
|
4890
4920
|
|
|
4891
4921
|
// src/mongo/mongo-filter-query-operation.ts
|
|
4892
4922
|
var KEY_CONDITION_MAP4 = {
|
|
@@ -5106,7 +5136,7 @@ var MongoFilterQueryOperation = class {
|
|
|
5106
5136
|
fieldName,
|
|
5107
5137
|
attrValues: conditionValue
|
|
5108
5138
|
});
|
|
5109
|
-
if (
|
|
5139
|
+
if (nestedMatchConditions?.length) {
|
|
5110
5140
|
queryConditionsAdvanced.push(...nestedMatchConditions);
|
|
5111
5141
|
}
|
|
5112
5142
|
} else if (conditionKey === "$exists") {
|
|
@@ -5165,7 +5195,7 @@ var MongoFilterQueryOperation = class {
|
|
|
5165
5195
|
fieldName,
|
|
5166
5196
|
queryObject: orQueryObjectOrValue
|
|
5167
5197
|
});
|
|
5168
|
-
if (
|
|
5198
|
+
if (orQueryCond01?.length) {
|
|
5169
5199
|
if (orQueryCond01.length > 1) {
|
|
5170
5200
|
queryAndCondition_Inside_Or.push(orQueryCond01);
|
|
5171
5201
|
} else {
|
|
@@ -5223,21 +5253,21 @@ var MongoFilterQueryOperation = class {
|
|
|
5223
5253
|
}
|
|
5224
5254
|
});
|
|
5225
5255
|
let queryAllConditions = {};
|
|
5226
|
-
if (
|
|
5256
|
+
if (queryMainConditions?.length) {
|
|
5227
5257
|
queryMainConditions.forEach((item1) => {
|
|
5228
5258
|
if (item1) {
|
|
5229
5259
|
queryAllConditions = { ...queryAllConditions, ...item1 };
|
|
5230
5260
|
}
|
|
5231
5261
|
});
|
|
5232
5262
|
}
|
|
5233
|
-
if (
|
|
5263
|
+
if (queryAndConditions?.length) {
|
|
5234
5264
|
queryAllConditions.$and = queryAndConditions;
|
|
5235
5265
|
}
|
|
5236
|
-
if (
|
|
5266
|
+
if (queryOrConditions?.length) {
|
|
5237
5267
|
queryAllConditions.$or = queryOrConditions;
|
|
5238
5268
|
}
|
|
5239
|
-
if (
|
|
5240
|
-
if (!
|
|
5269
|
+
if (queryAndCondition_Inside_Or?.length) {
|
|
5270
|
+
if (!queryAllConditions?.$or?.length) {
|
|
5241
5271
|
queryAllConditions.$or = [];
|
|
5242
5272
|
}
|
|
5243
5273
|
queryAndCondition_Inside_Or.forEach((query01) => {
|
|
@@ -5251,11 +5281,11 @@ var MongoFilterQueryOperation = class {
|
|
|
5251
5281
|
|
|
5252
5282
|
// src/mongo/mongo-table-manager.ts
|
|
5253
5283
|
var MongoManageTable = class {
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5284
|
+
partitionKeyFieldName;
|
|
5285
|
+
sortKeyFieldName;
|
|
5286
|
+
mongoDb;
|
|
5287
|
+
tableFullName;
|
|
5288
|
+
secondaryIndexOptions;
|
|
5259
5289
|
constructor({ mongoDb, secondaryIndexOptions, tableFullName, partitionKeyFieldName, sortKeyFieldName }) {
|
|
5260
5290
|
this.mongoDb = mongoDb;
|
|
5261
5291
|
this.tableFullName = tableFullName;
|
|
@@ -5309,7 +5339,7 @@ var MongoManageTable = class {
|
|
|
5309
5339
|
}
|
|
5310
5340
|
async mocody_createDefinedIndexes() {
|
|
5311
5341
|
const results = [];
|
|
5312
|
-
if (
|
|
5342
|
+
if (this.secondaryIndexOptions?.length) {
|
|
5313
5343
|
for (const indexOption of this.secondaryIndexOptions) {
|
|
5314
5344
|
if (indexOption.indexName) {
|
|
5315
5345
|
const resultData = await this.mocody_createIndex({
|
|
@@ -5326,25 +5356,25 @@ var MongoManageTable = class {
|
|
|
5326
5356
|
};
|
|
5327
5357
|
|
|
5328
5358
|
// src/mongo/mongo-data-operation.ts
|
|
5329
|
-
|
|
5330
|
-
var MongoDataOperation =
|
|
5331
|
-
|
|
5332
|
-
|
|
5359
|
+
var import_mongodb2 = require("mongodb");
|
|
5360
|
+
var MongoDataOperation = class extends RepoModel {
|
|
5361
|
+
_mocody_partitionKeyFieldName = "id";
|
|
5362
|
+
_mocody_sortKeyFieldName = "featureEntity";
|
|
5333
5363
|
//
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
|
|
5338
|
-
|
|
5339
|
-
|
|
5340
|
-
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
|
|
5364
|
+
_mocody_operationNotSuccessful = "Operation Not Successful";
|
|
5365
|
+
_mocody_entityFieldsKeySet;
|
|
5366
|
+
_mocody_mongoDb;
|
|
5367
|
+
_mocody_dataKeyGenerator;
|
|
5368
|
+
_mocody_schema;
|
|
5369
|
+
_mocody_tableFullName;
|
|
5370
|
+
_mocody_strictRequiredFields;
|
|
5371
|
+
_mocody_featureEntityValue;
|
|
5372
|
+
_mocody_secondaryIndexOptions;
|
|
5373
|
+
_mocody_filterQueryOperation = new MongoFilterQueryOperation();
|
|
5344
5374
|
//
|
|
5345
|
-
|
|
5375
|
+
_mocody_fieldAliases;
|
|
5346
5376
|
//
|
|
5347
|
-
|
|
5377
|
+
_mocody_tableManager;
|
|
5348
5378
|
constructor({
|
|
5349
5379
|
schemaDef,
|
|
5350
5380
|
mongoDbInitializer,
|
|
@@ -5355,7 +5385,7 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5355
5385
|
dataKeyGenerator,
|
|
5356
5386
|
fieldAliases
|
|
5357
5387
|
}) {
|
|
5358
|
-
super();
|
|
5388
|
+
super();
|
|
5359
5389
|
this._mocody_mongoDb = mongoDbInitializer;
|
|
5360
5390
|
this._mocody_dataKeyGenerator = dataKeyGenerator;
|
|
5361
5391
|
this._mocody_tableFullName = baseTableName;
|
|
@@ -5371,9 +5401,9 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5371
5401
|
Object.keys(fullSchemaMapDef).forEach((key) => {
|
|
5372
5402
|
this._mocody_entityFieldsKeySet.add(key);
|
|
5373
5403
|
});
|
|
5374
|
-
this._mocody_schema =
|
|
5404
|
+
this._mocody_schema = import_joi4.default.object().keys({
|
|
5375
5405
|
...fullSchemaMapDef,
|
|
5376
|
-
_id:
|
|
5406
|
+
_id: import_joi4.default.string().required().min(5).max(512)
|
|
5377
5407
|
});
|
|
5378
5408
|
}
|
|
5379
5409
|
mocody_tableManager() {
|
|
@@ -5424,7 +5454,7 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5424
5454
|
item,
|
|
5425
5455
|
withCondition
|
|
5426
5456
|
}) {
|
|
5427
|
-
if (item && typeof item === "object" &&
|
|
5457
|
+
if (item && typeof item === "object" && withCondition?.length) {
|
|
5428
5458
|
const isPassed = withCondition.every(({ field, equals }) => {
|
|
5429
5459
|
return item[field] !== void 0 && item[field] === equals;
|
|
5430
5460
|
});
|
|
@@ -5440,7 +5470,7 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5440
5470
|
_mocody_checkValidateStrictRequiredFields(onDataObj) {
|
|
5441
5471
|
this._mocody_checkValidateMustBeAnObjectDataType(onDataObj);
|
|
5442
5472
|
const { strictRequiredFields } = this._mocody_getLocalVariables();
|
|
5443
|
-
if (
|
|
5473
|
+
if (strictRequiredFields?.length) {
|
|
5444
5474
|
strictRequiredFields.forEach((field) => {
|
|
5445
5475
|
if (onDataObj[field] === null || onDataObj[field] === void 0) {
|
|
5446
5476
|
throw this._mocody_createGenericError(`Strict required field: '${field}', NOT defined`);
|
|
@@ -5462,7 +5492,7 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5462
5492
|
});
|
|
5463
5493
|
}
|
|
5464
5494
|
_mocody_toMongoProjection(fields) {
|
|
5465
|
-
if (
|
|
5495
|
+
if (fields?.length) {
|
|
5466
5496
|
const projection = {};
|
|
5467
5497
|
const uniqueFields = this._mocody_removeDuplicateString(fields);
|
|
5468
5498
|
uniqueFields.forEach((field) => {
|
|
@@ -5477,7 +5507,7 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5477
5507
|
stripUnknown: true
|
|
5478
5508
|
});
|
|
5479
5509
|
if (error) {
|
|
5480
|
-
const msg =
|
|
5510
|
+
const msg = getJoiValidationErrors(error) ?? "Validation error occured";
|
|
5481
5511
|
throw MocodyErrorUtilsService.mocody_helper_createFriendlyError(msg);
|
|
5482
5512
|
}
|
|
5483
5513
|
const validatedData = MocodyUtil.alignFormatFieldAlias({
|
|
@@ -5504,7 +5534,7 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5504
5534
|
const nativeId = this._mocody_getNativeMongoId(dataId);
|
|
5505
5535
|
const query = { _id: nativeId };
|
|
5506
5536
|
const dataInDb = await mongo.findOne(query, { projection: { _id: 0 } });
|
|
5507
|
-
if (!(
|
|
5537
|
+
if (!(dataInDb?.id === dataId && dataInDb.featureEntity === this._mocody_featureEntityValue)) {
|
|
5508
5538
|
return null;
|
|
5509
5539
|
}
|
|
5510
5540
|
const passed = this._mocody_withConditionPassed({ item: dataInDb, withCondition });
|
|
@@ -5520,20 +5550,20 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5520
5550
|
withCondition
|
|
5521
5551
|
}) {
|
|
5522
5552
|
const dataList = [];
|
|
5523
|
-
if (!
|
|
5553
|
+
if (!dataIds?.length) {
|
|
5524
5554
|
return dataList;
|
|
5525
5555
|
}
|
|
5526
5556
|
dataIds.forEach((dataId) => {
|
|
5527
5557
|
MocodyErrorUtilsService.mocody_helper_validateRequiredString({ BatchGetDataId: dataId });
|
|
5528
5558
|
});
|
|
5529
5559
|
const uniqueIds = this._mocody_removeDuplicateString(dataIds);
|
|
5530
|
-
if (
|
|
5560
|
+
if (uniqueIds?.length === 1) {
|
|
5531
5561
|
const result = await this.mocody_getOneById({
|
|
5532
5562
|
dataId: uniqueIds[0],
|
|
5533
5563
|
withCondition
|
|
5534
5564
|
});
|
|
5535
5565
|
if (result) {
|
|
5536
|
-
if (
|
|
5566
|
+
if (fields?.length) {
|
|
5537
5567
|
const result01 = UtilService.pickFromObject({ dataObject: result, pickKeys: fields });
|
|
5538
5568
|
dataList.push(result01);
|
|
5539
5569
|
} else {
|
|
@@ -5545,7 +5575,7 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5545
5575
|
const fullUniqueIds = uniqueIds.map((id) => this._mocody_getNativeMongoId(id));
|
|
5546
5576
|
const mongo = await this._mocody_getDbInstance();
|
|
5547
5577
|
const fieldKeys = this._mocody_getProjectionFields({ fields, excludeFields });
|
|
5548
|
-
if (
|
|
5578
|
+
if (withCondition?.length && fieldKeys?.length) {
|
|
5549
5579
|
withCondition.forEach((item) => {
|
|
5550
5580
|
fieldKeys.push(item.field);
|
|
5551
5581
|
});
|
|
@@ -5553,13 +5583,13 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5553
5583
|
const projection = this._mocody_toMongoProjection(fieldKeys);
|
|
5554
5584
|
const query = { _id: { $in: fullUniqueIds } };
|
|
5555
5585
|
const dataListInDb = await mongo.find(query, { projection }).toArray();
|
|
5556
|
-
if (!
|
|
5586
|
+
if (!dataListInDb?.length) {
|
|
5557
5587
|
return [];
|
|
5558
5588
|
}
|
|
5559
5589
|
const dataListInDb01 = dataListInDb.map((f) => {
|
|
5560
5590
|
return UtilService.deleteKeysFromObject({ dataObject: f, delKeys: ["_id"] });
|
|
5561
5591
|
});
|
|
5562
|
-
if (
|
|
5592
|
+
if (withCondition?.length) {
|
|
5563
5593
|
const dataFiltered = dataListInDb01.filter((item) => {
|
|
5564
5594
|
const passed = this._mocody_withConditionPassed({ item, withCondition });
|
|
5565
5595
|
return passed;
|
|
@@ -5584,7 +5614,7 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5584
5614
|
const { validatedData, validatedDataWithTTL } = await this._mocody_validateReady({ data });
|
|
5585
5615
|
const mongo = await this._mocody_getDbInstance();
|
|
5586
5616
|
const result = await mongo.insertOne(validatedDataWithTTL);
|
|
5587
|
-
if (!
|
|
5617
|
+
if (!result?.acknowledged) {
|
|
5588
5618
|
throw this._mocody_createGenericError(this._mocody_operationNotSuccessful);
|
|
5589
5619
|
}
|
|
5590
5620
|
const final = { ...validatedData };
|
|
@@ -5615,7 +5645,7 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5615
5645
|
return { validatedData, validatedDataWithTTL };
|
|
5616
5646
|
}
|
|
5617
5647
|
_mocody_formatTTL(fullData) {
|
|
5618
|
-
if (
|
|
5648
|
+
if (fullData?.dangerouslyExpireAt) {
|
|
5619
5649
|
fullData.dangerouslyExpireAtTTL = new Date(fullData.dangerouslyExpireAt);
|
|
5620
5650
|
} else {
|
|
5621
5651
|
delete fullData.dangerouslyExpireAtTTL;
|
|
@@ -5632,7 +5662,7 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5632
5662
|
const query = { _id: nativeId };
|
|
5633
5663
|
const mongo = await this._mocody_getDbInstance();
|
|
5634
5664
|
const dataInDb = await mongo.findOne(query);
|
|
5635
|
-
if (!(
|
|
5665
|
+
if (!(dataInDb?.id === dataId && dataInDb.featureEntity === this._mocody_featureEntityValue)) {
|
|
5636
5666
|
throw this._mocody_createGenericError("Record does not exists");
|
|
5637
5667
|
}
|
|
5638
5668
|
const passed = this._mocody_withConditionPassed({ item: dataInDb, withCondition });
|
|
@@ -5694,9 +5724,9 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5694
5724
|
const session = await this._mocody_mongoDb().getNewSession();
|
|
5695
5725
|
try {
|
|
5696
5726
|
const transactionOptions = {
|
|
5697
|
-
readPreference: new
|
|
5698
|
-
readConcern: new
|
|
5699
|
-
writeConcern: new
|
|
5727
|
+
readPreference: new import_mongodb2.ReadPreference("primary"),
|
|
5728
|
+
readConcern: new import_mongodb2.ReadConcern("local"),
|
|
5729
|
+
writeConcern: new import_mongodb2.WriteConcern("majority")
|
|
5700
5730
|
};
|
|
5701
5731
|
await session.withTransaction(async () => {
|
|
5702
5732
|
for (const item of transactInfo) {
|
|
@@ -5727,7 +5757,7 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5727
5757
|
canPaginate: false,
|
|
5728
5758
|
enableRelationFetch: false
|
|
5729
5759
|
});
|
|
5730
|
-
if (
|
|
5760
|
+
if (result?.paginationResults) {
|
|
5731
5761
|
return result.paginationResults;
|
|
5732
5762
|
}
|
|
5733
5763
|
return [];
|
|
@@ -5745,7 +5775,7 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5745
5775
|
canPaginate: false,
|
|
5746
5776
|
enableRelationFetch: true
|
|
5747
5777
|
});
|
|
5748
|
-
if (
|
|
5778
|
+
if (result?.paginationResults) {
|
|
5749
5779
|
return result.paginationResults;
|
|
5750
5780
|
}
|
|
5751
5781
|
return [];
|
|
@@ -5763,10 +5793,10 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5763
5793
|
enableRelationFetch
|
|
5764
5794
|
}) {
|
|
5765
5795
|
const { secondaryIndexOptions } = this._mocody_getLocalVariables();
|
|
5766
|
-
if (!
|
|
5796
|
+
if (!secondaryIndexOptions?.length) {
|
|
5767
5797
|
throw this._mocody_createGenericError("Invalid secondary index definitions");
|
|
5768
5798
|
}
|
|
5769
|
-
if (!
|
|
5799
|
+
if (!paramOption?.indexName) {
|
|
5770
5800
|
throw this._mocody_createGenericError("Invalid index name input");
|
|
5771
5801
|
}
|
|
5772
5802
|
const secondaryIndex = secondaryIndexOptions.find((item) => {
|
|
@@ -5809,7 +5839,7 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5809
5839
|
fields: paramOption.fields,
|
|
5810
5840
|
excludeFields: paramOption.excludeFields
|
|
5811
5841
|
});
|
|
5812
|
-
const projection =
|
|
5842
|
+
const projection = this._mocody_toMongoProjection(fieldKeys) ?? { _id: 0 };
|
|
5813
5843
|
const sort01 = [];
|
|
5814
5844
|
if (paramOption.sort === "desc") {
|
|
5815
5845
|
sort01.push([index_PartitionKeyFieldName, -1]);
|
|
@@ -5832,7 +5862,7 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5832
5862
|
pagingOptions.limit = Number(paramOption.limit);
|
|
5833
5863
|
}
|
|
5834
5864
|
try {
|
|
5835
|
-
const nextPageHash01 =
|
|
5865
|
+
const nextPageHash01 = paramOption?.pagingParams?.nextPageHash;
|
|
5836
5866
|
if (nextPageHash01) {
|
|
5837
5867
|
const param01 = JSON.parse(UtilService.decodeStringFromBase64(nextPageHash01));
|
|
5838
5868
|
if (UtilService.isNumericInteger(param01.limit)) {
|
|
@@ -5843,7 +5873,7 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5843
5873
|
}
|
|
5844
5874
|
}
|
|
5845
5875
|
} catch (error) {
|
|
5846
|
-
LoggingService.log(
|
|
5876
|
+
LoggingService.log(error?.message);
|
|
5847
5877
|
}
|
|
5848
5878
|
const skipValue = pagingOptions.limit * (pagingOptions.pageNo || 0);
|
|
5849
5879
|
if (skipValue) {
|
|
@@ -5881,7 +5911,7 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5881
5911
|
const nativeId = this._mocody_getNativeMongoId(dataId);
|
|
5882
5912
|
const query = { _id: nativeId };
|
|
5883
5913
|
const dataInDb = await db.findOne(query);
|
|
5884
|
-
if (!(
|
|
5914
|
+
if (!(dataInDb?.id === dataId && dataInDb.featureEntity === this._mocody_featureEntityValue)) {
|
|
5885
5915
|
throw this._mocody_createGenericError("Record does not exists");
|
|
5886
5916
|
}
|
|
5887
5917
|
const passed = this._mocody_withConditionPassed({ item: dataInDb, withCondition });
|
|
@@ -5889,19 +5919,20 @@ var MongoDataOperation = (_class3 = class extends RepoModel {
|
|
|
5889
5919
|
throw this._mocody_createGenericError("Record with conditions does not exists for deletion");
|
|
5890
5920
|
}
|
|
5891
5921
|
const result = await db.deleteOne(query);
|
|
5892
|
-
if (!
|
|
5922
|
+
if (!result?.deletedCount) {
|
|
5893
5923
|
throw this._mocody_createGenericError(this._mocody_operationNotSuccessful);
|
|
5894
5924
|
}
|
|
5895
5925
|
return dataInDb;
|
|
5896
5926
|
}
|
|
5897
|
-
}
|
|
5898
|
-
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
5927
|
+
};
|
|
5928
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
5929
|
+
0 && (module.exports = {
|
|
5930
|
+
CouchDataOperation,
|
|
5931
|
+
DynamoDataOperation,
|
|
5932
|
+
MocodyGenericError,
|
|
5933
|
+
MocodyInitializerCouch,
|
|
5934
|
+
MocodyInitializerDynamo,
|
|
5935
|
+
MocodyInitializerMongo,
|
|
5936
|
+
MocodyUtil,
|
|
5937
|
+
MongoDataOperation
|
|
5938
|
+
});
|