@qrvey/data-persistence 0.5.18-796 → 0.5.19-831-beta

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.
@@ -26,6 +26,7 @@ var __spreadValues = (a, b) => {
26
26
  return a;
27
27
  };
28
28
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
29
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
29
30
  var __objRest = (source, exclude) => {
30
31
  var target = {};
31
32
  for (var prop in source)
@@ -38,6 +39,7 @@ var __objRest = (source, exclude) => {
38
39
  }
39
40
  return target;
40
41
  };
42
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
41
43
  var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
42
44
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
43
45
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
@@ -65,16 +67,32 @@ var FILTER_OPERATOR_MAP = {
65
67
  var DYNAMODB_OPERATORS = {
66
68
  EQUAL: "EQUAL"
67
69
  };
68
- var CONNECTION_CLOSING_MODES = /* @__PURE__ */ ((CONNECTION_CLOSING_MODES2) => {
69
- CONNECTION_CLOSING_MODES2["AUTO"] = "AUTO";
70
- CONNECTION_CLOSING_MODES2["MANUAL"] = "MANUAL";
71
- return CONNECTION_CLOSING_MODES2;
72
- })(CONNECTION_CLOSING_MODES || {});
73
- var FILTER_LOGIC_OPERATORS = /* @__PURE__ */ ((FILTER_LOGIC_OPERATORS2) => {
70
+ var SORT_DIRECTIONS = /* @__PURE__ */ (function(SORT_DIRECTIONS2) {
71
+ SORT_DIRECTIONS2["ASC"] = "ASC";
72
+ SORT_DIRECTIONS2["DESC"] = "DESC";
73
+ return SORT_DIRECTIONS2;
74
+ })({});
75
+ var FILTER_LOGIC_OPERATORS = /* @__PURE__ */ (function(FILTER_LOGIC_OPERATORS2) {
74
76
  FILTER_LOGIC_OPERATORS2["AND"] = "AND";
75
77
  FILTER_LOGIC_OPERATORS2["OR"] = "OR";
76
78
  return FILTER_LOGIC_OPERATORS2;
77
- })(FILTER_LOGIC_OPERATORS || {});
79
+ })({});
80
+ var FilterOperator = /* @__PURE__ */ (function(FilterOperator2) {
81
+ FilterOperator2["EQUAL"] = "EQUAL";
82
+ FilterOperator2["NOT_EQUAL"] = "NOT_EQUAL";
83
+ FilterOperator2["CONTAINS"] = "CONTAINS";
84
+ FilterOperator2["GREATER_THAN"] = "GREATER_THAN";
85
+ FilterOperator2["GREATER_THAN_EQUAL"] = "GREATER_THAN_EQUAL";
86
+ FilterOperator2["LESS_THAN"] = "LESS_THAN";
87
+ FilterOperator2["LESS_THAN_EQUAL"] = "LESS_THAN_EQUAL";
88
+ FilterOperator2["IN"] = "IN";
89
+ FilterOperator2["STARTS_WITH"] = "STARTS_WITH";
90
+ FilterOperator2["NOT_CONTAINS"] = "NOT_CONTAINS";
91
+ FilterOperator2["BETWEEN"] = "BETWEEN";
92
+ FilterOperator2["EXIST"] = "EXIST";
93
+ FilterOperator2["NOT_EXIST"] = "NOT_EXIST";
94
+ return FilterOperator2;
95
+ })({});
78
96
  var POSTGRES_FILTER_OPERATOR_MAP = {
79
97
  EQUAL: "=",
80
98
  NOT_EQUAL: "<>",
@@ -95,6 +113,10 @@ var POSTGRES_FILTER_OPERATOR_MAP = {
95
113
  NOT_EXIST: "IS NULL"
96
114
  };
97
115
  var DEFAULT_PG_SCHEMA = "public";
116
+ var AGGREGATE_FUNCTIONS = /* @__PURE__ */ (function(AGGREGATE_FUNCTIONS2) {
117
+ AGGREGATE_FUNCTIONS2["COUNT"] = "COUNT";
118
+ return AGGREGATE_FUNCTIONS2;
119
+ })({});
98
120
  var DYNAMO_DB_UPDATE_ACTIONS = {
99
121
  SET: "SET",
100
122
  ADD: "ADD",
@@ -102,12 +124,14 @@ var DYNAMO_DB_UPDATE_ACTIONS = {
102
124
  REMOVE: "REMOVE"
103
125
  };
104
126
  function isMultiPlatformMode() {
105
- var _a;
106
- return ((_a = process.env.PLATFORM_TYPE) == null ? void 0 : _a.toLowerCase()) === "container";
127
+ var _a2;
128
+ return ((_a2 = process.env.PLATFORM_TYPE) == null ? void 0 : _a2.toLowerCase()) === "container";
107
129
  }
130
+ __name(isMultiPlatformMode, "isMultiPlatformMode");
108
131
  function getConnectionAlias() {
109
132
  return process.env.PG_CONNECTION_ALIAS || process.env.HOSTNAME || process.env.SERVICE_NAME || "qrvey-service";
110
133
  }
134
+ __name(getConnectionAlias, "getConnectionAlias");
111
135
 
112
136
  // src/helpers/crudHelpers.ts
113
137
  function buildFilter(attribute, value, operator = "EQUAL", relativePath = void 0) {
@@ -118,27 +142,31 @@ function buildFilter(attribute, value, operator = "EQUAL", relativePath = void 0
118
142
  relativePath
119
143
  };
120
144
  }
145
+ __name(buildFilter, "buildFilter");
121
146
  function buildQueryIndex(indexName, columns) {
122
147
  return {
123
148
  indexName,
124
149
  columns
125
150
  };
126
151
  }
127
- function buildSort(column, direction = "ASC" /* ASC */) {
152
+ __name(buildQueryIndex, "buildQueryIndex");
153
+ function buildSort(column, direction = SORT_DIRECTIONS.ASC) {
128
154
  return {
129
155
  column,
130
156
  direction
131
157
  };
132
158
  }
159
+ __name(buildSort, "buildSort");
133
160
  var AWS_REGION = process.env.AWS_DEFAULT_REGION;
134
- var DynamoDbClientService = class {
161
+ var _DynamoDbClientService = class _DynamoDbClientService {
135
162
  constructor(tableName) {
136
- if (!tableName)
137
- throw new Error(
138
- 'The "tableName" is required to use a DynamoDbClientService.'
139
- );
163
+ __publicField(this, "tableName");
164
+ __publicField(this, "dynamoDBClient");
165
+ if (!tableName) throw new Error('The "tableName" is required to use a DynamoDbClientService.');
140
166
  this.tableName = tableName;
141
- const client = new DynamoDBClient({ region: AWS_REGION });
167
+ const client = new DynamoDBClient({
168
+ region: AWS_REGION
169
+ });
142
170
  this.dynamoDBClient = DynamoDBDocumentClient.from(client, {
143
171
  marshallOptions: {
144
172
  removeUndefinedValues: true
@@ -268,23 +296,36 @@ var DynamoDbClientService = class {
268
296
  return await this.dynamoDBClient.send(new UpdateCommand(params));
269
297
  }
270
298
  };
299
+ __name(_DynamoDbClientService, "DynamoDbClientService");
300
+ var DynamoDbClientService = _DynamoDbClientService;
271
301
 
272
302
  // src/helpers/queryHelpers.ts
303
+ var METHOD_TO_QUERY = /* @__PURE__ */ (function(METHOD_TO_QUERY2) {
304
+ METHOD_TO_QUERY2["where"] = "where";
305
+ METHOD_TO_QUERY2["filter"] = "filter";
306
+ METHOD_TO_QUERY2["update"] = "update";
307
+ return METHOD_TO_QUERY2;
308
+ })({});
273
309
  function buildAggFunctionAlias(aggregateFunction) {
274
310
  return `AGG_FN_${aggregateFunction}`;
275
311
  }
312
+ __name(buildAggFunctionAlias, "buildAggFunctionAlias");
276
313
 
277
314
  // src/services/cruds/dynamodb/queryBuilderCondition.service.ts
278
- var QueryBuilderConditionService = class {
315
+ var _QueryBuilderConditionService = class _QueryBuilderConditionService {
279
316
  constructor(query) {
280
- this.tempKey = "";
281
- this.tempLogicOperator = null;
282
- this.wheres = [];
283
- this.filters = [];
284
- this.updates = [];
285
- this.attributeNames = {};
317
+ __publicField(this, "query");
318
+ __publicField(this, "command");
319
+ __publicField(this, "queryFrom");
320
+ __publicField(this, "tempKey", "");
321
+ __publicField(this, "tempLogicOperator", null);
322
+ __publicField(this, "config");
323
+ __publicField(this, "wheres", []);
324
+ __publicField(this, "filters", []);
325
+ __publicField(this, "updates", []);
326
+ __publicField(this, "attributeNames", {});
286
327
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
287
- this.attributeValues = {};
328
+ __publicField(this, "attributeValues", {});
288
329
  this.query = query;
289
330
  this.command = {};
290
331
  }
@@ -311,49 +352,69 @@ var QueryBuilderConditionService = class {
311
352
  eq(keyValue) {
312
353
  const { key, value } = this.generateKeyValue(keyValue);
313
354
  let expression = `${key} = ${value}`;
314
- if (this.tempLogicOperator)
315
- expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
355
+ if (this.tempLogicOperator) expression = {
356
+ expression,
357
+ logicOperator: this.tempLogicOperator,
358
+ config: this.config
359
+ };
316
360
  this.setExpression(expression);
317
361
  return this.query;
318
362
  }
319
363
  notEq(keyValue) {
320
364
  const { key, value } = this.generateKeyValue(keyValue);
321
365
  let expression = `${key} <> ${value}`;
322
- if (this.tempLogicOperator)
323
- expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
366
+ if (this.tempLogicOperator) expression = {
367
+ expression,
368
+ logicOperator: this.tempLogicOperator,
369
+ config: this.config
370
+ };
324
371
  this.setExpression(expression);
325
372
  return this.query;
326
373
  }
327
374
  contains(keyValue) {
328
375
  const { key, value } = this.generateKeyValue(keyValue);
329
376
  let expression = `contains(${key}, ${value})`;
330
- if (this.tempLogicOperator)
331
- expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
377
+ if (this.tempLogicOperator) expression = {
378
+ expression,
379
+ logicOperator: this.tempLogicOperator,
380
+ config: this.config
381
+ };
332
382
  this.setExpression(expression);
333
383
  return this.query;
334
384
  }
335
385
  notContains(keyValue) {
336
386
  const { key, value } = this.generateKeyValue(keyValue);
337
387
  let expression = `NOT contains(${key}, ${value})`;
338
- if (this.tempLogicOperator)
339
- expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
388
+ if (this.tempLogicOperator) expression = {
389
+ expression,
390
+ logicOperator: this.tempLogicOperator,
391
+ config: this.config
392
+ };
340
393
  this.setExpression(expression);
341
394
  return this.query;
342
395
  }
343
396
  in(keyValue) {
344
- const keyValues = Array.isArray(keyValue) ? keyValue : [keyValue];
397
+ const keyValues = Array.isArray(keyValue) ? keyValue : [
398
+ keyValue
399
+ ];
345
400
  const { key, value } = this.generateKeyValue(keyValues);
346
401
  let expression = `${key} IN (${value})`;
347
- if (this.tempLogicOperator)
348
- expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
402
+ if (this.tempLogicOperator) expression = {
403
+ expression,
404
+ logicOperator: this.tempLogicOperator,
405
+ config: this.config
406
+ };
349
407
  this.setExpression(expression);
350
408
  return this.query;
351
409
  }
352
410
  beginsWith(keyValue) {
353
411
  const { key, value } = this.generateKeyValue(keyValue);
354
412
  let expression = `begins_with(${key}, ${value})`;
355
- if (this.tempLogicOperator)
356
- expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
413
+ if (this.tempLogicOperator) expression = {
414
+ expression,
415
+ logicOperator: this.tempLogicOperator,
416
+ config: this.config
417
+ };
357
418
  this.setExpression(expression);
358
419
  return this.query;
359
420
  }
@@ -365,70 +426,88 @@ var QueryBuilderConditionService = class {
365
426
  gt(keyValue) {
366
427
  const { key, value } = this.generateKeyValue(keyValue);
367
428
  let expression = `${key} > ${value}`;
368
- if (this.tempLogicOperator)
369
- expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
429
+ if (this.tempLogicOperator) expression = {
430
+ expression,
431
+ logicOperator: this.tempLogicOperator,
432
+ config: this.config
433
+ };
370
434
  this.setExpression(expression);
371
435
  return this.query;
372
436
  }
373
437
  gte(keyValue) {
374
438
  const { key, value } = this.generateKeyValue(keyValue);
375
439
  let expression = `${key} >= ${value}`;
376
- if (this.tempLogicOperator)
377
- expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
440
+ if (this.tempLogicOperator) expression = {
441
+ expression,
442
+ logicOperator: this.tempLogicOperator,
443
+ config: this.config
444
+ };
378
445
  this.setExpression(expression);
379
446
  return this.query;
380
447
  }
381
448
  lte(keyValue) {
382
449
  const { key, value } = this.generateKeyValue(keyValue);
383
450
  let expression = `${key} <= ${value}`;
384
- if (this.tempLogicOperator)
385
- expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
451
+ if (this.tempLogicOperator) expression = {
452
+ expression,
453
+ logicOperator: this.tempLogicOperator,
454
+ config: this.config
455
+ };
386
456
  this.setExpression(expression);
387
457
  return this.query;
388
458
  }
389
459
  lt(keyValue) {
390
460
  const { key, value } = this.generateKeyValue(keyValue);
391
461
  let expression = `${key} < ${value}`;
392
- if (this.tempLogicOperator)
393
- expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
462
+ if (this.tempLogicOperator) expression = {
463
+ expression,
464
+ logicOperator: this.tempLogicOperator,
465
+ config: this.config
466
+ };
394
467
  this.setExpression(expression);
395
468
  return this.query;
396
469
  }
397
470
  attribute_exists(keyValue) {
398
471
  const { key } = this.generateKeyValue(keyValue, null, true);
399
472
  let expression = `attribute_exists(${key})`;
400
- if (this.tempLogicOperator)
401
- expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
473
+ if (this.tempLogicOperator) expression = {
474
+ expression,
475
+ logicOperator: this.tempLogicOperator,
476
+ config: this.config
477
+ };
402
478
  this.setExpression(expression);
403
479
  return this.query;
404
480
  }
405
481
  attribute_not_exists(keyValue) {
406
482
  const { key } = this.generateKeyValue(keyValue, null, true);
407
483
  let expression = `attribute_not_exists(${key})`;
408
- if (this.tempLogicOperator)
409
- expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
484
+ if (this.tempLogicOperator) expression = {
485
+ expression,
486
+ logicOperator: this.tempLogicOperator,
487
+ config: this.config
488
+ };
410
489
  this.setExpression(expression);
411
490
  return this.query;
412
491
  }
413
492
  between(keyValues) {
414
493
  const isValidValues = Array.isArray(keyValues) && (keyValues == null ? void 0 : keyValues.length) === 2;
415
- if (!isValidValues)
416
- throw new Error(
417
- "The value for between filter operator should be an Array with 2 values."
418
- );
494
+ if (!isValidValues) throw new Error("The value for between filter operator should be an Array with 2 values.");
419
495
  const { key, value } = this.generateKeyValue(keyValues, " AND");
420
496
  let expression = `${key} between ${value}`;
421
- if (this.tempLogicOperator)
422
- expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
497
+ if (this.tempLogicOperator) expression = {
498
+ expression,
499
+ logicOperator: this.tempLogicOperator,
500
+ config: this.config
501
+ };
423
502
  this.setExpression(expression);
424
503
  return this.query;
425
504
  }
426
505
  setExpression(expression) {
427
506
  switch (this.queryFrom) {
428
- case "filter" /* filter */:
507
+ case METHOD_TO_QUERY.filter:
429
508
  this.filters.push(expression);
430
509
  break;
431
- case "update" /* update */:
510
+ case METHOD_TO_QUERY.update:
432
511
  this.updates.push(expression);
433
512
  break;
434
513
  default:
@@ -459,23 +538,25 @@ var QueryBuilderConditionService = class {
459
538
  if (index === valueExpression) valueExpression += "1";
460
539
  }
461
540
  }
462
- if (!omitAttributeValues)
463
- this.attributeValues[valueExpression] = value;
464
- return { key: keyExpression, value: valueExpression };
541
+ if (!omitAttributeValues) this.attributeValues[valueExpression] = value;
542
+ return {
543
+ key: keyExpression,
544
+ value: valueExpression
545
+ };
465
546
  }
466
547
  }
467
548
  build() {
468
- var _a;
549
+ var _a2;
469
550
  if (this.wheres.length > 0) {
470
551
  const keyConditionExpression = this.wheres.join(" AND ");
471
552
  this.command["KeyConditionExpression"] = keyConditionExpression;
472
553
  }
473
554
  if (this.filters.length > 0) {
474
555
  let filterExpression = "";
475
- (_a = this.filters) == null ? void 0 : _a.forEach((filter, index) => {
476
- var _a2, _b;
556
+ (_a2 = this.filters) == null ? void 0 : _a2.forEach((filter, index) => {
557
+ var _a3, _b;
477
558
  if (filter == null ? void 0 : filter.logicOperator) {
478
- if ((_a2 = filter == null ? void 0 : filter.config) == null ? void 0 : _a2.openExpression) {
559
+ if ((_a3 = filter == null ? void 0 : filter.config) == null ? void 0 : _a3.openExpression) {
479
560
  filterExpression = filterExpression.replace(/\s+(AND|OR)\s*$/, ` ${filter.config.parentKey} (`);
480
561
  if (filterExpression === "") filterExpression += "(";
481
562
  filterExpression += `${filter.expression} ${filter.logicOperator} `;
@@ -493,16 +574,19 @@ var QueryBuilderConditionService = class {
493
574
  const filterExpression = this.updates.join(", ");
494
575
  this.command["UpdateExpression"] = `SET ${filterExpression}`;
495
576
  }
496
- if (Object.values(this.attributeNames).length > 0)
497
- this.command["ExpressionAttributeNames"] = this.attributeNames;
498
- if (Object.values(this.attributeValues).length > 0)
499
- this.command["ExpressionAttributeValues"] = this.attributeValues;
577
+ if (Object.values(this.attributeNames).length > 0) this.command["ExpressionAttributeNames"] = this.attributeNames;
578
+ if (Object.values(this.attributeValues).length > 0) this.command["ExpressionAttributeValues"] = this.attributeValues;
500
579
  }
501
580
  };
581
+ __name(_QueryBuilderConditionService, "QueryBuilderConditionService");
582
+ var QueryBuilderConditionService = _QueryBuilderConditionService;
502
583
 
503
584
  // src/services/cruds/dynamodb/queryBuilder.service.ts
504
- var QueryBuilderService = class {
585
+ var _QueryBuilderService = class _QueryBuilderService {
505
586
  constructor(useScan = false) {
587
+ __publicField(this, "useScan");
588
+ __publicField(this, "command");
589
+ __publicField(this, "condition");
506
590
  this.useScan = useScan;
507
591
  this.command = {};
508
592
  this.condition = new QueryBuilderConditionService(this);
@@ -543,16 +627,16 @@ var QueryBuilderService = class {
543
627
  return this;
544
628
  }
545
629
  where(keyName) {
546
- this.condition.setKey(keyName).setTmpLogicOp(null).from("where" /* where */);
630
+ this.condition.setKey(keyName).setTmpLogicOp(null).from(METHOD_TO_QUERY.where);
547
631
  return this.condition;
548
632
  }
549
633
  filter(keyName, logicOperator = "AND", config) {
550
- this.condition.setKey(keyName).setTmpLogicOp(logicOperator).setConfig(config).from("filter" /* filter */);
634
+ this.condition.setKey(keyName).setTmpLogicOp(logicOperator).setConfig(config).from(METHOD_TO_QUERY.filter);
551
635
  return this.condition;
552
636
  }
553
637
  update(attribute) {
554
638
  for (const [key, value] of Object.entries(attribute)) {
555
- this.condition.setKey(key).from("update" /* update */);
639
+ this.condition.setKey(key).from(METHOD_TO_QUERY.update);
556
640
  this.condition.eq(value);
557
641
  }
558
642
  return this;
@@ -562,47 +646,53 @@ var QueryBuilderService = class {
562
646
  return this;
563
647
  }
564
648
  count() {
565
- this.command.Select = "COUNT" /* COUNT */;
649
+ this.command.Select = AGGREGATE_FUNCTIONS.COUNT;
566
650
  return this;
567
651
  }
568
652
  };
653
+ __name(_QueryBuilderService, "QueryBuilderService");
654
+ var QueryBuilderService = _QueryBuilderService;
569
655
 
570
656
  // src/helpers/tableHelper.ts
571
657
  function getTableColumnNames(columns) {
572
658
  return Object.keys(columns);
573
659
  }
660
+ __name(getTableColumnNames, "getTableColumnNames");
574
661
  function findIdColumnName(columns) {
575
- return getTableColumnNames(columns).find(
576
- (columnName) => columns[columnName].columnId === true
577
- );
662
+ return getTableColumnNames(columns).find((columnName) => columns[columnName].columnId === true);
578
663
  }
664
+ __name(findIdColumnName, "findIdColumnName");
579
665
  function getTableName(table, property = "name") {
580
666
  if (!table) throw new Error("missing table property");
581
667
  if (typeof table === "string") return table;
582
668
  const { name, alias } = table;
583
669
  return property === "alias" && alias ? alias : name;
584
670
  }
671
+ __name(getTableName, "getTableName");
585
672
  function getPrimaryKeyColumns(columns) {
586
- return getTableColumnNames(columns).filter(
587
- (columnName) => columns[columnName].primary === true
588
- );
673
+ return getTableColumnNames(columns).filter((columnName) => columns[columnName].primary === true);
589
674
  }
675
+ __name(getPrimaryKeyColumns, "getPrimaryKeyColumns");
590
676
 
591
677
  // src/error/NoRecordsAffectedException.ts
592
- var NoRecordsAffectedException = class extends Error {
678
+ var _NoRecordsAffectedException = class _NoRecordsAffectedException extends Error {
593
679
  constructor() {
594
680
  super("No records affected by update");
595
681
  this.name = "NoRecordsAffectedException";
596
682
  }
597
683
  };
684
+ __name(_NoRecordsAffectedException, "NoRecordsAffectedException");
685
+ var NoRecordsAffectedException = _NoRecordsAffectedException;
598
686
 
599
687
  // src/helpers/errorHelper.ts
600
688
  function logError(context, err) {
601
689
  const message = err instanceof Error ? err.message : String(err);
602
690
  const stack = err instanceof Error ? err.stack : void 0;
603
- console.error(`[data-persistence] ${context}:`, message);
691
+ const serviceName = process.env.SERVICE_NAME ? `[${process.env.SERVICE_NAME}/data-persistence]` : "[data-persistence]";
692
+ console.error(`${serviceName} ${context}:`, message);
604
693
  if (stack) console.error(stack);
605
694
  }
695
+ __name(logError, "logError");
606
696
  function PersistenceErrorWrapper(queryResult) {
607
697
  const dynamoNoRecordsAffectedExceptions = [
608
698
  "ConditionalCheckFailedException"
@@ -620,13 +710,16 @@ function PersistenceErrorWrapper(queryResult) {
620
710
  }
621
711
  return queryResult;
622
712
  }
713
+ __name(PersistenceErrorWrapper, "PersistenceErrorWrapper");
623
714
 
624
715
  // src/services/cruds/dynamodb/dynamoDbCrud.service.ts
625
716
  var _DynamoDbCrudService_instances, prepareAndExecuteUpdateExpression_fn, buildUpdateExpressionQuery_fn, getKeyObjectForUpdateExpression_fn, getUpdateExpressionOptions_fn, extractUpdateExpressionAttributesAndNames_fn;
626
- var DynamoDbCrudService = class {
717
+ var _DynamoDbCrudService = class _DynamoDbCrudService {
627
718
  constructor(tableSchema) {
628
- this.tableSchema = tableSchema;
629
719
  __privateAdd(this, _DynamoDbCrudService_instances);
720
+ __publicField(this, "tableSchema");
721
+ __publicField(this, "dynamoDbClientService");
722
+ this.tableSchema = tableSchema;
630
723
  this.dynamoDbClientService = new DynamoDbClientService(this.tableName);
631
724
  }
632
725
  get tableName() {
@@ -639,11 +732,11 @@ var DynamoDbCrudService = class {
639
732
  return getPrimaryKeyColumns(this.tableSchema.columns);
640
733
  }
641
734
  async create(data) {
642
- var _a;
735
+ var _a2;
643
736
  if (Array.isArray(data)) {
644
737
  const response = await this.dynamoDbClientService.batchWrittenPut(data);
645
738
  return {
646
- unprocessedItems: (_a = response.UnprocessedItems) != null ? _a : []
739
+ unprocessedItems: (_a2 = response.UnprocessedItems) != null ? _a2 : []
647
740
  };
648
741
  } else {
649
742
  await this.dynamoDbClientService.put(data);
@@ -655,28 +748,20 @@ var DynamoDbCrudService = class {
655
748
  throw new Error("Method not implemented.");
656
749
  }
657
750
  find(options = {}) {
658
- var _a, _b, _c, _d;
751
+ var _a2, _b, _c, _d;
659
752
  const query = new QueryBuilderService(options.useScan);
660
- if ((_a = options.index) == null ? void 0 : _a.indexName)
661
- query.usingIndex((_b = options.index) == null ? void 0 : _b.indexName);
753
+ if ((_a2 = options.index) == null ? void 0 : _a2.indexName) query.usingIndex((_b = options.index) == null ? void 0 : _b.indexName);
662
754
  this.applySorting(query, options.sorting, (_c = options.index) == null ? void 0 : _c.indexName);
663
755
  this.applyPagination(query, options.pagination);
664
- if (options.consistentRead)
665
- query.consistentRead(options.consistentRead);
756
+ if (options.consistentRead) query.consistentRead(options.consistentRead);
666
757
  if (options.fields) query.projection(options.fields);
667
758
  this.applyFilters(query, options);
668
- if (options.aggregateFunction === "COUNT" /* COUNT */)
669
- query.count();
670
- return this.fetchResults(
671
- query.get(),
672
- (_d = options.pagination) == null ? void 0 : _d.limit,
673
- options.useScan
674
- ).then((res) => {
675
- var _a2, _b2;
759
+ if (options.aggregateFunction === AGGREGATE_FUNCTIONS.COUNT) query.count();
760
+ return this.fetchResults(query.get(), (_d = options.pagination) == null ? void 0 : _d.limit, options.useScan).then((res) => {
761
+ var _a3, _b2;
676
762
  const pagination = {};
677
763
  if (res.lastEvaluatedKey) pagination.from = res.lastEvaluatedKey;
678
- if ((_a2 = options.pagination) == null ? void 0 : _a2.limit)
679
- pagination.limit = (_b2 = options.pagination) == null ? void 0 : _b2.limit;
764
+ if ((_a3 = options.pagination) == null ? void 0 : _a3.limit) pagination.limit = (_b2 = options.pagination) == null ? void 0 : _b2.limit;
680
765
  return {
681
766
  items: res.items,
682
767
  pagination,
@@ -685,24 +770,18 @@ var DynamoDbCrudService = class {
685
770
  });
686
771
  }
687
772
  async fetchResults(command, limit = 100, useScan = false) {
688
- var _a, _b;
773
+ var _a2, _b;
689
774
  let results = [];
690
775
  let lastEvaluatedKey = {};
691
776
  let rowsCount = 0;
692
777
  do {
693
- const result = await this.fetchBatch(
694
- command,
695
- useScan,
696
- lastEvaluatedKey
697
- );
698
- const rows = (_a = result.Items) != null ? _a : [];
778
+ const result = await this.fetchBatch(command, useScan, lastEvaluatedKey);
779
+ const rows = (_a2 = result.Items) != null ? _a2 : [];
699
780
  results = results.concat(rows);
700
781
  lastEvaluatedKey = (_b = result.LastEvaluatedKey) != null ? _b : {};
701
782
  rowsCount += result.Count || rows.length;
702
783
  } while (rowsCount < limit && this.isNotEmptyObject(lastEvaluatedKey));
703
- const encryptedLastEvaluatedKey = this.isNotEmptyObject(
704
- lastEvaluatedKey
705
- ) ? this.encryptPaginationKey(lastEvaluatedKey) : null;
784
+ const encryptedLastEvaluatedKey = this.isNotEmptyObject(lastEvaluatedKey) ? this.encryptPaginationKey(lastEvaluatedKey) : null;
706
785
  return {
707
786
  items: results,
708
787
  lastEvaluatedKey: encryptedLastEvaluatedKey,
@@ -710,26 +789,25 @@ var DynamoDbCrudService = class {
710
789
  };
711
790
  }
712
791
  async fetchBatch(command, useScan, lastEvaluatedKey) {
713
- var _a, _b, _c;
714
- if (this.isNotEmptyObject(lastEvaluatedKey))
715
- command.ExclusiveStartKey = lastEvaluatedKey;
792
+ var _a2, _b, _c;
793
+ if (this.isNotEmptyObject(lastEvaluatedKey)) command.ExclusiveStartKey = lastEvaluatedKey;
716
794
  const result = await (useScan ? this.dynamoDbClientService.scan(command) : this.dynamoDbClientService.query(command));
717
- if (command.Select !== "COUNT" /* COUNT */) {
718
- command.Limit = ((_a = command.Limit) != null ? _a : 0) - ((_c = (_b = result.Items) == null ? void 0 : _b.length) != null ? _c : 0);
795
+ if (command.Select !== AGGREGATE_FUNCTIONS.COUNT) {
796
+ command.Limit = ((_a2 = command.Limit) != null ? _a2 : 0) - ((_c = (_b = result.Items) == null ? void 0 : _b.length) != null ? _c : 0);
719
797
  }
720
798
  return result;
721
799
  }
722
800
  applyPagination(query, pagination) {
723
801
  if (pagination == null ? void 0 : pagination.limit) query.limit(pagination.limit);
724
- if (pagination == null ? void 0 : pagination.from)
725
- query.startKey(this.decryptPaginationKey(pagination.from));
802
+ if (pagination == null ? void 0 : pagination.from) query.startKey(this.decryptPaginationKey(pagination.from));
726
803
  }
727
804
  async findAll(options = {}, allResults = [], rowsCount = 0) {
728
805
  const { items, pagination, count } = await this.find(options);
729
806
  allResults.push(...items);
730
807
  rowsCount += count;
731
- if (pagination == null ? void 0 : pagination.from)
732
- await this.findAll(__spreadProps(__spreadValues({}, options), { pagination }), allResults);
808
+ if (pagination == null ? void 0 : pagination.from) await this.findAll(__spreadProps(__spreadValues({}, options), {
809
+ pagination
810
+ }), allResults);
733
811
  return {
734
812
  items: allResults,
735
813
  pagination: null,
@@ -737,20 +815,20 @@ var DynamoDbCrudService = class {
737
815
  };
738
816
  }
739
817
  async findCount(options = {}) {
740
- var _a;
818
+ var _a2;
741
819
  const findOptions = __spreadProps(__spreadValues({}, options), {
742
- aggregateFunction: "COUNT" /* COUNT */
820
+ aggregateFunction: AGGREGATE_FUNCTIONS.COUNT
743
821
  });
744
- if ((_a = options.pagination) == null ? void 0 : _a.from) {
822
+ if ((_a2 = options.pagination) == null ? void 0 : _a2.from) {
745
823
  return this.find(findOptions).then((res) => res.count);
746
824
  } else {
747
825
  return this.findAll(findOptions).then((res) => res.count);
748
826
  }
749
827
  }
750
828
  buildFindItemQuery(options) {
751
- var _a;
829
+ var _a2;
752
830
  const query = new QueryBuilderService();
753
- if ((_a = options.index) == null ? void 0 : _a.indexName) query.usingIndex(options.index.indexName);
831
+ if ((_a2 = options.index) == null ? void 0 : _a2.indexName) query.usingIndex(options.index.indexName);
754
832
  this.applyFilters(query, options);
755
833
  query.projection(options.fields);
756
834
  query.limit(1);
@@ -759,20 +837,20 @@ var DynamoDbCrudService = class {
759
837
  findItem(options) {
760
838
  const query = this.buildFindItemQuery(options);
761
839
  return this.dynamoDbClientService.query(query.get()).then((result) => {
762
- var _a;
763
- if ((_a = result.Items) == null ? void 0 : _a.length) return result.Items[0];
840
+ var _a2;
841
+ if ((_a2 = result.Items) == null ? void 0 : _a2.length) return result.Items[0];
764
842
  if (options.throwErrorIfNull) throw new Error("NOT_FOUND");
765
843
  return null;
766
844
  });
767
845
  }
768
846
  applyWhereFilter(query, filter) {
769
- var _a, _b;
770
- const operator = FILTER_OPERATOR_MAP[(_b = (_a = filter.operator) == null ? void 0 : _a.toUpperCase()) != null ? _b : DYNAMODB_OPERATORS.EQUAL];
847
+ var _a2, _b;
848
+ const operator = FILTER_OPERATOR_MAP[(_b = (_a2 = filter.operator) == null ? void 0 : _a2.toUpperCase()) != null ? _b : DYNAMODB_OPERATORS.EQUAL];
771
849
  query.where(filter.attribute)[operator](filter.value);
772
850
  }
773
851
  applyFilterFilter(query, filter, logicOperator = "AND", config) {
774
- var _a, _b;
775
- const operator = FILTER_OPERATOR_MAP[(_b = (_a = filter.operator) == null ? void 0 : _a.toUpperCase()) != null ? _b : DYNAMODB_OPERATORS.EQUAL];
852
+ var _a2, _b;
853
+ const operator = FILTER_OPERATOR_MAP[(_b = (_a2 = filter.operator) == null ? void 0 : _a2.toUpperCase()) != null ? _b : DYNAMODB_OPERATORS.EQUAL];
776
854
  query.filter(filter.attribute, logicOperator, config)[operator](filter.value);
777
855
  }
778
856
  applyFilters(query, options) {
@@ -783,8 +861,8 @@ var DynamoDbCrudService = class {
783
861
  }
784
862
  }
785
863
  applySimpleFilters(query, options) {
786
- var _a, _b;
787
- const queryIndexColumns = (_b = (_a = options.index) == null ? void 0 : _a.columns) != null ? _b : [];
864
+ var _a2, _b;
865
+ const queryIndexColumns = (_b = (_a2 = options.index) == null ? void 0 : _a2.columns) != null ? _b : [];
788
866
  const defaultWhereProperties = this.defaultPrimaryKeys;
789
867
  const whereProperties = (queryIndexColumns == null ? void 0 : queryIndexColumns.length) ? queryIndexColumns : defaultWhereProperties;
790
868
  const filters = options.filters;
@@ -798,42 +876,33 @@ var DynamoDbCrudService = class {
798
876
  this.buildFilterExpression(query, options);
799
877
  }
800
878
  buildFilterExpression(query, options, parentKey) {
801
- var _a;
879
+ var _a2;
802
880
  const compositeFilters = options.filters;
803
- const queryIndexColumns = ((_a = options.index) == null ? void 0 : _a.columns) || [];
881
+ const queryIndexColumns = ((_a2 = options.index) == null ? void 0 : _a2.columns) || [];
804
882
  const defaultWhereProperties = this.defaultPrimaryKeys;
805
883
  const whereProperties = (queryIndexColumns == null ? void 0 : queryIndexColumns.length) ? queryIndexColumns : defaultWhereProperties;
806
884
  for (const [key, value] of Object.entries(compositeFilters)) {
807
- value.forEach(
808
- (filter, index) => {
809
- const isCompositeFilter = "OR" in filter || "AND" in filter;
810
- if (isCompositeFilter) {
811
- const newOptions = __spreadProps(__spreadValues({}, options), {
812
- filters: filter
813
- });
814
- this.buildFilterExpression(query, newOptions, key);
815
- } else {
816
- const simpleFilter = filter;
817
- const isWhereProperty = whereProperties.includes(
818
- simpleFilter.attribute
819
- );
820
- let config;
821
- if (parentKey) {
822
- config = {
823
- parentKey,
824
- openExpression: index === 0,
825
- closeExpression: index === value.length - 1
826
- };
827
- }
828
- isWhereProperty && !options.useScan ? this.applyWhereFilter(query, simpleFilter) : this.applyFilterFilter(
829
- query,
830
- simpleFilter,
831
- key,
832
- config
833
- );
885
+ value.forEach((filter, index) => {
886
+ const isCompositeFilter = "OR" in filter || "AND" in filter;
887
+ if (isCompositeFilter) {
888
+ const newOptions = __spreadProps(__spreadValues({}, options), {
889
+ filters: filter
890
+ });
891
+ this.buildFilterExpression(query, newOptions, key);
892
+ } else {
893
+ const simpleFilter = filter;
894
+ const isWhereProperty = whereProperties.includes(simpleFilter.attribute);
895
+ let config;
896
+ if (parentKey) {
897
+ config = {
898
+ parentKey,
899
+ openExpression: index === 0,
900
+ closeExpression: index === value.length - 1
901
+ };
834
902
  }
903
+ isWhereProperty && !options.useScan ? this.applyWhereFilter(query, simpleFilter) : this.applyFilterFilter(query, simpleFilter, key, config);
835
904
  }
836
- );
905
+ });
837
906
  }
838
907
  }
839
908
  applySorting(query, sorting, sortIndex) {
@@ -871,7 +940,11 @@ var DynamoDbCrudService = class {
871
940
  async upsert(keyColumnNames, data) {
872
941
  const filters = [];
873
942
  keyColumnNames.map((key) => {
874
- filters.push({ attribute: key, value: data[key], operator: "EQUAL" });
943
+ filters.push({
944
+ attribute: key,
945
+ value: data[key],
946
+ operator: "EQUAL"
947
+ });
875
948
  });
876
949
  const savedRecord = await this.findItem({
877
950
  filters
@@ -882,9 +955,7 @@ var DynamoDbCrudService = class {
882
955
  }
883
956
  async remove(filters, options) {
884
957
  if (options == null ? void 0 : options.filterGroups) {
885
- await this.dynamoDbClientService.batchRemove(
886
- filters
887
- );
958
+ await this.dynamoDbClientService.batchRemove(filters);
888
959
  } else {
889
960
  const key = filters.reduce((obj, item) => {
890
961
  const property = item.attribute;
@@ -907,8 +978,10 @@ var DynamoDbCrudService = class {
907
978
  }
908
979
  };
909
980
  _DynamoDbCrudService_instances = new WeakSet();
910
- prepareAndExecuteUpdateExpression_fn = async function(filters, actions, options) {
911
- const queryObject = __privateMethod(this, _DynamoDbCrudService_instances, buildUpdateExpressionQuery_fn).call(this, { filters }).get();
981
+ prepareAndExecuteUpdateExpression_fn = /* @__PURE__ */ __name(async function(filters, actions, options) {
982
+ const queryObject = __privateMethod(this, _DynamoDbCrudService_instances, buildUpdateExpressionQuery_fn).call(this, {
983
+ filters
984
+ }).get();
912
985
  const primaryKeys = this.defaultPrimaryKeys;
913
986
  const keyObject = __privateMethod(this, _DynamoDbCrudService_instances, getKeyObjectForUpdateExpression_fn).call(this, queryObject, primaryKeys);
914
987
  const updateExpressions = [];
@@ -926,46 +999,38 @@ prepareAndExecuteUpdateExpression_fn = async function(filters, actions, options)
926
999
  if (Object.keys(ExpressionAttributeNames).length > 0) {
927
1000
  dbParams["ExpressionAttributeNames"] = __spreadValues(__spreadValues({}, ExpressionAttributeNames), dbParams.ExpressionAttributeNames);
928
1001
  }
929
- if (queryObject.FilterExpression)
930
- dbParams["ConditionExpression"] = queryObject.FilterExpression;
931
- return this.dynamoDbClientService.updateExpressions(
932
- keyObject,
933
- dbParams
934
- );
935
- };
936
- buildUpdateExpressionQuery_fn = function(options) {
937
- var _a;
1002
+ if (queryObject.FilterExpression) dbParams["ConditionExpression"] = queryObject.FilterExpression;
1003
+ return this.dynamoDbClientService.updateExpressions(keyObject, dbParams);
1004
+ }, "#prepareAndExecuteUpdateExpression");
1005
+ buildUpdateExpressionQuery_fn = /* @__PURE__ */ __name(function(options) {
1006
+ var _a2;
938
1007
  const query = new QueryBuilderService();
939
- if ((_a = options.index) == null ? void 0 : _a.indexName) query.usingIndex(options.index.indexName);
1008
+ if ((_a2 = options.index) == null ? void 0 : _a2.indexName) query.usingIndex(options.index.indexName);
940
1009
  this.applyFilters(query, options);
941
1010
  return query;
942
- };
943
- getKeyObjectForUpdateExpression_fn = function(queryObject, primaryKeys) {
1011
+ }, "#buildUpdateExpressionQuery");
1012
+ getKeyObjectForUpdateExpression_fn = /* @__PURE__ */ __name(function(queryObject, primaryKeys) {
944
1013
  const keyObject = {};
945
- Object.keys(queryObject.ExpressionAttributeNames).forEach(
946
- (attribute) => {
947
- const sanitizedAttribute = attribute.replace("#", "").replace("1", "");
948
- if (primaryKeys.includes(sanitizedAttribute)) {
949
- const valueName = `:${sanitizedAttribute}1`;
950
- keyObject[sanitizedAttribute] = queryObject.ExpressionAttributeValues[valueName];
951
- delete queryObject.ExpressionAttributeValues[valueName];
952
- delete queryObject.ExpressionAttributeNames[attribute];
953
- }
1014
+ Object.keys(queryObject.ExpressionAttributeNames).forEach((attribute) => {
1015
+ const sanitizedAttribute = attribute.replace("#", "").replace("1", "");
1016
+ if (primaryKeys.includes(sanitizedAttribute)) {
1017
+ const valueName = `:${sanitizedAttribute}1`;
1018
+ keyObject[sanitizedAttribute] = queryObject.ExpressionAttributeValues[valueName];
1019
+ delete queryObject.ExpressionAttributeValues[valueName];
1020
+ delete queryObject.ExpressionAttributeNames[attribute];
954
1021
  }
955
- );
1022
+ });
956
1023
  return keyObject;
957
- };
958
- getUpdateExpressionOptions_fn = function(options) {
1024
+ }, "#getKeyObjectForUpdateExpression");
1025
+ getUpdateExpressionOptions_fn = /* @__PURE__ */ __name(function(options) {
959
1026
  const updateExprOptions = {
960
1027
  ReturnValues: options.returnValues
961
1028
  };
962
- if (options.expressionAttributeNames)
963
- updateExprOptions.ExpressionAttributeNames = options.expressionAttributeNames;
964
- if (options.expressionAttributeValues)
965
- updateExprOptions.ExpressionAttributeValues = options.expressionAttributeValues;
1029
+ if (options.expressionAttributeNames) updateExprOptions.ExpressionAttributeNames = options.expressionAttributeNames;
1030
+ if (options.expressionAttributeValues) updateExprOptions.ExpressionAttributeValues = options.expressionAttributeValues;
966
1031
  return updateExprOptions;
967
- };
968
- extractUpdateExpressionAttributesAndNames_fn = function(actions, actionType) {
1032
+ }, "#getUpdateExpressionOptions");
1033
+ extractUpdateExpressionAttributesAndNames_fn = /* @__PURE__ */ __name(function(actions, actionType) {
969
1034
  const actionUpdateExpressions = [];
970
1035
  actions[actionType].forEach((action) => {
971
1036
  switch (actionType) {
@@ -977,47 +1042,39 @@ extractUpdateExpressionAttributesAndNames_fn = function(actions, actionType) {
977
1042
  case DYNAMO_DB_UPDATE_ACTIONS.SET:
978
1043
  {
979
1044
  let operator = "";
980
- if (actionType == DYNAMO_DB_UPDATE_ACTIONS.SET)
981
- operator = "=";
982
- actionUpdateExpressions.push(
983
- `${action.path} ${operator}${action.value}`
984
- );
1045
+ if (actionType == DYNAMO_DB_UPDATE_ACTIONS.SET) operator = "=";
1046
+ actionUpdateExpressions.push(`${action.path} ${operator}${action.value}`);
985
1047
  }
986
1048
  break;
987
1049
  }
988
1050
  });
989
- const actionUpdateExpression = `${actionType} ${actionUpdateExpressions.join(
990
- ", "
991
- )}`;
1051
+ const actionUpdateExpression = `${actionType} ${actionUpdateExpressions.join(", ")}`;
992
1052
  return actionUpdateExpression;
993
- };
1053
+ }, "#extractUpdateExpressionAttributesAndNames");
1054
+ __name(_DynamoDbCrudService, "DynamoDbCrudService");
1055
+ var DynamoDbCrudService = _DynamoDbCrudService;
994
1056
 
995
1057
  // src/services/connectionRegistry.ts
996
1058
  var poolRegistry = /* @__PURE__ */ new Set();
997
1059
  var clientRegistry = /* @__PURE__ */ new Set();
998
- var shutdownHandlersRegistered = false;
999
- function registerShutdownHandlers() {
1000
- if (shutdownHandlersRegistered) return;
1001
- shutdownHandlersRegistered = true;
1002
- const handler = async (signal) => {
1003
- const poolCount = poolRegistry.size;
1004
- const clientCount = clientRegistry.size;
1005
- console.log(
1006
- `[data-persistence] ${signal} received, closing ${poolCount} pool(s) and ${clientCount} client(s)...`
1007
- );
1008
- try {
1009
- await closeAllPools();
1010
- await closeAllClients();
1011
- console.log("[data-persistence] All connections closed");
1012
- } catch (err) {
1013
- logError("Unexpected error during shutdown", err);
1014
- }
1015
- };
1016
- process.on("SIGTERM", () => void handler("SIGTERM"));
1017
- process.on("SIGINT", () => void handler("SIGINT"));
1060
+ async function shutdown(signal) {
1061
+ const poolCount = poolRegistry.size;
1062
+ const clientCount = clientRegistry.size;
1063
+ let serviceName = process.env.SERVICE_NAME ? `[${process.env.SERVICE_NAME}/data-persistence]` : "[data-persistence]";
1064
+ console.log(`${serviceName} ${signal} received, closing ${poolCount} pool(s) and ${clientCount} client(s)...`);
1065
+ try {
1066
+ await closeAllClients();
1067
+ await closeAllPools();
1068
+ console.log(`${serviceName} All connections closed`);
1069
+ } catch (err) {
1070
+ logError("Unexpected error during shutdown", err);
1071
+ }
1018
1072
  }
1073
+ __name(shutdown, "shutdown");
1019
1074
  async function closeAllPools() {
1020
- const pools = [...poolRegistry];
1075
+ const pools = [
1076
+ ...poolRegistry
1077
+ ];
1021
1078
  poolRegistry.clear();
1022
1079
  const results = await Promise.allSettled(pools.map((pool) => pool.end()));
1023
1080
  results.forEach((result, i) => {
@@ -1026,40 +1083,42 @@ async function closeAllPools() {
1026
1083
  }
1027
1084
  });
1028
1085
  }
1086
+ __name(closeAllPools, "closeAllPools");
1029
1087
  async function closeAllClients() {
1030
- const clients = [...clientRegistry];
1088
+ const clients = [
1089
+ ...clientRegistry
1090
+ ];
1031
1091
  clientRegistry.clear();
1032
- const results = await Promise.allSettled(
1033
- clients.map((client) => client.end())
1034
- );
1092
+ const results = await Promise.allSettled(clients.map((client) => client.end()));
1035
1093
  results.forEach((result, i) => {
1036
1094
  if (result.status === "rejected") {
1037
1095
  logError(`Client[${i}] failed to close`, result.reason);
1038
1096
  }
1039
1097
  });
1040
1098
  }
1099
+ __name(closeAllClients, "closeAllClients");
1041
1100
  function registerPool(pool) {
1042
1101
  if (!pool) return;
1043
1102
  try {
1044
1103
  poolRegistry.add(pool);
1045
- registerShutdownHandlers();
1046
1104
  } catch (err) {
1047
1105
  logError("Failed to register pool, closing pool", err);
1048
1106
  void pool.end().catch((e) => logError("pool.end failed during rollback", e));
1049
1107
  throw err;
1050
1108
  }
1051
1109
  }
1110
+ __name(registerPool, "registerPool");
1052
1111
  function registerClient(client) {
1053
1112
  if (!client) return;
1054
1113
  try {
1055
1114
  clientRegistry.add(client);
1056
- registerShutdownHandlers();
1057
1115
  } catch (err) {
1058
1116
  logError("Failed to register client, closing client", err);
1059
1117
  void client.end().catch((e) => logError("client.end failed during rollback", e));
1060
1118
  throw err;
1061
1119
  }
1062
1120
  }
1121
+ __name(registerClient, "registerClient");
1063
1122
  function unregisterClient(client) {
1064
1123
  try {
1065
1124
  clientRegistry.delete(client);
@@ -1067,15 +1126,14 @@ function unregisterClient(client) {
1067
1126
  logError("Failed to unregister client", err);
1068
1127
  }
1069
1128
  }
1129
+ __name(unregisterClient, "unregisterClient");
1070
1130
 
1071
1131
  // src/services/cruds/postgresql/connection.service.ts
1072
- var ConnectionService = class {
1132
+ var _ConnectionService = class _ConnectionService {
1073
1133
  get connectionString() {
1074
1134
  const connectionString = process.env.MULTIPLATFORM_PG_CONNECTION_STRING || "";
1075
1135
  if (!connectionString) {
1076
- throw new Error(
1077
- "MULTIPLATFORM_PG_CONNECTION_STRING environment variable must be configured"
1078
- );
1136
+ throw new Error("MULTIPLATFORM_PG_CONNECTION_STRING environment variable must be configured");
1079
1137
  }
1080
1138
  return connectionString;
1081
1139
  }
@@ -1097,18 +1155,24 @@ var ConnectionService = class {
1097
1155
  void client.end().catch((e) => logError("client.end failed during release", e));
1098
1156
  }
1099
1157
  };
1158
+ __name(_ConnectionService, "ConnectionService");
1159
+ var ConnectionService = _ConnectionService;
1100
1160
 
1101
1161
  // src/services/cruds/postgresql/query.service.ts
1102
- var QueryService = class {
1162
+ var _QueryService = class _QueryService {
1103
1163
  constructor(pool) {
1164
+ __publicField(this, "pool");
1165
+ __publicField(this, "connectionService");
1104
1166
  this.pool = pool;
1105
1167
  this.connectionService = new ConnectionService();
1106
1168
  }
1107
1169
  async runQuery(queryText, values) {
1108
1170
  const client = await (this.pool ? this.pool.connect() : this.connectionService.getClient());
1109
1171
  try {
1110
- if (process.env.NODE_ENV === "development")
1111
- console.info("[data-persistence] Query as Text:", queryText);
1172
+ if (process.env.NODE_ENV === "development") {
1173
+ const serviceName = process.env.SERVICE_NAME ? `[${process.env.SERVICE_NAME}/data-persistence]` : "[data-persistence]";
1174
+ console.info(`${serviceName} Query as Text:`, queryText);
1175
+ }
1112
1176
  const result = await client.query(queryText, values);
1113
1177
  return result;
1114
1178
  } finally {
@@ -1120,14 +1184,17 @@ var QueryService = class {
1120
1184
  }
1121
1185
  }
1122
1186
  };
1187
+ __name(_QueryService, "QueryService");
1188
+ var QueryService = _QueryService;
1123
1189
 
1124
1190
  // src/services/cruds/postgresql/postgreSqlClient.service.ts
1125
- var PostgresqlClientService = class extends QueryService {
1191
+ var _PostgresqlClientService = class _PostgresqlClientService extends QueryService {
1126
1192
  constructor(tableSchema, poolClient) {
1127
1193
  super(poolClient);
1128
- this.isCompositeFilter = function(value) {
1194
+ __publicField(this, "crudSchema");
1195
+ __publicField(this, "isCompositeFilter", /* @__PURE__ */ __name(function(value) {
1129
1196
  return "OR" in value || "AND" in value;
1130
- };
1197
+ }, "isCompositeFilter"));
1131
1198
  this.crudSchema = tableSchema;
1132
1199
  }
1133
1200
  get dbSchema() {
@@ -1137,29 +1204,28 @@ var PostgresqlClientService = class extends QueryService {
1137
1204
  return getTableName(this.crudSchema.table, "alias") || getTableName(this.crudSchema.table);
1138
1205
  }
1139
1206
  get isTemporalTable() {
1140
- var _a;
1141
- return (_a = this.crudSchema) == null ? void 0 : _a.isTemporalTable;
1207
+ var _a2;
1208
+ return (_a2 = this.crudSchema) == null ? void 0 : _a2.isTemporalTable;
1142
1209
  }
1143
1210
  getWildcardValue(operator, value) {
1144
- if (operator === "CONTAINS" /* CONTAINS */ || operator === "NOT_CONTAINS" /* NOT_CONTAINS */) {
1211
+ if (operator === FilterOperator.CONTAINS || operator === FilterOperator.NOT_CONTAINS) {
1145
1212
  return "%" + value + "%";
1146
- } else if (operator === "STARTS_WITH" /* STARTS_WITH */) {
1213
+ } else if (operator === FilterOperator.STARTS_WITH) {
1147
1214
  return value + "%";
1148
1215
  } else {
1149
1216
  return value;
1150
1217
  }
1151
1218
  }
1152
1219
  buildClause(operator, attribute, relativePath, value) {
1153
- var _a;
1220
+ var _a2;
1154
1221
  const formattedValue = literal(value);
1155
- operator = operator ? operator.toUpperCase() : "EQUAL" /* EQUAL */;
1222
+ operator = operator ? operator.toUpperCase() : FilterOperator.EQUAL;
1156
1223
  const postgresOperator = POSTGRES_FILTER_OPERATOR_MAP[operator];
1157
- if (!postgresOperator)
1158
- throw new Error(`Unsupported filter operator: ${operator}`);
1224
+ if (!postgresOperator) throw new Error(`Unsupported filter operator: ${operator}`);
1159
1225
  let property;
1160
1226
  const filterProperty = ident(attribute);
1161
1227
  const columnExists = !!this.crudSchema.columns[attribute];
1162
- const columnType = columnExists && ((_a = this.crudSchema.columns[attribute]) == null ? void 0 : _a.type);
1228
+ const columnType = columnExists && ((_a2 = this.crudSchema.columns[attribute]) == null ? void 0 : _a2.type);
1163
1229
  if (relativePath != void 0) {
1164
1230
  const attributePath = relativePath.split(".").join(",");
1165
1231
  property = `("${attribute}" #> '{${attributePath}}')`;
@@ -1170,27 +1236,25 @@ var PostgresqlClientService = class extends QueryService {
1170
1236
  } else {
1171
1237
  property = columnExists ? filterProperty : `("qvAttributes" ->> '${attribute}')`;
1172
1238
  }
1173
- if (operator === "IN" /* IN */) {
1174
- const formattedValues = Array.isArray(value) ? value.map(literal) : [formattedValue];
1175
- return `${property} ${postgresOperator} (${formattedValues.join(
1176
- ", "
1177
- )})`;
1239
+ if (operator === FilterOperator.IN) {
1240
+ const formattedValues = Array.isArray(value) ? value.map(literal) : [
1241
+ formattedValue
1242
+ ];
1243
+ return `${property} ${postgresOperator} (${formattedValues.join(", ")})`;
1178
1244
  }
1179
- if (operator === "BETWEEN" /* BETWEEN */) {
1245
+ if (operator === FilterOperator.BETWEEN) {
1180
1246
  return `${property} ${postgresOperator} ${value[0]} AND ${value[1]}`;
1181
1247
  }
1182
- if (operator === "NOT_EQUAL" /* NOT_EQUAL */ && value !== null) {
1183
- return `(${property} ${postgresOperator} ${literal(
1184
- value
1185
- )} OR ${property} IS NULL)`;
1248
+ if (operator === FilterOperator.NOT_EQUAL && value !== null) {
1249
+ return `(${property} ${postgresOperator} ${literal(value)} OR ${property} IS NULL)`;
1186
1250
  }
1187
- if (operator === "NOT_EXIST" /* NOT_EXIST */ || operator === "EXIST" /* EXIST */) {
1251
+ if (operator === FilterOperator.NOT_EXIST || operator === FilterOperator.EXIST) {
1188
1252
  return `${property} ${postgresOperator}`;
1189
1253
  }
1190
- if ((operator === "CONTAINS" /* CONTAINS */ || operator === "NOT_CONTAINS" /* NOT_CONTAINS */) && columnType === "array") {
1254
+ if ((operator === FilterOperator.CONTAINS || operator === FilterOperator.NOT_CONTAINS) && columnType === "array") {
1191
1255
  const filterValue = typeof value === "number" ? value : `'${value}'`;
1192
1256
  let filterString = `${filterValue} = ANY(${property})`;
1193
- if (operator === "NOT_CONTAINS" /* NOT_CONTAINS */) {
1257
+ if (operator === FilterOperator.NOT_CONTAINS) {
1194
1258
  if (value === null) {
1195
1259
  filterString = `(NOT (${filterString}))`;
1196
1260
  } else {
@@ -1205,16 +1269,9 @@ var PostgresqlClientService = class extends QueryService {
1205
1269
  buildFilterClause(filters, logicOperator) {
1206
1270
  if (Array.isArray(filters)) {
1207
1271
  const filterClauses = filters.map((filter) => {
1208
- return this.buildClause(
1209
- filter.operator,
1210
- filter.attribute,
1211
- filter.relativePath,
1212
- filter.value
1213
- );
1272
+ return this.buildClause(filter.operator, filter.attribute, filter.relativePath, filter.value);
1214
1273
  });
1215
- return filterClauses.join(
1216
- ` ${logicOperator != null ? logicOperator : "AND" /* AND */} `
1217
- );
1274
+ return filterClauses.join(` ${logicOperator != null ? logicOperator : FILTER_LOGIC_OPERATORS.AND} `);
1218
1275
  } else {
1219
1276
  return this.buildQueryByClause(filters);
1220
1277
  }
@@ -1228,24 +1285,15 @@ var PostgresqlClientService = class extends QueryService {
1228
1285
  }
1229
1286
  if (this.isCompositeFilter(value)) {
1230
1287
  filterClauses += "(";
1231
- filterClauses += this.buildQueryByClause(
1232
- value
1233
- );
1288
+ filterClauses += this.buildQueryByClause(value);
1234
1289
  filterClauses += ")";
1235
1290
  } else {
1236
1291
  value.forEach((filter) => {
1237
1292
  let clause = "";
1238
1293
  if (this.isCompositeFilter(filter)) {
1239
- clause = `(${this.buildQueryByClause(
1240
- filter
1241
- )})`;
1294
+ clause = `(${this.buildQueryByClause(filter)})`;
1242
1295
  } else {
1243
- clause = this.buildClause(
1244
- filter.operator,
1245
- filter.attribute,
1246
- filter.relativePath,
1247
- filter.value
1248
- );
1296
+ clause = this.buildClause(filter.operator, filter.attribute, filter.relativePath, filter.value);
1249
1297
  }
1250
1298
  filterClauses += `${clause} ${key} `;
1251
1299
  });
@@ -1256,7 +1304,7 @@ var PostgresqlClientService = class extends QueryService {
1256
1304
  return filterClauses;
1257
1305
  }
1258
1306
  formatOrderByItem(sort) {
1259
- return `${ident(sort.column)} ${sort.direction || "ASC" /* ASC */}`;
1307
+ return `${ident(sort.column)} ${sort.direction || SORT_DIRECTIONS.ASC}`;
1260
1308
  }
1261
1309
  buildOrderByClause(querySorting) {
1262
1310
  try {
@@ -1287,16 +1335,8 @@ var PostgresqlClientService = class extends QueryService {
1287
1335
  }
1288
1336
  async createCommand(data) {
1289
1337
  const keys = Object.keys(data[0]);
1290
- const values = data.map(
1291
- (item) => keys.map((key) => this.formatValue(item[key]))
1292
- );
1293
- const query = format(
1294
- `INSERT INTO ${ident(this.dbSchema)}.${ident(
1295
- this.tableName
1296
- )} (%I) VALUES %L RETURNING *;`,
1297
- keys,
1298
- values
1299
- );
1338
+ const values = data.map((item) => keys.map((key) => this.formatValue(item[key])));
1339
+ const query = format(`INSERT INTO ${ident(this.dbSchema)}.${ident(this.tableName)} (%I) VALUES %L RETURNING *;`, keys, values);
1300
1340
  return this.runQuery(query);
1301
1341
  }
1302
1342
  isValidFiltersInput(filters) {
@@ -1313,8 +1353,7 @@ var PostgresqlClientService = class extends QueryService {
1313
1353
  }
1314
1354
  addFiltersToQuery(query, filters) {
1315
1355
  if (!filters) return query;
1316
- if (this.isValidFiltersInput(filters))
1317
- query += ` WHERE ${this.buildFilterClause(filters)}`;
1356
+ if (this.isValidFiltersInput(filters)) query += ` WHERE ${this.buildFilterClause(filters)}`;
1318
1357
  return query;
1319
1358
  }
1320
1359
  addOrderByToQuery(query, orderBy) {
@@ -1330,17 +1369,12 @@ var PostgresqlClientService = class extends QueryService {
1330
1369
  return query;
1331
1370
  }
1332
1371
  getSelectClause(aggregateFunction, fields = []) {
1333
- if (aggregateFunction)
1334
- return `CAST(${aggregateFunction}(1) AS INTEGER) AS "${buildAggFunctionAlias(
1335
- aggregateFunction
1336
- )}"`;
1372
+ if (aggregateFunction) return `CAST(${aggregateFunction}(1) AS INTEGER) AS "${buildAggFunctionAlias(aggregateFunction)}"`;
1337
1373
  if (!(fields == null ? void 0 : fields.length)) return "*";
1338
1374
  return this.parseFields(fields).join(", ");
1339
1375
  }
1340
1376
  parseFields(fields) {
1341
- const columnsFromSchema = Object.keys(
1342
- this.crudSchema.columns
1343
- );
1377
+ const columnsFromSchema = Object.keys(this.crudSchema.columns);
1344
1378
  const attributes = fields.filter((field) => columnsFromSchema.indexOf(field) !== -1).map((field) => `"${field}"`);
1345
1379
  fields.filter((field) => columnsFromSchema.indexOf(field) === -1).forEach((field) => {
1346
1380
  attributes.push(`"qvAttributes" ->> '${field}' as "${field}"`);
@@ -1367,10 +1401,7 @@ var PostgresqlClientService = class extends QueryService {
1367
1401
  }
1368
1402
  async findCommand(options = {}) {
1369
1403
  const rawWithClause = this.getRawWithClause(options.rawWith);
1370
- let query = `SELECT ${this.getSelectClause(
1371
- options.aggregateFunction,
1372
- options.fields
1373
- )} FROM ${this.getQueryFrom()}`;
1404
+ let query = `SELECT ${this.getSelectClause(options.aggregateFunction, options.fields)} FROM ${this.getQueryFrom()}`;
1374
1405
  query = this.addFiltersToQuery(query, options.filters);
1375
1406
  if (!options.aggregateFunction) {
1376
1407
  query = this.addOrderByToQuery(query, options.sorting);
@@ -1399,9 +1430,7 @@ var PostgresqlClientService = class extends QueryService {
1399
1430
  }
1400
1431
  }
1401
1432
  async updateCommand(filters, data) {
1402
- let query = `UPDATE ${ident(this.dbSchema)}.${ident(
1403
- this.tableName
1404
- )} SET`;
1433
+ let query = `UPDATE ${ident(this.dbSchema)}.${ident(this.tableName)} SET`;
1405
1434
  const updateClauses = Object.entries(data).map(([key, value]) => {
1406
1435
  const dbValue = literal(this.formatValue(value));
1407
1436
  return `${ident(key)} = ${dbValue}`;
@@ -1416,13 +1445,12 @@ var PostgresqlClientService = class extends QueryService {
1416
1445
  const dbValue = literal(this.formatValue(value));
1417
1446
  return `${ident(key)} = ${dbValue}`;
1418
1447
  }) || [];
1419
- if (!(updateClauses == null ? void 0 : updateClauses.length))
1420
- return this.createCommand([data]);
1448
+ if (!(updateClauses == null ? void 0 : updateClauses.length)) return this.createCommand([
1449
+ data
1450
+ ]);
1421
1451
  const columnNames = Object.keys(data);
1422
1452
  const values = columnNames.map((key) => this.formatValue(data[key]));
1423
- let query = format(`INSERT INTO ${ident(this.dbSchema)}.${ident(
1424
- this.tableName
1425
- )} (%I) VALUES (%L) ON CONFLICT (%I) DO UPDATE SET`, columnNames, values, keyColumnNames);
1453
+ let query = format(`INSERT INTO ${ident(this.dbSchema)}.${ident(this.tableName)} (%I) VALUES (%L) ON CONFLICT (%I) DO UPDATE SET`, columnNames, values, keyColumnNames);
1426
1454
  query += ` ${updateClauses.join(", ")} RETURNING *;`;
1427
1455
  return this.runQuery(query);
1428
1456
  }
@@ -1433,19 +1461,13 @@ var PostgresqlClientService = class extends QueryService {
1433
1461
  return filterClauses.join(" OR ");
1434
1462
  }
1435
1463
  async deleteCommand(filters, useFilterGroups = false) {
1436
- let query = `DELETE FROM ${ident(this.dbSchema)}.${ident(
1437
- this.tableName
1438
- )}`;
1464
+ let query = `DELETE FROM ${ident(this.dbSchema)}.${ident(this.tableName)}`;
1439
1465
  if (filters) {
1440
1466
  query += " WHERE ";
1441
1467
  if (useFilterGroups) {
1442
- query += this.buildFilterClauseForFilterGroups(
1443
- filters
1444
- );
1468
+ query += this.buildFilterClauseForFilterGroups(filters);
1445
1469
  } else {
1446
- query += this.buildFilterClause(
1447
- filters
1448
- );
1470
+ query += this.buildFilterClause(filters);
1449
1471
  }
1450
1472
  }
1451
1473
  return this.runQuery(query);
@@ -1454,24 +1476,12 @@ var PostgresqlClientService = class extends QueryService {
1454
1476
  return this.runQuery(queryText, values);
1455
1477
  }
1456
1478
  async updateExpressionCommand(filters, actions, options = {}) {
1457
- let query = `UPDATE ${ident(this.dbSchema)}.${ident(
1458
- this.tableName
1459
- )} SET`;
1479
+ let query = `UPDATE ${ident(this.dbSchema)}.${ident(this.tableName)} SET`;
1460
1480
  const set = actions.SET || [];
1461
1481
  const add = actions.ADD || [];
1462
1482
  const columns = this.crudSchema.columns;
1463
- const setValues = this.replacePathAndValueByAttributeNames(
1464
- set,
1465
- options,
1466
- columns,
1467
- DYNAMO_DB_UPDATE_ACTIONS.SET
1468
- );
1469
- const addValues = this.replacePathAndValueByAttributeNames(
1470
- add,
1471
- options,
1472
- columns,
1473
- DYNAMO_DB_UPDATE_ACTIONS.ADD
1474
- );
1483
+ const setValues = this.replacePathAndValueByAttributeNames(set, options, columns, DYNAMO_DB_UPDATE_ACTIONS.SET);
1484
+ const addValues = this.replacePathAndValueByAttributeNames(add, options, columns, DYNAMO_DB_UPDATE_ACTIONS.ADD);
1475
1485
  const setValuesAndAddValues = setValues.concat(addValues);
1476
1486
  const updateClauses = [];
1477
1487
  const jsonSetExpressionGroup = {};
@@ -1479,20 +1489,22 @@ var PostgresqlClientService = class extends QueryService {
1479
1489
  setValuesAndAddValues.forEach((expression) => {
1480
1490
  const { path, value, createNewColumn, actionName, dynamoFuncName } = expression;
1481
1491
  if (dynamoFuncName) {
1482
- queryFunctions.push({ path, value, dynamoFuncName });
1483
- }
1484
- if (path.includes(".") && !dynamoFuncName) {
1485
- const jsonExpr = this.getJSONBSetExpressionByAction(
1492
+ queryFunctions.push({
1486
1493
  path,
1487
1494
  value,
1488
- {
1489
- createNewColumn,
1490
- actionName
1491
- }
1492
- );
1495
+ dynamoFuncName
1496
+ });
1497
+ }
1498
+ if (path.includes(".") && !dynamoFuncName) {
1499
+ const jsonExpr = this.getJSONBSetExpressionByAction(path, value, {
1500
+ createNewColumn,
1501
+ actionName
1502
+ });
1493
1503
  const columnName = jsonExpr.columnName;
1494
1504
  if (!jsonSetExpressionGroup[columnName]) {
1495
- jsonSetExpressionGroup[columnName] = [jsonExpr];
1505
+ jsonSetExpressionGroup[columnName] = [
1506
+ jsonExpr
1507
+ ];
1496
1508
  } else {
1497
1509
  jsonSetExpressionGroup[columnName].push(jsonExpr);
1498
1510
  }
@@ -1506,16 +1518,13 @@ var PostgresqlClientService = class extends QueryService {
1506
1518
  setObjProperty = true;
1507
1519
  columnName = "qvAttributes";
1508
1520
  column = this.crudSchema.columns[columnName];
1509
- if ((column == null ? void 0 : column.type) == void 0)
1510
- throw `Column type definition for column: (${path}) must be in the CrudSchema`;
1521
+ if ((column == null ? void 0 : column.type) == void 0) throw `Column type definition for column: (${path}) must be in the CrudSchema`;
1511
1522
  columnType = Array.isArray(value) ? "array" : typeof value == "object" ? "object" : "default";
1512
1523
  }
1513
1524
  switch (columnType) {
1514
1525
  case "object":
1515
1526
  {
1516
- const valueSerialized = `${JSON.stringify(
1517
- value
1518
- ).replace(/'/g, "''")}`;
1527
+ const valueSerialized = `${JSON.stringify(value).replace(/'/g, "''")}`;
1519
1528
  expValue = `'${valueSerialized}'::jsonb`;
1520
1529
  }
1521
1530
  break;
@@ -1532,23 +1541,14 @@ var PostgresqlClientService = class extends QueryService {
1532
1541
  updateClauses.push(`${ident(columnName)} = ${expValue}`);
1533
1542
  }
1534
1543
  });
1535
- this.setCommonColumnsQueryFunctions(
1536
- jsonSetExpressionGroup,
1537
- queryFunctions
1538
- );
1544
+ this.setCommonColumnsQueryFunctions(jsonSetExpressionGroup, queryFunctions);
1539
1545
  if (Object.keys(jsonSetExpressionGroup).length > 0) {
1540
1546
  Object.keys(jsonSetExpressionGroup).forEach((groupIndex) => {
1541
- const jsonSetExpression = this.buildJSONBExpression(
1542
- jsonSetExpressionGroup[groupIndex],
1543
- "jsonb_set"
1544
- );
1547
+ const jsonSetExpression = this.buildJSONBExpression(jsonSetExpressionGroup[groupIndex], "jsonb_set");
1545
1548
  updateClauses.push(`${groupIndex} = ${jsonSetExpression}`);
1546
1549
  });
1547
1550
  }
1548
- this.buildUpdateClausesFormDynamoFunctions(
1549
- queryFunctions,
1550
- updateClauses
1551
- );
1551
+ this.buildUpdateClausesFormDynamoFunctions(queryFunctions, updateClauses);
1552
1552
  query += ` ${updateClauses.join(", ")}`;
1553
1553
  query += " WHERE ";
1554
1554
  query += this.buildFilterClause(filters);
@@ -1558,17 +1558,10 @@ var PostgresqlClientService = class extends QueryService {
1558
1558
  if (queryFunctions.length > 0) {
1559
1559
  queryFunctions.forEach((queryFunction) => {
1560
1560
  if (typeof queryFunction.value == "object") {
1561
- const jsonExpr = this.buildJSONBExpression(
1562
- queryFunction.value.jsonExpression,
1563
- "jsonb_insert"
1564
- );
1565
- updateClauses.push(
1566
- `${ident(queryFunction.path)} = ${jsonExpr}`
1567
- );
1561
+ const jsonExpr = this.buildJSONBExpression(queryFunction.value.jsonExpression, "jsonb_insert");
1562
+ updateClauses.push(`${ident(queryFunction.path)} = ${jsonExpr}`);
1568
1563
  } else {
1569
- updateClauses.push(
1570
- `${ident(queryFunction.path)} = ${queryFunction.value}`
1571
- );
1564
+ updateClauses.push(`${ident(queryFunction.path)} = ${queryFunction.value}`);
1572
1565
  }
1573
1566
  });
1574
1567
  }
@@ -1626,10 +1619,7 @@ var PostgresqlClientService = class extends QueryService {
1626
1619
  const parentPath = pathSplitted[0];
1627
1620
  const { createNewColumn, actionName } = options;
1628
1621
  const pathSerialized = pathSplitted.slice(1).join(",");
1629
- const valueSerialized = `'${JSON.stringify(value).replace(
1630
- /'/g,
1631
- "''"
1632
- )}'`;
1622
+ const valueSerialized = `'${JSON.stringify(value).replace(/'/g, "''")}'`;
1633
1623
  if (actionName == DYNAMO_DB_UPDATE_ACTIONS.ADD) {
1634
1624
  if (typeof value != "string" && !isNaN(value)) {
1635
1625
  const resultExpr = {
@@ -1657,7 +1647,9 @@ var PostgresqlClientService = class extends QueryService {
1657
1647
  value: attributesFromGroup.slice(1).join(",").trim(),
1658
1648
  isDynamoFunction: true,
1659
1649
  functionExpr: "",
1660
- jsonExpression: [{}]
1650
+ jsonExpression: [
1651
+ {}
1652
+ ]
1661
1653
  };
1662
1654
  if (columnType == "array") {
1663
1655
  attributes["functionExpr"] = this.buildArrayAppendExpr(attributes);
@@ -1680,11 +1672,7 @@ var PostgresqlClientService = class extends QueryService {
1680
1672
  isDynamoFunction: params == null ? void 0 : params.isDynamoFunction,
1681
1673
  relativePath: arrayPath.length && Array.isArray(arrayPath) ? arrayPath : []
1682
1674
  };
1683
- const jsonbInsertExpressions = this.getExpressionsByDefinitionForJSONBInsert(
1684
- columnName,
1685
- params.value,
1686
- options
1687
- );
1675
+ const jsonbInsertExpressions = this.getExpressionsByDefinitionForJSONBInsert(columnName, params.value, options);
1688
1676
  return jsonbInsertExpressions;
1689
1677
  }
1690
1678
  getExpressionsByDefinitionForJSONBInsert(columnName, value, options) {
@@ -1700,18 +1688,14 @@ var PostgresqlClientService = class extends QueryService {
1700
1688
  parsedValue.forEach((arrayValue) => {
1701
1689
  arrayValue = typeof arrayValue == "string" ? `"${arrayValue}"` : arrayValue;
1702
1690
  jsonbInsertExpressions.push({
1703
- jsonExpr: `'{${pathToAffect}}','${this.serializeJSONValue(
1704
- arrayValue
1705
- )}'`,
1691
+ jsonExpr: `'{${pathToAffect}}','${this.serializeJSONValue(arrayValue)}'`,
1706
1692
  columnName: `"${columnName}"`,
1707
1693
  functionName: "jsonb_insert"
1708
1694
  });
1709
1695
  });
1710
1696
  } else {
1711
1697
  jsonbInsertExpressions.push({
1712
- jsonExpr: `'{${pathToAffect}}','${this.serializeJSONValue(
1713
- parsedValue
1714
- )}'`,
1698
+ jsonExpr: `'{${pathToAffect}}','${this.serializeJSONValue(parsedValue)}'`,
1715
1699
  columnName: `"${columnName}"`,
1716
1700
  functionName: "jsonb_insert"
1717
1701
  });
@@ -1726,15 +1710,9 @@ var PostgresqlClientService = class extends QueryService {
1726
1710
  return jsonbInsertExpressions;
1727
1711
  }
1728
1712
  getInsertExprFromJsonbDef(queryValue, columnType) {
1729
- const listAppendParams = this.getListAppendDefFromValue(
1730
- queryValue,
1731
- columnType
1732
- );
1713
+ const listAppendParams = this.getListAppendDefFromValue(queryValue, columnType);
1733
1714
  if (listAppendParams != null && (listAppendParams == null ? void 0 : listAppendParams.jsonExpression.length) === 0) {
1734
- queryValue = queryValue.replace(
1735
- listAppendParams.originalString,
1736
- listAppendParams.functionExpr
1737
- );
1715
+ queryValue = queryValue.replace(listAppendParams.originalString, listAppendParams.functionExpr);
1738
1716
  } else {
1739
1717
  return listAppendParams;
1740
1718
  }
@@ -1742,27 +1720,15 @@ var PostgresqlClientService = class extends QueryService {
1742
1720
  }
1743
1721
  replacePathAndValueByAttributeNames(actions, options, columns, actionName) {
1744
1722
  return actions.map((action) => {
1745
- action.path = this.replaceExpressionAttributeNames(
1746
- action.path,
1747
- options
1748
- );
1723
+ action.path = this.replaceExpressionAttributeNames(action.path, options);
1749
1724
  if (typeof action.value == "string" && action.value.includes("list_append")) {
1750
1725
  action.path = action.path.split(".")[0];
1751
1726
  const column = columns[action.path];
1752
- action.value = this.replaceExpressionAttributeValuesForDynamoFunctions(
1753
- action.value,
1754
- options
1755
- );
1756
- action.value = this.getInsertExprFromJsonbDef(
1757
- action.value,
1758
- column.type
1759
- );
1727
+ action.value = this.replaceExpressionAttributeValuesForDynamoFunctions(action.value, options);
1728
+ action.value = this.getInsertExprFromJsonbDef(action.value, column.type);
1760
1729
  action.dynamoFuncName = "list_append";
1761
1730
  } else {
1762
- action.value = this.replaceExpressionAttributeValues(
1763
- action.value,
1764
- options
1765
- );
1731
+ action.value = this.replaceExpressionAttributeValues(action.value, options);
1766
1732
  }
1767
1733
  action.actionName = actionName;
1768
1734
  action.createNewColumn = true;
@@ -1775,17 +1741,12 @@ var PostgresqlClientService = class extends QueryService {
1775
1741
  const exprAttributeValuesKeys = expressionAttributeValues ? Object.keys(expressionAttributeValues) : [];
1776
1742
  if (exprAttributeNamesKeys.length > 0) {
1777
1743
  exprAttributeNamesKeys.forEach((exprAttribute) => {
1778
- value = value.replace(
1779
- exprAttribute,
1780
- expressionAttributeNames[exprAttribute]
1781
- );
1744
+ value = value.replace(exprAttribute, expressionAttributeNames[exprAttribute]);
1782
1745
  });
1783
1746
  }
1784
1747
  if (exprAttributeValuesKeys.length > 0) {
1785
1748
  exprAttributeValuesKeys.forEach((exprAttribute) => {
1786
- const valueSerialized = this.serializeJSONValue(
1787
- expressionAttributeValues[exprAttribute]
1788
- );
1749
+ const valueSerialized = this.serializeJSONValue(expressionAttributeValues[exprAttribute]);
1789
1750
  value = value.replace(exprAttribute, `${valueSerialized}`);
1790
1751
  });
1791
1752
  }
@@ -1794,12 +1755,10 @@ var PostgresqlClientService = class extends QueryService {
1794
1755
  replaceExpressionAttributeNames(path, options) {
1795
1756
  const { expressionAttributeNames } = options;
1796
1757
  if (expressionAttributeNames) {
1797
- Object.keys(expressionAttributeNames).forEach(
1798
- (attributeName) => {
1799
- const attributeNameValue = expressionAttributeNames[attributeName];
1800
- path = path.replace(attributeName, attributeNameValue);
1801
- }
1802
- );
1758
+ Object.keys(expressionAttributeNames).forEach((attributeName) => {
1759
+ const attributeNameValue = expressionAttributeNames[attributeName];
1760
+ path = path.replace(attributeName, attributeNameValue);
1761
+ });
1803
1762
  }
1804
1763
  return path;
1805
1764
  }
@@ -1822,24 +1781,27 @@ var PostgresqlClientService = class extends QueryService {
1822
1781
  }
1823
1782
  }
1824
1783
  };
1784
+ __name(_PostgresqlClientService, "PostgresqlClientService");
1785
+ var PostgresqlClientService = _PostgresqlClientService;
1825
1786
 
1826
1787
  // src/services/cruds/postgresql/postgreSqlCrud.service.ts
1827
- var PostgreSqlCrudService = class extends PostgresqlClientService {
1788
+ var _PostgreSqlCrudService = class _PostgreSqlCrudService extends PostgresqlClientService {
1828
1789
  constructor(tableSchema, poolClient) {
1829
1790
  super(tableSchema, poolClient);
1791
+ __publicField(this, "tableSchema");
1830
1792
  this.tableSchema = tableSchema;
1831
1793
  }
1832
1794
  get idColumnName() {
1833
1795
  return findIdColumnName(this.tableSchema.columns);
1834
1796
  }
1835
1797
  normalizeInputData(inputData) {
1836
- var _a;
1798
+ var _a2;
1837
1799
  inputData.qvAttributes = {};
1838
1800
  for (const key in inputData) {
1839
1801
  if (!this.tableSchema.columns[key] && key !== "qvAttributes") {
1840
1802
  inputData.qvAttributes[key] = inputData[key];
1841
1803
  delete inputData[key];
1842
- } else if (Array.isArray(inputData[key]) && ((_a = this.tableSchema.columns[key]) == null ? void 0 : _a.type) !== "array") {
1804
+ } else if (Array.isArray(inputData[key]) && ((_a2 = this.tableSchema.columns[key]) == null ? void 0 : _a2.type) !== "array") {
1843
1805
  inputData[key] = JSON.stringify(inputData[key]);
1844
1806
  }
1845
1807
  }
@@ -1875,9 +1837,9 @@ var PostgreSqlCrudService = class extends PostgresqlClientService {
1875
1837
  });
1876
1838
  } else {
1877
1839
  const inputData = this.prepareData(data);
1878
- return this.createCommand([inputData]).then(
1879
- (result) => result.rowCount ? this.getItem(result.rows[0]) : null
1880
- );
1840
+ return this.createCommand([
1841
+ inputData
1842
+ ]).then((result) => result.rowCount ? this.getItem(result.rows[0]) : null);
1881
1843
  }
1882
1844
  }
1883
1845
  findItem(findOptions) {
@@ -1887,15 +1849,16 @@ var PostgreSqlCrudService = class extends PostgresqlClientService {
1887
1849
  }
1888
1850
  async processQueryResult(findOptions, omitPagination = false) {
1889
1851
  const rows = await this.findCommand(findOptions);
1890
- const items = rows.map(
1891
- (row) => this.getItem(row)
1892
- );
1852
+ const items = rows.map((row) => this.getItem(row));
1893
1853
  const { limit, from } = (findOptions == null ? void 0 : findOptions.pagination) || {};
1894
1854
  const hasMoreRecords = items.length && items.length === limit;
1895
1855
  const newFrom = limit && hasMoreRecords ? limit + (from || 0) : null;
1896
1856
  const result = {
1897
1857
  items,
1898
- pagination: omitPagination ? null : { limit, from: newFrom },
1858
+ pagination: omitPagination ? null : {
1859
+ limit,
1860
+ from: newFrom
1861
+ },
1899
1862
  count: items.length
1900
1863
  };
1901
1864
  return result;
@@ -1908,16 +1871,16 @@ var PostgreSqlCrudService = class extends PostgresqlClientService {
1908
1871
  }
1909
1872
  async findCount(findOptions) {
1910
1873
  const items = await this.findCommand(__spreadProps(__spreadValues({}, findOptions), {
1911
- aggregateFunction: "COUNT" /* COUNT */
1874
+ aggregateFunction: AGGREGATE_FUNCTIONS.COUNT
1912
1875
  }));
1913
- const aggFunctionProperty = buildAggFunctionAlias(
1914
- "COUNT" /* COUNT */
1915
- );
1876
+ const aggFunctionProperty = buildAggFunctionAlias(AGGREGATE_FUNCTIONS.COUNT);
1916
1877
  const item = items.length ? items[0] : {};
1917
1878
  return item[aggFunctionProperty] || 0;
1918
1879
  }
1919
1880
  async update(filters, data, options = {}) {
1920
- const savedRecord = (options == null ? void 0 : options.skipFindItems) ? {} : await this.findItem({ filters });
1881
+ const savedRecord = (options == null ? void 0 : options.skipFindItems) ? {} : await this.findItem({
1882
+ filters
1883
+ });
1921
1884
  const inputData = __spreadValues(__spreadValues({}, savedRecord), data);
1922
1885
  const result = await this.updateCommand(filters, this.prepareData(inputData));
1923
1886
  if (options == null ? void 0 : options.returnRowsAffected) {
@@ -1927,12 +1890,10 @@ var PostgreSqlCrudService = class extends PostgresqlClientService {
1927
1890
  }
1928
1891
  async upsert(keyColumnNames, data) {
1929
1892
  const inputData = this.prepareData(data);
1930
- return this.upsertCommand(keyColumnNames, inputData).then(
1931
- (result) => {
1932
- var _a;
1933
- return result.rowCount && ((_a = result.rows) == null ? void 0 : _a.length) ? this.getItem(result.rows[0]) : null;
1934
- }
1935
- );
1893
+ return this.upsertCommand(keyColumnNames, inputData).then((result) => {
1894
+ var _a2;
1895
+ return result.rowCount && ((_a2 = result.rows) == null ? void 0 : _a2.length) ? this.getItem(result.rows[0]) : null;
1896
+ });
1936
1897
  }
1937
1898
  async remove(filters, options) {
1938
1899
  await this.deleteCommand(filters, options == null ? void 0 : options.filterGroups);
@@ -1941,11 +1902,7 @@ var PostgreSqlCrudService = class extends PostgresqlClientService {
1941
1902
  return super.runQuery(querySentence, values);
1942
1903
  }
1943
1904
  async updateExpressions(filters, actions, options) {
1944
- const result = await this.updateExpressionCommand(
1945
- filters,
1946
- actions,
1947
- options
1948
- );
1905
+ const result = await this.updateExpressionCommand(filters, actions, options);
1949
1906
  return PersistenceErrorWrapper(result);
1950
1907
  }
1951
1908
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -1953,29 +1910,32 @@ var PostgreSqlCrudService = class extends PostgresqlClientService {
1953
1910
  return super.runQuery(query, params);
1954
1911
  }
1955
1912
  };
1913
+ __name(_PostgreSqlCrudService, "PostgreSqlCrudService");
1914
+ var PostgreSqlCrudService = _PostgreSqlCrudService;
1956
1915
 
1957
1916
  // src/services/crudFactory.service.ts
1958
- var CrudFactory = class {
1917
+ var _CrudFactory = class _CrudFactory {
1959
1918
  static databaseClientService(crudSchema, pool) {
1960
- var _a;
1961
- const isMultiPlatformMode2 = ((_a = process.env.PLATFORM_TYPE) == null ? void 0 : _a.toLowerCase()) === "container";
1962
- if (isMultiPlatformMode2)
1963
- return new PostgreSqlCrudService(crudSchema, pool);
1919
+ var _a2;
1920
+ const isMultiPlatformMode2 = ((_a2 = process.env.PLATFORM_TYPE) == null ? void 0 : _a2.toLowerCase()) === "container";
1921
+ if (isMultiPlatformMode2) return new PostgreSqlCrudService(crudSchema, pool);
1964
1922
  return new DynamoDbCrudService(crudSchema);
1965
1923
  }
1966
1924
  };
1925
+ __name(_CrudFactory, "CrudFactory");
1926
+ var CrudFactory = _CrudFactory;
1967
1927
 
1968
1928
  // src/services/crud.service.ts
1969
- var CrudService = class {
1929
+ var _a;
1930
+ var CrudService = (_a = class {
1970
1931
  constructor(crudSchema, pool) {
1932
+ __publicField(this, "pool");
1933
+ __publicField(this, "crudSchema");
1971
1934
  this.pool = pool;
1972
1935
  this.crudSchema = crudSchema;
1973
1936
  }
1974
1937
  async getCrudServiceInstance() {
1975
- const crudService = await CrudFactory.databaseClientService(
1976
- this.crudSchema,
1977
- this.pool
1978
- );
1938
+ const crudService = await CrudFactory.databaseClientService(this.crudSchema, this.pool);
1979
1939
  return crudService;
1980
1940
  }
1981
1941
  getDefaultValue(columnName) {
@@ -1996,45 +1956,29 @@ var CrudService = class {
1996
1956
  }
1997
1957
  create(data) {
1998
1958
  const processedData = Array.isArray(data) ? data.map(this.setDefaultValues.bind(this)) : this.setDefaultValues(data);
1999
- return this.getCrudServiceInstance().then(
2000
- (crudService) => crudService.create(processedData)
2001
- );
1959
+ return this.getCrudServiceInstance().then((crudService) => crudService.create(processedData));
2002
1960
  }
2003
1961
  find(options) {
2004
- return this.getCrudServiceInstance().then(
2005
- (crudService) => crudService.find(options)
2006
- );
1962
+ return this.getCrudServiceInstance().then((crudService) => crudService.find(options));
2007
1963
  }
2008
1964
  findItem(options) {
2009
- return this.getCrudServiceInstance().then(
2010
- (crudService) => crudService.findItem(options)
2011
- );
1965
+ return this.getCrudServiceInstance().then((crudService) => crudService.findItem(options));
2012
1966
  }
2013
1967
  update(filters, data, options = {}) {
2014
- return this.getCrudServiceInstance().then(
2015
- (crudService) => crudService.update(filters, data, options)
2016
- );
1968
+ return this.getCrudServiceInstance().then((crudService) => crudService.update(filters, data, options));
2017
1969
  }
2018
1970
  upsert(keyColumnNames, data) {
2019
- return this.getCrudServiceInstance().then(
2020
- (crudService) => crudService.upsert(keyColumnNames, data)
2021
- );
1971
+ return this.getCrudServiceInstance().then((crudService) => crudService.upsert(keyColumnNames, data));
2022
1972
  }
2023
1973
  remove(filters, options = {}) {
2024
- return this.getCrudServiceInstance().then(
2025
- (crudService) => crudService.remove(filters, options)
2026
- );
1974
+ return this.getCrudServiceInstance().then((crudService) => crudService.remove(filters, options));
2027
1975
  }
2028
1976
  findAll(options) {
2029
- const _a = options, { pagination } = _a, findAllOptions = __objRest(_a, ["pagination"]);
2030
- return this.getCrudServiceInstance().then(
2031
- (crudService) => crudService.findAll(findAllOptions)
2032
- );
1977
+ const _a2 = options, { pagination } = _a2, findAllOptions = __objRest(_a2, ["pagination"]);
1978
+ return this.getCrudServiceInstance().then((crudService) => crudService.findAll(findAllOptions));
2033
1979
  }
2034
1980
  findCount(findCountOptions) {
2035
- return this.getCrudServiceInstance().then(
2036
- (crudService) => crudService.findCount(findCountOptions)
2037
- );
1981
+ return this.getCrudServiceInstance().then((crudService) => crudService.findCount(findCountOptions));
2038
1982
  }
2039
1983
  buildFilter(attribute, value, operator = "EQUAL", relativePath = void 0) {
2040
1984
  return buildFilter(attribute, value, operator, relativePath);
@@ -2046,32 +1990,25 @@ var CrudService = class {
2046
1990
  return buildSort(column, direction);
2047
1991
  }
2048
1992
  updateExpression(filters, actions, options) {
2049
- return this.getCrudServiceInstance().then(
2050
- (crudService) => crudService.updateExpressions(filters, actions, options)
2051
- );
1993
+ return this.getCrudServiceInstance().then((crudService) => crudService.updateExpressions(filters, actions, options));
2052
1994
  }
2053
1995
  runRawQuery(query, params) {
2054
- return this.getCrudServiceInstance().then(
2055
- (crudService) => crudService.runRawQuery(query, params)
2056
- );
1996
+ return this.getCrudServiceInstance().then((crudService) => crudService.runRawQuery(query, params));
2057
1997
  }
2058
- };
1998
+ }, __name(_a, "CrudService"), _a);
2059
1999
  var crud_service_default = CrudService;
2060
2000
 
2061
2001
  // src/schemas/crudSchema.ts
2062
- var CrudSchema = class {
2002
+ var _CrudSchema = class _CrudSchema {
2063
2003
  };
2064
- CrudSchema.usePool = false;
2065
- CrudSchema.schema = null;
2066
- CrudSchema.isTemporalTable = false;
2067
-
2068
- // src/types/filterLogicOperator.type.ts
2069
- Object.values(
2070
- FILTER_LOGIC_OPERATORS
2071
- );
2072
-
2073
- // src/types/connectionClosingMode.type.ts
2074
- Object.values(CONNECTION_CLOSING_MODES);
2004
+ __name(_CrudSchema, "CrudSchema");
2005
+ __publicField(_CrudSchema, "table");
2006
+ __publicField(_CrudSchema, "columns");
2007
+ __publicField(_CrudSchema, "usePool", false);
2008
+ __publicField(_CrudSchema, "schema", null);
2009
+ __publicField(_CrudSchema, "poolClient");
2010
+ __publicField(_CrudSchema, "isTemporalTable", false);
2011
+ var CrudSchema = _CrudSchema;
2075
2012
  var DEFAULT_DB_POOL_CONFIG = {
2076
2013
  max: 20,
2077
2014
  connectionTimeoutMillis: 10 * 1e3,
@@ -2086,14 +2023,13 @@ function getDbPool(poolConfig) {
2086
2023
  }), poolConfig));
2087
2024
  registerPool(pool);
2088
2025
  pool.on("error", (error) => {
2089
- console.error(
2090
- "[data-persistence] Unexpected PG pool error on idle client",
2091
- error
2092
- );
2026
+ const serviceName = process.env.SERVICE_NAME ? `[${process.env.SERVICE_NAME}/data-persistence]` : "[data-persistence]";
2027
+ console.error(`${serviceName} Unexpected PG pool error on idle client`, error);
2093
2028
  });
2094
2029
  return pool;
2095
2030
  }
2031
+ __name(getDbPool, "getDbPool");
2096
2032
 
2097
- export { CrudSchema, crud_service_default as CrudService, DEFAULT_DB_POOL_CONFIG, buildFilter, buildQueryIndex, buildSort, closeAllClients, closeAllPools, getDbPool };
2033
+ export { CrudSchema, crud_service_default as CrudService, DEFAULT_DB_POOL_CONFIG, buildFilter, buildQueryIndex, buildSort, closeAllClients, closeAllPools, getDbPool, shutdown };
2098
2034
  //# sourceMappingURL=index.mjs.map
2099
2035
  //# sourceMappingURL=index.mjs.map