@qrvey/data-persistence 0.3.6-beta.2 → 0.3.6-bundle
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/services/crud.service.js +1 -1
- package/dist/cjs/services/crud.service.js.map +1 -1
- package/dist/cjs/services/crudFactory.service.js +5 -34
- package/dist/cjs/services/crudFactory.service.js.map +1 -1
- package/dist/cjs/services/cruds/index.js +19 -0
- package/dist/cjs/services/cruds/index.js.map +1 -0
- package/dist/esm/index.mjs +1703 -14
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +3 -17
- package/dist/esm/chunk-6MOAJFFY.mjs +0 -112
- package/dist/esm/chunk-6MOAJFFY.mjs.map +0 -1
- package/dist/esm/chunk-DHIGNHXS.mjs +0 -58
- package/dist/esm/chunk-DHIGNHXS.mjs.map +0 -1
- package/dist/esm/dynamoDbCrud.service-EFYPBZKN.mjs +0 -818
- package/dist/esm/dynamoDbCrud.service-EFYPBZKN.mjs.map +0 -1
- package/dist/esm/postgreSqlCrud.service-GXH7ZQZY.mjs +0 -730
- package/dist/esm/postgreSqlCrud.service-GXH7ZQZY.mjs.map +0 -1
package/dist/esm/index.mjs
CHANGED
|
@@ -1,5 +1,116 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
2
|
+
import { DynamoDBDocumentClient, GetCommand, QueryCommand, ScanCommand, PutCommand, UpdateCommand, DeleteCommand, BatchWriteCommand } from '@aws-sdk/lib-dynamodb';
|
|
3
|
+
import format from 'pg-format';
|
|
4
|
+
import { Pool, Client } from 'pg';
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __defProps = Object.defineProperties;
|
|
8
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
9
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __objRest = (source, exclude) => {
|
|
26
|
+
var target = {};
|
|
27
|
+
for (var prop in source)
|
|
28
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
if (source != null && __getOwnPropSymbols)
|
|
31
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
+
target[prop] = source[prop];
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
37
|
+
var __accessCheck = (obj, member, msg) => {
|
|
38
|
+
if (!member.has(obj))
|
|
39
|
+
throw TypeError("Cannot " + msg);
|
|
40
|
+
};
|
|
41
|
+
var __privateAdd = (obj, member, value) => {
|
|
42
|
+
if (member.has(obj))
|
|
43
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
44
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
45
|
+
};
|
|
46
|
+
var __privateMethod = (obj, member, method) => {
|
|
47
|
+
__accessCheck(obj, member, "access private method");
|
|
48
|
+
return method;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/utils/constants.ts
|
|
52
|
+
var FILTER_OPERATOR_MAP = {
|
|
53
|
+
CONTAINS: "contains",
|
|
54
|
+
NOT_CONTAINS: "notContains",
|
|
55
|
+
EQUAL: "eq",
|
|
56
|
+
STARTS_WITH: "beginsWith",
|
|
57
|
+
NOT_EQUAL: "notEq",
|
|
58
|
+
IN: "in",
|
|
59
|
+
GREATER_THAN: "gt",
|
|
60
|
+
GT: "gt",
|
|
61
|
+
GREATER_THAN_EQUAL: "gte",
|
|
62
|
+
GTE: "gte",
|
|
63
|
+
LESS_THAN: "lt",
|
|
64
|
+
LT: "lt",
|
|
65
|
+
LESS_THAN_EQUAL: "lte",
|
|
66
|
+
LTE: "lte",
|
|
67
|
+
EXIST: "attribute_exists",
|
|
68
|
+
NOT_EXIST: "attribute_not_exists",
|
|
69
|
+
BETWEEN: "between"
|
|
70
|
+
};
|
|
71
|
+
var DYNAMODB_OPERATORS = {
|
|
72
|
+
EQUAL: "EQUAL"
|
|
73
|
+
};
|
|
74
|
+
var CONNECTION_CLOSING_MODES = /* @__PURE__ */ ((CONNECTION_CLOSING_MODES2) => {
|
|
75
|
+
CONNECTION_CLOSING_MODES2["AUTO"] = "AUTO";
|
|
76
|
+
CONNECTION_CLOSING_MODES2["MANUAL"] = "MANUAL";
|
|
77
|
+
return CONNECTION_CLOSING_MODES2;
|
|
78
|
+
})(CONNECTION_CLOSING_MODES || {});
|
|
79
|
+
var FILTER_LOGIC_OPERATORS = /* @__PURE__ */ ((FILTER_LOGIC_OPERATORS2) => {
|
|
80
|
+
FILTER_LOGIC_OPERATORS2["AND"] = "AND";
|
|
81
|
+
FILTER_LOGIC_OPERATORS2["OR"] = "OR";
|
|
82
|
+
return FILTER_LOGIC_OPERATORS2;
|
|
83
|
+
})(FILTER_LOGIC_OPERATORS || {});
|
|
84
|
+
var POSTGRES_FILTER_OPERATOR_MAP = {
|
|
85
|
+
EQUAL: "=",
|
|
86
|
+
NOT_EQUAL: "<>",
|
|
87
|
+
GREATER_THAN: ">",
|
|
88
|
+
GT: ">",
|
|
89
|
+
GTE: ">=",
|
|
90
|
+
GREATER_THAN_EQUAL: ">=",
|
|
91
|
+
LTE: "<=",
|
|
92
|
+
LESS_THAN_EQUAL: "<=",
|
|
93
|
+
LESS_THAN: "<",
|
|
94
|
+
LT: "<",
|
|
95
|
+
IN: "IN",
|
|
96
|
+
STARTS_WITH: "LIKE",
|
|
97
|
+
CONTAINS: "LIKE",
|
|
98
|
+
NOT_CONTAINS: "NOT LIKE",
|
|
99
|
+
BETWEEN: "BETWEEN",
|
|
100
|
+
EXIST: "IS NOT NULL",
|
|
101
|
+
NOT_EXIST: "IS NULL"
|
|
102
|
+
};
|
|
103
|
+
var DEFAULT_PG_SCHEMA = "public";
|
|
104
|
+
var DYNAMO_DB_UPDATE_ACTIONS = {
|
|
105
|
+
SET: "SET",
|
|
106
|
+
ADD: "ADD",
|
|
107
|
+
DELETE: "DELETE",
|
|
108
|
+
REMOVE: "REMOVE"
|
|
109
|
+
};
|
|
110
|
+
function isMultiPlatformMode() {
|
|
111
|
+
var _a;
|
|
112
|
+
return ((_a = process.env.PLATFORM_TYPE) == null ? void 0 : _a.toLowerCase()) === "container";
|
|
113
|
+
}
|
|
3
114
|
|
|
4
115
|
// src/helpers/crudHelpers.ts
|
|
5
116
|
function buildFilter(attribute, value, operator = "EQUAL") {
|
|
@@ -21,21 +132,1600 @@ function buildSort(column, direction = "ASC" /* ASC */) {
|
|
|
21
132
|
direction
|
|
22
133
|
};
|
|
23
134
|
}
|
|
135
|
+
var AWS_REGION = process.env.AWS_DEFAULT_REGION;
|
|
136
|
+
var DynamoDbClientService = class {
|
|
137
|
+
constructor(tableName) {
|
|
138
|
+
if (!tableName)
|
|
139
|
+
throw new Error(
|
|
140
|
+
'The "tableName" is required to use a DynamoDbClientService.'
|
|
141
|
+
);
|
|
142
|
+
this.tableName = tableName;
|
|
143
|
+
const client = new DynamoDBClient({ region: AWS_REGION });
|
|
144
|
+
this.dynamoDBClient = DynamoDBDocumentClient.from(client, {
|
|
145
|
+
marshallOptions: {
|
|
146
|
+
removeUndefinedValues: true
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get an item by key
|
|
152
|
+
* @param {Object} keyObject - Ex: { jobId: 1234 }
|
|
153
|
+
* @param {GetCommandInput} options
|
|
154
|
+
*/
|
|
155
|
+
async getByKey(keyObject, options = {}) {
|
|
156
|
+
const params = __spreadValues({
|
|
157
|
+
TableName: this.tableName,
|
|
158
|
+
Key: keyObject
|
|
159
|
+
}, options);
|
|
160
|
+
const result = await this.dynamoDBClient.send(new GetCommand(params));
|
|
161
|
+
return result.Item;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Query a table
|
|
165
|
+
* @param {QueryCommandInput} options
|
|
166
|
+
*/
|
|
167
|
+
async query(options = {}) {
|
|
168
|
+
const params = __spreadValues({
|
|
169
|
+
TableName: this.tableName
|
|
170
|
+
}, options);
|
|
171
|
+
const result = await this.dynamoDBClient.send(new QueryCommand(params));
|
|
172
|
+
if (result.$metadata)
|
|
173
|
+
delete result.$metadata;
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Scan a table
|
|
178
|
+
* @param {ScanInput} options
|
|
179
|
+
*/
|
|
180
|
+
async scan(input) {
|
|
181
|
+
const params = __spreadProps(__spreadValues({}, input), {
|
|
182
|
+
TableName: this.tableName
|
|
183
|
+
});
|
|
184
|
+
const command = new ScanCommand(params);
|
|
185
|
+
const response = await this.dynamoDBClient.send(command);
|
|
186
|
+
if (response.$metadata)
|
|
187
|
+
delete response.$metadata;
|
|
188
|
+
return response;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Create/Replace a item object
|
|
192
|
+
* To take care:
|
|
193
|
+
* - https://stackoverflow.com/questions/43667229/difference-between-dynamodb-putitem-vs-updateitem
|
|
194
|
+
* @param {Object} input
|
|
195
|
+
*/
|
|
196
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
197
|
+
async put(input) {
|
|
198
|
+
const params = {
|
|
199
|
+
TableName: this.tableName,
|
|
200
|
+
Item: input,
|
|
201
|
+
ReturnValues: "NONE"
|
|
202
|
+
};
|
|
203
|
+
return await this.dynamoDBClient.send(new PutCommand(params));
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Update a item object
|
|
207
|
+
* To take care:
|
|
208
|
+
* - https://stackoverflow.com/questions/43667229/difference-between-dynamodb-putitem-vs-updateitem
|
|
209
|
+
* @param {Object} keyObject - Ex: { jobId: 1234 }
|
|
210
|
+
* @param {UpdateCommandInput} updateObject
|
|
211
|
+
*/
|
|
212
|
+
async update(keyObject, options = {}) {
|
|
213
|
+
const params = __spreadValues({
|
|
214
|
+
TableName: this.tableName,
|
|
215
|
+
Key: keyObject,
|
|
216
|
+
ReturnValues: "NONE"
|
|
217
|
+
}, options);
|
|
218
|
+
return await this.dynamoDBClient.send(new UpdateCommand(params));
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Delete/Remove an item object
|
|
222
|
+
*/
|
|
223
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
224
|
+
async remove(keyObject) {
|
|
225
|
+
const params = {
|
|
226
|
+
TableName: this.tableName,
|
|
227
|
+
Key: keyObject,
|
|
228
|
+
ReturnValues: "NONE"
|
|
229
|
+
};
|
|
230
|
+
return await this.dynamoDBClient.send(new DeleteCommand(params));
|
|
231
|
+
}
|
|
232
|
+
batchWrittenPut(data) {
|
|
233
|
+
const putRequests = data.map((item) => ({
|
|
234
|
+
PutRequest: {
|
|
235
|
+
Item: item
|
|
236
|
+
}
|
|
237
|
+
}));
|
|
238
|
+
const params = {
|
|
239
|
+
RequestItems: {
|
|
240
|
+
[this.tableName]: putRequests
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
const insertCommand = new BatchWriteCommand(params);
|
|
244
|
+
return this.dynamoDBClient.send(insertCommand);
|
|
245
|
+
}
|
|
246
|
+
buildDeleteRequestKeys(filters) {
|
|
247
|
+
const deleteRequestKeys = {};
|
|
248
|
+
filters.forEach((filter) => {
|
|
249
|
+
deleteRequestKeys[filter.attribute] = filter.value;
|
|
250
|
+
});
|
|
251
|
+
return deleteRequestKeys;
|
|
252
|
+
}
|
|
253
|
+
async batchRemove(filterGroups) {
|
|
254
|
+
if (!(filterGroups == null ? void 0 : filterGroups.length))
|
|
255
|
+
return;
|
|
256
|
+
const deleteRequests = filterGroups.map((filterGroup) => ({
|
|
257
|
+
DeleteRequest: {
|
|
258
|
+
Key: this.buildDeleteRequestKeys(filterGroup)
|
|
259
|
+
}
|
|
260
|
+
}));
|
|
261
|
+
const params = {
|
|
262
|
+
RequestItems: {
|
|
263
|
+
[this.tableName]: deleteRequests
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
await this.dynamoDBClient.send(new BatchWriteCommand(params));
|
|
267
|
+
}
|
|
268
|
+
async updateExpressions(keyObject, options = {}) {
|
|
269
|
+
const params = __spreadValues({
|
|
270
|
+
TableName: this.tableName,
|
|
271
|
+
Key: keyObject
|
|
272
|
+
}, options);
|
|
273
|
+
return await this.dynamoDBClient.send(new UpdateCommand(params));
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
// src/helpers/queryHelpers.ts
|
|
278
|
+
function buildAggFunctionAlias(aggregateFunction) {
|
|
279
|
+
return `AGG_FN_${aggregateFunction}`;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// src/services/cruds/dynamodb/queryBuilderCondition.service.ts
|
|
283
|
+
var QueryBuilderConditionService = class {
|
|
284
|
+
constructor(query) {
|
|
285
|
+
this.tempKey = "";
|
|
286
|
+
this.tempLogicOperator = null;
|
|
287
|
+
this.wheres = [];
|
|
288
|
+
this.filters = [];
|
|
289
|
+
this.updates = [];
|
|
290
|
+
this.attributeNames = {};
|
|
291
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
292
|
+
this.attributeValues = {};
|
|
293
|
+
this.query = query;
|
|
294
|
+
this.command = {};
|
|
295
|
+
}
|
|
296
|
+
get() {
|
|
297
|
+
this.build();
|
|
298
|
+
return this.command;
|
|
299
|
+
}
|
|
300
|
+
setKey(key) {
|
|
301
|
+
this.tempKey = key;
|
|
302
|
+
return this;
|
|
303
|
+
}
|
|
304
|
+
setTmpLogicOp(logicOp) {
|
|
305
|
+
this.tempLogicOperator = logicOp;
|
|
306
|
+
return this;
|
|
307
|
+
}
|
|
308
|
+
setConfig(config) {
|
|
309
|
+
this.config = config;
|
|
310
|
+
return this;
|
|
311
|
+
}
|
|
312
|
+
from(methodName) {
|
|
313
|
+
this.queryFrom = methodName;
|
|
314
|
+
return this;
|
|
315
|
+
}
|
|
316
|
+
eq(keyValue) {
|
|
317
|
+
const { key, value } = this.generateKeyValue(keyValue);
|
|
318
|
+
let expression = `${key} = ${value}`;
|
|
319
|
+
if (this.tempLogicOperator)
|
|
320
|
+
expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
|
|
321
|
+
this.setExpression(expression);
|
|
322
|
+
return this.query;
|
|
323
|
+
}
|
|
324
|
+
notEq(keyValue) {
|
|
325
|
+
const { key, value } = this.generateKeyValue(keyValue);
|
|
326
|
+
let expression = `${key} <> ${value}`;
|
|
327
|
+
if (this.tempLogicOperator)
|
|
328
|
+
expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
|
|
329
|
+
this.setExpression(expression);
|
|
330
|
+
return this.query;
|
|
331
|
+
}
|
|
332
|
+
contains(keyValue) {
|
|
333
|
+
const { key, value } = this.generateKeyValue(keyValue);
|
|
334
|
+
let expression = `contains(${key}, ${value})`;
|
|
335
|
+
if (this.tempLogicOperator)
|
|
336
|
+
expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
|
|
337
|
+
this.setExpression(expression);
|
|
338
|
+
return this.query;
|
|
339
|
+
}
|
|
340
|
+
notContains(keyValue) {
|
|
341
|
+
const { key, value } = this.generateKeyValue(keyValue);
|
|
342
|
+
let expression = `NOT contains(${key}, ${value})`;
|
|
343
|
+
if (this.tempLogicOperator)
|
|
344
|
+
expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
|
|
345
|
+
this.setExpression(expression);
|
|
346
|
+
return this.query;
|
|
347
|
+
}
|
|
348
|
+
in(keyValue) {
|
|
349
|
+
const keyValues = Array.isArray(keyValue) ? keyValue : [keyValue];
|
|
350
|
+
const { key, value } = this.generateKeyValue(keyValues);
|
|
351
|
+
let expression = `${key} IN (${value})`;
|
|
352
|
+
if (this.tempLogicOperator)
|
|
353
|
+
expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
|
|
354
|
+
this.setExpression(expression);
|
|
355
|
+
return this.query;
|
|
356
|
+
}
|
|
357
|
+
beginsWith(keyValue) {
|
|
358
|
+
const { key, value } = this.generateKeyValue(keyValue);
|
|
359
|
+
let expression = `begins_with(${key}, ${value})`;
|
|
360
|
+
if (this.tempLogicOperator)
|
|
361
|
+
expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
|
|
362
|
+
this.setExpression(expression);
|
|
363
|
+
return this.query;
|
|
364
|
+
}
|
|
365
|
+
project(keyValue) {
|
|
366
|
+
const key = `#${keyValue}`;
|
|
367
|
+
this.attributeNames[key] = keyValue;
|
|
368
|
+
return key;
|
|
369
|
+
}
|
|
370
|
+
gt(keyValue) {
|
|
371
|
+
const { key, value } = this.generateKeyValue(keyValue);
|
|
372
|
+
let expression = `${key} > ${value}`;
|
|
373
|
+
if (this.tempLogicOperator)
|
|
374
|
+
expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
|
|
375
|
+
this.setExpression(expression);
|
|
376
|
+
return this.query;
|
|
377
|
+
}
|
|
378
|
+
gte(keyValue) {
|
|
379
|
+
const { key, value } = this.generateKeyValue(keyValue);
|
|
380
|
+
let expression = `${key} >= ${value}`;
|
|
381
|
+
if (this.tempLogicOperator)
|
|
382
|
+
expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
|
|
383
|
+
this.setExpression(expression);
|
|
384
|
+
return this.query;
|
|
385
|
+
}
|
|
386
|
+
lte(keyValue) {
|
|
387
|
+
const { key, value } = this.generateKeyValue(keyValue);
|
|
388
|
+
let expression = `${key} <= ${value}`;
|
|
389
|
+
if (this.tempLogicOperator)
|
|
390
|
+
expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
|
|
391
|
+
this.setExpression(expression);
|
|
392
|
+
return this.query;
|
|
393
|
+
}
|
|
394
|
+
lt(keyValue) {
|
|
395
|
+
const { key, value } = this.generateKeyValue(keyValue);
|
|
396
|
+
let expression = `${key} < ${value}`;
|
|
397
|
+
if (this.tempLogicOperator)
|
|
398
|
+
expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
|
|
399
|
+
this.setExpression(expression);
|
|
400
|
+
return this.query;
|
|
401
|
+
}
|
|
402
|
+
attribute_exists(keyValue) {
|
|
403
|
+
const { key } = this.generateKeyValue(keyValue, null, true);
|
|
404
|
+
let expression = `attribute_exists(${key})`;
|
|
405
|
+
if (this.tempLogicOperator)
|
|
406
|
+
expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
|
|
407
|
+
this.setExpression(expression);
|
|
408
|
+
return this.query;
|
|
409
|
+
}
|
|
410
|
+
attribute_not_exists(keyValue) {
|
|
411
|
+
const { key } = this.generateKeyValue(keyValue, null, true);
|
|
412
|
+
let expression = `attribute_not_exists(${key})`;
|
|
413
|
+
if (this.tempLogicOperator)
|
|
414
|
+
expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
|
|
415
|
+
this.setExpression(expression);
|
|
416
|
+
return this.query;
|
|
417
|
+
}
|
|
418
|
+
between(keyValues) {
|
|
419
|
+
const isValidValues = Array.isArray(keyValues) && (keyValues == null ? void 0 : keyValues.length) === 2;
|
|
420
|
+
if (!isValidValues)
|
|
421
|
+
throw new Error(
|
|
422
|
+
"The value for between filter operator should be an Array with 2 values."
|
|
423
|
+
);
|
|
424
|
+
const { key, value } = this.generateKeyValue(keyValues, " AND");
|
|
425
|
+
let expression = `${key} between ${value}`;
|
|
426
|
+
if (this.tempLogicOperator)
|
|
427
|
+
expression = { expression, logicOperator: this.tempLogicOperator, config: this.config };
|
|
428
|
+
this.setExpression(expression);
|
|
429
|
+
return this.query;
|
|
430
|
+
}
|
|
431
|
+
setExpression(expression) {
|
|
432
|
+
switch (this.queryFrom) {
|
|
433
|
+
case "filter" /* filter */:
|
|
434
|
+
this.filters.push(expression);
|
|
435
|
+
break;
|
|
436
|
+
case "update" /* update */:
|
|
437
|
+
this.updates.push(expression);
|
|
438
|
+
break;
|
|
439
|
+
default:
|
|
440
|
+
this.wheres.push(expression);
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
generateKeyValue(value, separatorCharacter = ",", omitAttributeValues = false) {
|
|
445
|
+
const keyExpression = `#${this.tempKey}1`;
|
|
446
|
+
this.attributeNames[keyExpression] = this.tempKey;
|
|
447
|
+
if (Array.isArray(value)) {
|
|
448
|
+
const valueExpressions = value.map((val, index) => {
|
|
449
|
+
let valueExpression = `:${this.tempKey}${index + 1}1`;
|
|
450
|
+
for (const [i] of Object.entries(this.attributeValues)) {
|
|
451
|
+
if (i === valueExpression)
|
|
452
|
+
valueExpression += "1";
|
|
453
|
+
}
|
|
454
|
+
this.attributeValues[valueExpression] = val;
|
|
455
|
+
return valueExpression;
|
|
456
|
+
});
|
|
457
|
+
return {
|
|
458
|
+
key: keyExpression,
|
|
459
|
+
value: valueExpressions.join(`${separatorCharacter} `)
|
|
460
|
+
};
|
|
461
|
+
} else {
|
|
462
|
+
let valueExpression = `:${this.tempKey}1`;
|
|
463
|
+
if (valueExpression in this.attributeValues) {
|
|
464
|
+
for (const [index] of Object.entries(this.attributeValues)) {
|
|
465
|
+
if (index === valueExpression)
|
|
466
|
+
valueExpression += "1";
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
if (!omitAttributeValues)
|
|
470
|
+
this.attributeValues[valueExpression] = value;
|
|
471
|
+
return { key: keyExpression, value: valueExpression };
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
build() {
|
|
475
|
+
var _a;
|
|
476
|
+
if (this.wheres.length > 0) {
|
|
477
|
+
const keyConditionExpression = this.wheres.join(" AND ");
|
|
478
|
+
this.command["KeyConditionExpression"] = keyConditionExpression;
|
|
479
|
+
}
|
|
480
|
+
if (this.filters.length > 0) {
|
|
481
|
+
let filterExpression = "";
|
|
482
|
+
(_a = this.filters) == null ? void 0 : _a.forEach((filter, index) => {
|
|
483
|
+
var _a2, _b;
|
|
484
|
+
if (filter == null ? void 0 : filter.logicOperator) {
|
|
485
|
+
if ((_a2 = filter == null ? void 0 : filter.config) == null ? void 0 : _a2.openExpression) {
|
|
486
|
+
filterExpression = filterExpression.replace(/\s+(AND|OR)\s*$/, ` ${filter.config.parentKey} (`);
|
|
487
|
+
if (filterExpression === "")
|
|
488
|
+
filterExpression += "(";
|
|
489
|
+
filterExpression += `${filter.expression} ${filter.logicOperator} `;
|
|
490
|
+
} else if ((_b = filter == null ? void 0 : filter.config) == null ? void 0 : _b.closeExpression) {
|
|
491
|
+
filterExpression += `${filter.expression}) ${filter.config.parentKey} `;
|
|
492
|
+
} else {
|
|
493
|
+
filterExpression += `${filter.expression} ${filter.logicOperator} `;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
filterExpression = filterExpression.replace(/\s+(AND|OR)\s*$/, "");
|
|
498
|
+
this.command["FilterExpression"] = filterExpression;
|
|
499
|
+
}
|
|
500
|
+
if (this.updates.length > 0) {
|
|
501
|
+
const filterExpression = this.updates.join(", ");
|
|
502
|
+
this.command["UpdateExpression"] = `SET ${filterExpression}`;
|
|
503
|
+
}
|
|
504
|
+
if (Object.values(this.attributeNames).length > 0)
|
|
505
|
+
this.command["ExpressionAttributeNames"] = this.attributeNames;
|
|
506
|
+
if (Object.values(this.attributeValues).length > 0)
|
|
507
|
+
this.command["ExpressionAttributeValues"] = this.attributeValues;
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
// src/services/cruds/dynamodb/queryBuilder.service.ts
|
|
512
|
+
var QueryBuilderService = class {
|
|
513
|
+
constructor(useScan = false) {
|
|
514
|
+
this.useScan = useScan;
|
|
515
|
+
this.command = {};
|
|
516
|
+
this.condition = new QueryBuilderConditionService(this);
|
|
517
|
+
}
|
|
518
|
+
get() {
|
|
519
|
+
const condition = this.condition.get();
|
|
520
|
+
return __spreadValues(__spreadValues({}, this.command), condition);
|
|
521
|
+
}
|
|
522
|
+
limit(num) {
|
|
523
|
+
this.command.Limit = num;
|
|
524
|
+
return this;
|
|
525
|
+
}
|
|
526
|
+
usingIndex(indexName) {
|
|
527
|
+
this.command.IndexName = indexName;
|
|
528
|
+
return this;
|
|
529
|
+
}
|
|
530
|
+
ascending() {
|
|
531
|
+
if (!this.useScan)
|
|
532
|
+
this.command.ScanIndexForward = true;
|
|
533
|
+
return this;
|
|
534
|
+
}
|
|
535
|
+
descending() {
|
|
536
|
+
if (!this.useScan)
|
|
537
|
+
this.command.ScanIndexForward = false;
|
|
538
|
+
return this;
|
|
539
|
+
}
|
|
540
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
541
|
+
startKey(lastEvaluatedKey) {
|
|
542
|
+
this.command.ExclusiveStartKey = lastEvaluatedKey;
|
|
543
|
+
return this;
|
|
544
|
+
}
|
|
545
|
+
projection(fields = []) {
|
|
546
|
+
if (!fields.length)
|
|
547
|
+
return this;
|
|
548
|
+
const expression = [];
|
|
549
|
+
fields.forEach((field) => {
|
|
550
|
+
const key = this.condition.project(field);
|
|
551
|
+
expression.push(key);
|
|
552
|
+
});
|
|
553
|
+
this.command.ProjectionExpression = expression.join(",");
|
|
554
|
+
return this;
|
|
555
|
+
}
|
|
556
|
+
where(keyName) {
|
|
557
|
+
this.condition.setKey(keyName).setTmpLogicOp(null).from("where" /* where */);
|
|
558
|
+
return this.condition;
|
|
559
|
+
}
|
|
560
|
+
filter(keyName, logicOperator = "AND", config) {
|
|
561
|
+
this.condition.setKey(keyName).setTmpLogicOp(logicOperator).setConfig(config).from("filter" /* filter */);
|
|
562
|
+
return this.condition;
|
|
563
|
+
}
|
|
564
|
+
update(attribute) {
|
|
565
|
+
for (const [key, value] of Object.entries(attribute)) {
|
|
566
|
+
this.condition.setKey(key).from("update" /* update */);
|
|
567
|
+
this.condition.eq(value);
|
|
568
|
+
}
|
|
569
|
+
return this;
|
|
570
|
+
}
|
|
571
|
+
consistentRead(consistentRead) {
|
|
572
|
+
this.command.ConsistentRead = consistentRead;
|
|
573
|
+
return this;
|
|
574
|
+
}
|
|
575
|
+
count() {
|
|
576
|
+
this.command.Select = "COUNT" /* COUNT */;
|
|
577
|
+
return this;
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
// src/helpers/tableHelper.ts
|
|
582
|
+
function getTableColumnNames(columns) {
|
|
583
|
+
return Object.keys(columns);
|
|
584
|
+
}
|
|
585
|
+
function findIdColumnName(columns) {
|
|
586
|
+
return getTableColumnNames(columns).find(
|
|
587
|
+
(columnName) => columns[columnName].columnId === true
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
function getTableName(table, property = "name") {
|
|
591
|
+
if (!table)
|
|
592
|
+
throw new Error("missing table property");
|
|
593
|
+
if (typeof table === "string")
|
|
594
|
+
return table;
|
|
595
|
+
const { name, alias } = table;
|
|
596
|
+
return property === "alias" && alias ? alias : name;
|
|
597
|
+
}
|
|
598
|
+
function getPrimaryKeyColumns(columns) {
|
|
599
|
+
return getTableColumnNames(columns).filter(
|
|
600
|
+
(columnName) => columns[columnName].primary === true
|
|
601
|
+
);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// src/error/NoRecordsAffectedException.ts
|
|
605
|
+
var NoRecordsAffectedException = class extends Error {
|
|
606
|
+
constructor() {
|
|
607
|
+
super("No records affected by update");
|
|
608
|
+
this.name = "NoRecordsAffectedException";
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
// src/helpers/errorHelper.ts
|
|
613
|
+
function PersistenceErrorWrapper(queryResult) {
|
|
614
|
+
const dynamoNoRecordsAffectedExceptions = [
|
|
615
|
+
"ConditionalCheckFailedException"
|
|
616
|
+
];
|
|
617
|
+
if (queryResult instanceof Error) {
|
|
618
|
+
if (queryResult.name && dynamoNoRecordsAffectedExceptions.includes(queryResult.name)) {
|
|
619
|
+
throw new NoRecordsAffectedException();
|
|
620
|
+
} else {
|
|
621
|
+
throw queryResult;
|
|
622
|
+
}
|
|
623
|
+
} else {
|
|
624
|
+
if (queryResult.rowCount === 0) {
|
|
625
|
+
throw new NoRecordsAffectedException();
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
return queryResult;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// src/services/cruds/dynamodb/dynamoDbCrud.service.ts
|
|
632
|
+
var _prepareAndExecuteUpdateExpression, prepareAndExecuteUpdateExpression_fn, _buildUpdateExpressionQuery, buildUpdateExpressionQuery_fn, _getKeyObjectForUpdateExpression, getKeyObjectForUpdateExpression_fn, _getUpdateExpressionOptions, getUpdateExpressionOptions_fn, _extractUpdateExpressionAttributesAndNames, extractUpdateExpressionAttributesAndNames_fn;
|
|
633
|
+
var DynamoDbCrudService = class {
|
|
634
|
+
constructor(tableSchema) {
|
|
635
|
+
this.tableSchema = tableSchema;
|
|
636
|
+
__privateAdd(this, _prepareAndExecuteUpdateExpression);
|
|
637
|
+
__privateAdd(this, _buildUpdateExpressionQuery);
|
|
638
|
+
__privateAdd(this, _getKeyObjectForUpdateExpression);
|
|
639
|
+
__privateAdd(this, _getUpdateExpressionOptions);
|
|
640
|
+
__privateAdd(this, _extractUpdateExpressionAttributesAndNames);
|
|
641
|
+
this.dynamoDbClientService = new DynamoDbClientService(this.tableName);
|
|
642
|
+
}
|
|
643
|
+
get tableName() {
|
|
644
|
+
return getTableName(this.tableSchema.table);
|
|
645
|
+
}
|
|
646
|
+
get idColumnName() {
|
|
647
|
+
return findIdColumnName(this.tableSchema.columns);
|
|
648
|
+
}
|
|
649
|
+
get defaultPrimaryKeys() {
|
|
650
|
+
return getPrimaryKeyColumns(this.tableSchema.columns);
|
|
651
|
+
}
|
|
652
|
+
async create(data) {
|
|
653
|
+
var _a;
|
|
654
|
+
if (Array.isArray(data)) {
|
|
655
|
+
const response = await this.dynamoDbClientService.batchWrittenPut(data);
|
|
656
|
+
return {
|
|
657
|
+
unprocessedItems: (_a = response.UnprocessedItems) != null ? _a : []
|
|
658
|
+
};
|
|
659
|
+
} else {
|
|
660
|
+
await this.dynamoDbClientService.put(data);
|
|
661
|
+
return data;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
|
|
665
|
+
runQuery(queryCommand) {
|
|
666
|
+
throw new Error("Method not implemented.");
|
|
667
|
+
}
|
|
668
|
+
find(options = {}) {
|
|
669
|
+
var _a, _b, _c, _d;
|
|
670
|
+
const query = new QueryBuilderService(options.useScan);
|
|
671
|
+
if ((_a = options.index) == null ? void 0 : _a.indexName)
|
|
672
|
+
query.usingIndex((_b = options.index) == null ? void 0 : _b.indexName);
|
|
673
|
+
this.applySorting(query, options.sorting, (_c = options.index) == null ? void 0 : _c.indexName);
|
|
674
|
+
this.applyPagination(query, options.pagination);
|
|
675
|
+
if (options.consistentRead)
|
|
676
|
+
query.consistentRead(options.consistentRead);
|
|
677
|
+
if (options.fields)
|
|
678
|
+
query.projection(options.fields);
|
|
679
|
+
this.applyFilters(query, options);
|
|
680
|
+
if (options.aggregateFunction === "COUNT" /* COUNT */)
|
|
681
|
+
query.count();
|
|
682
|
+
return this.fetchResults(
|
|
683
|
+
query.get(),
|
|
684
|
+
(_d = options.pagination) == null ? void 0 : _d.limit,
|
|
685
|
+
options.useScan
|
|
686
|
+
).then((res) => {
|
|
687
|
+
var _a2, _b2;
|
|
688
|
+
const pagination = {};
|
|
689
|
+
if (res.lastEvaluatedKey)
|
|
690
|
+
pagination.from = res.lastEvaluatedKey;
|
|
691
|
+
if ((_a2 = options.pagination) == null ? void 0 : _a2.limit)
|
|
692
|
+
pagination.limit = (_b2 = options.pagination) == null ? void 0 : _b2.limit;
|
|
693
|
+
return {
|
|
694
|
+
items: res.items,
|
|
695
|
+
pagination,
|
|
696
|
+
count: res.count
|
|
697
|
+
};
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
async fetchResults(command, limit = 100, useScan = false) {
|
|
701
|
+
var _a, _b;
|
|
702
|
+
let results = [];
|
|
703
|
+
let lastEvaluatedKey = {};
|
|
704
|
+
let rowsCount = 0;
|
|
705
|
+
do {
|
|
706
|
+
const result = await this.fetchBatch(
|
|
707
|
+
command,
|
|
708
|
+
useScan,
|
|
709
|
+
lastEvaluatedKey
|
|
710
|
+
);
|
|
711
|
+
const rows = (_a = result.Items) != null ? _a : [];
|
|
712
|
+
results = results.concat(rows);
|
|
713
|
+
lastEvaluatedKey = (_b = result.LastEvaluatedKey) != null ? _b : {};
|
|
714
|
+
rowsCount += result.Count || rows.length;
|
|
715
|
+
} while (rowsCount < limit && this.isNotEmptyObject(lastEvaluatedKey));
|
|
716
|
+
const encryptedLastEvaluatedKey = this.isNotEmptyObject(
|
|
717
|
+
lastEvaluatedKey
|
|
718
|
+
) ? this.encryptPaginationKey(lastEvaluatedKey) : null;
|
|
719
|
+
return {
|
|
720
|
+
items: results,
|
|
721
|
+
lastEvaluatedKey: encryptedLastEvaluatedKey,
|
|
722
|
+
count: rowsCount
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
async fetchBatch(command, useScan, lastEvaluatedKey) {
|
|
726
|
+
var _a, _b, _c;
|
|
727
|
+
if (this.isNotEmptyObject(lastEvaluatedKey))
|
|
728
|
+
command.ExclusiveStartKey = lastEvaluatedKey;
|
|
729
|
+
const result = await (useScan ? this.dynamoDbClientService.scan(command) : this.dynamoDbClientService.query(command));
|
|
730
|
+
if (command.Select !== "COUNT" /* COUNT */) {
|
|
731
|
+
command.Limit = ((_a = command.Limit) != null ? _a : 0) - ((_c = (_b = result.Items) == null ? void 0 : _b.length) != null ? _c : 0);
|
|
732
|
+
}
|
|
733
|
+
return result;
|
|
734
|
+
}
|
|
735
|
+
applyPagination(query, pagination) {
|
|
736
|
+
if (pagination == null ? void 0 : pagination.limit)
|
|
737
|
+
query.limit(pagination.limit);
|
|
738
|
+
if (pagination == null ? void 0 : pagination.from)
|
|
739
|
+
query.startKey(this.decryptPaginationKey(pagination.from));
|
|
740
|
+
}
|
|
741
|
+
async findAll(options = {}, allResults = [], rowsCount = 0) {
|
|
742
|
+
const { items, pagination, count } = await this.find(options);
|
|
743
|
+
allResults.push(...items);
|
|
744
|
+
rowsCount += count;
|
|
745
|
+
if (pagination == null ? void 0 : pagination.from)
|
|
746
|
+
await this.findAll(__spreadProps(__spreadValues({}, options), { pagination }), allResults);
|
|
747
|
+
return {
|
|
748
|
+
items: allResults,
|
|
749
|
+
pagination: null,
|
|
750
|
+
count: rowsCount
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
async findCount(options = {}) {
|
|
754
|
+
var _a;
|
|
755
|
+
const findOptions = __spreadProps(__spreadValues({}, options), {
|
|
756
|
+
aggregateFunction: "COUNT" /* COUNT */
|
|
757
|
+
});
|
|
758
|
+
if ((_a = options.pagination) == null ? void 0 : _a.from) {
|
|
759
|
+
return this.find(findOptions).then((res) => res.count);
|
|
760
|
+
} else {
|
|
761
|
+
return this.findAll(findOptions).then((res) => res.count);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
buildFindItemQuery(options) {
|
|
765
|
+
var _a;
|
|
766
|
+
const query = new QueryBuilderService();
|
|
767
|
+
if ((_a = options.index) == null ? void 0 : _a.indexName)
|
|
768
|
+
query.usingIndex(options.index.indexName);
|
|
769
|
+
this.applyFilters(query, options);
|
|
770
|
+
query.projection(options.fields);
|
|
771
|
+
query.limit(1);
|
|
772
|
+
return query;
|
|
773
|
+
}
|
|
774
|
+
findItem(options) {
|
|
775
|
+
const query = this.buildFindItemQuery(options);
|
|
776
|
+
return this.dynamoDbClientService.query(query.get()).then((result) => {
|
|
777
|
+
var _a;
|
|
778
|
+
if ((_a = result.Items) == null ? void 0 : _a.length)
|
|
779
|
+
return result.Items[0];
|
|
780
|
+
if (options.throwErrorIfNull)
|
|
781
|
+
throw new Error("NOT_FOUND");
|
|
782
|
+
return null;
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
applyWhereFilter(query, filter) {
|
|
786
|
+
var _a, _b;
|
|
787
|
+
const operator = FILTER_OPERATOR_MAP[(_b = (_a = filter.operator) == null ? void 0 : _a.toUpperCase()) != null ? _b : DYNAMODB_OPERATORS.EQUAL];
|
|
788
|
+
query.where(filter.attribute)[operator](filter.value);
|
|
789
|
+
}
|
|
790
|
+
applyFilterFilter(query, filter, logicOperator = "AND", config) {
|
|
791
|
+
var _a, _b;
|
|
792
|
+
const operator = FILTER_OPERATOR_MAP[(_b = (_a = filter.operator) == null ? void 0 : _a.toUpperCase()) != null ? _b : DYNAMODB_OPERATORS.EQUAL];
|
|
793
|
+
query.filter(filter.attribute, logicOperator, config)[operator](filter.value);
|
|
794
|
+
}
|
|
795
|
+
applyFilters(query, options) {
|
|
796
|
+
if (Array.isArray(options.filters)) {
|
|
797
|
+
this.applySimpleFilters(query, options);
|
|
798
|
+
} else {
|
|
799
|
+
this.applyCompoundFilters(query, options);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
applySimpleFilters(query, options) {
|
|
803
|
+
var _a, _b;
|
|
804
|
+
const queryIndexColumns = (_b = (_a = options.index) == null ? void 0 : _a.columns) != null ? _b : [];
|
|
805
|
+
const defaultWhereProperties = this.defaultPrimaryKeys;
|
|
806
|
+
const whereProperties = (queryIndexColumns == null ? void 0 : queryIndexColumns.length) ? queryIndexColumns : defaultWhereProperties;
|
|
807
|
+
const filters = options.filters;
|
|
808
|
+
filters.forEach((filter) => {
|
|
809
|
+
const isWhereProperty = whereProperties.includes(filter.attribute);
|
|
810
|
+
isWhereProperty && !options.useScan ? this.applyWhereFilter(query, filter) : this.applyFilterFilter(query, filter);
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
applyCompoundFilters(query, options) {
|
|
814
|
+
if (!options.filters)
|
|
815
|
+
return;
|
|
816
|
+
this.buildFilterExpression(query, options);
|
|
817
|
+
}
|
|
818
|
+
buildFilterExpression(query, options, parentKey) {
|
|
819
|
+
var _a;
|
|
820
|
+
const compositeFilters = options.filters;
|
|
821
|
+
const queryIndexColumns = ((_a = options.index) == null ? void 0 : _a.columns) || [];
|
|
822
|
+
const defaultWhereProperties = this.defaultPrimaryKeys;
|
|
823
|
+
const whereProperties = (queryIndexColumns == null ? void 0 : queryIndexColumns.length) ? queryIndexColumns : defaultWhereProperties;
|
|
824
|
+
for (const [key, value] of Object.entries(compositeFilters)) {
|
|
825
|
+
value.forEach(
|
|
826
|
+
(filter, index) => {
|
|
827
|
+
const isCompositeFilter = "OR" in filter || "AND" in filter;
|
|
828
|
+
if (isCompositeFilter) {
|
|
829
|
+
const newOptions = __spreadProps(__spreadValues({}, options), {
|
|
830
|
+
filters: filter
|
|
831
|
+
});
|
|
832
|
+
this.buildFilterExpression(query, newOptions, key);
|
|
833
|
+
} else {
|
|
834
|
+
const simpleFilter = filter;
|
|
835
|
+
const isWhereProperty = whereProperties.includes(
|
|
836
|
+
simpleFilter.attribute
|
|
837
|
+
);
|
|
838
|
+
let config;
|
|
839
|
+
if (parentKey) {
|
|
840
|
+
config = {
|
|
841
|
+
parentKey,
|
|
842
|
+
openExpression: index === 0,
|
|
843
|
+
closeExpression: index === value.length - 1
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
isWhereProperty && !options.useScan ? this.applyWhereFilter(query, simpleFilter) : this.applyFilterFilter(
|
|
847
|
+
query,
|
|
848
|
+
simpleFilter,
|
|
849
|
+
key,
|
|
850
|
+
config
|
|
851
|
+
);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
);
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
applySorting(query, sorting, sortIndex) {
|
|
858
|
+
if (sorting == null ? void 0 : sorting.length) {
|
|
859
|
+
if (sortIndex)
|
|
860
|
+
query.usingIndex(sortIndex);
|
|
861
|
+
if (sorting[0].direction === "DESC") {
|
|
862
|
+
query.descending();
|
|
863
|
+
} else {
|
|
864
|
+
query.ascending();
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
isNotEmptyObject(obj) {
|
|
869
|
+
return obj !== null && typeof obj === "object" && Object.keys(obj).length > 0;
|
|
870
|
+
}
|
|
871
|
+
encryptPaginationKey(key) {
|
|
872
|
+
const jsonKey = JSON.stringify(key);
|
|
873
|
+
return Buffer.from(jsonKey).toString("base64");
|
|
874
|
+
}
|
|
875
|
+
decryptPaginationKey(encodedKey) {
|
|
876
|
+
const decodedKey = Buffer.from(encodedKey, "base64").toString("utf-8");
|
|
877
|
+
return JSON.parse(decodedKey);
|
|
878
|
+
}
|
|
879
|
+
async update(filters, data, { replace = false }) {
|
|
880
|
+
const savedRecord = await this.findItem({
|
|
881
|
+
filters
|
|
882
|
+
});
|
|
883
|
+
const newData = __spreadValues(__spreadValues({}, savedRecord), data);
|
|
884
|
+
await this.dynamoDbClientService.put(newData);
|
|
885
|
+
return newData;
|
|
886
|
+
}
|
|
887
|
+
async remove(filters, options) {
|
|
888
|
+
if (options == null ? void 0 : options.filterGroups) {
|
|
889
|
+
await this.dynamoDbClientService.batchRemove(
|
|
890
|
+
filters
|
|
891
|
+
);
|
|
892
|
+
} else {
|
|
893
|
+
const key = filters.reduce((obj, item) => {
|
|
894
|
+
const property = item.attribute;
|
|
895
|
+
obj[property] = item.value;
|
|
896
|
+
return obj;
|
|
897
|
+
}, {});
|
|
898
|
+
await this.dynamoDbClientService.remove(key);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
async updateExpressions(filters, actions, options) {
|
|
902
|
+
try {
|
|
903
|
+
return await __privateMethod(this, _prepareAndExecuteUpdateExpression, prepareAndExecuteUpdateExpression_fn).call(this, filters, actions, options);
|
|
904
|
+
} catch (error) {
|
|
905
|
+
PersistenceErrorWrapper(error);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
};
|
|
909
|
+
_prepareAndExecuteUpdateExpression = new WeakSet();
|
|
910
|
+
prepareAndExecuteUpdateExpression_fn = async function(filters, actions, options) {
|
|
911
|
+
const queryObject = __privateMethod(this, _buildUpdateExpressionQuery, buildUpdateExpressionQuery_fn).call(this, { filters }).get();
|
|
912
|
+
const primaryKeys = this.defaultPrimaryKeys;
|
|
913
|
+
const keyObject = __privateMethod(this, _getKeyObjectForUpdateExpression, getKeyObjectForUpdateExpression_fn).call(this, queryObject, primaryKeys);
|
|
914
|
+
const updateExpressions = [];
|
|
915
|
+
Object.keys(actions).forEach((action) => {
|
|
916
|
+
const actionUpdateExpression = __privateMethod(this, _extractUpdateExpressionAttributesAndNames, extractUpdateExpressionAttributesAndNames_fn).call(this, actions, action);
|
|
917
|
+
updateExpressions.push(actionUpdateExpression);
|
|
918
|
+
});
|
|
919
|
+
const dbParams = __spreadValues({
|
|
920
|
+
UpdateExpression: updateExpressions.join(" ")
|
|
921
|
+
}, __privateMethod(this, _getUpdateExpressionOptions, getUpdateExpressionOptions_fn).call(this, options));
|
|
922
|
+
const { ExpressionAttributeValues, ExpressionAttributeNames } = queryObject;
|
|
923
|
+
if (Object.keys(ExpressionAttributeValues).length > 0) {
|
|
924
|
+
dbParams["ExpressionAttributeValues"] = __spreadValues(__spreadValues({}, ExpressionAttributeValues), dbParams.ExpressionAttributeValues);
|
|
925
|
+
}
|
|
926
|
+
if (Object.keys(ExpressionAttributeNames).length > 0) {
|
|
927
|
+
dbParams["ExpressionAttributeNames"] = __spreadValues(__spreadValues({}, ExpressionAttributeNames), dbParams.ExpressionAttributeNames);
|
|
928
|
+
}
|
|
929
|
+
if (queryObject.FilterExpression)
|
|
930
|
+
dbParams["ConditionExpression"] = queryObject.FilterExpression;
|
|
931
|
+
return this.dynamoDbClientService.updateExpressions(
|
|
932
|
+
keyObject,
|
|
933
|
+
dbParams
|
|
934
|
+
);
|
|
935
|
+
};
|
|
936
|
+
_buildUpdateExpressionQuery = new WeakSet();
|
|
937
|
+
buildUpdateExpressionQuery_fn = function(options) {
|
|
938
|
+
var _a;
|
|
939
|
+
const query = new QueryBuilderService();
|
|
940
|
+
if ((_a = options.index) == null ? void 0 : _a.indexName)
|
|
941
|
+
query.usingIndex(options.index.indexName);
|
|
942
|
+
this.applyFilters(query, options);
|
|
943
|
+
return query;
|
|
944
|
+
};
|
|
945
|
+
_getKeyObjectForUpdateExpression = new WeakSet();
|
|
946
|
+
getKeyObjectForUpdateExpression_fn = function(queryObject, primaryKeys) {
|
|
947
|
+
const keyObject = {};
|
|
948
|
+
Object.keys(queryObject.ExpressionAttributeNames).forEach(
|
|
949
|
+
(attribute) => {
|
|
950
|
+
const sanitizedAttribute = attribute.replace("#", "").replace("1", "");
|
|
951
|
+
if (primaryKeys.includes(sanitizedAttribute)) {
|
|
952
|
+
const valueName = `:${sanitizedAttribute}1`;
|
|
953
|
+
keyObject[sanitizedAttribute] = queryObject.ExpressionAttributeValues[valueName];
|
|
954
|
+
delete queryObject.ExpressionAttributeValues[valueName];
|
|
955
|
+
delete queryObject.ExpressionAttributeNames[attribute];
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
);
|
|
959
|
+
return keyObject;
|
|
960
|
+
};
|
|
961
|
+
_getUpdateExpressionOptions = new WeakSet();
|
|
962
|
+
getUpdateExpressionOptions_fn = function(options) {
|
|
963
|
+
const updateExprOptions = {
|
|
964
|
+
ReturnValues: options.returnValues
|
|
965
|
+
};
|
|
966
|
+
if (options.expressionAttributeNames)
|
|
967
|
+
updateExprOptions.ExpressionAttributeNames = options.expressionAttributeNames;
|
|
968
|
+
if (options.expressionAttributeValues)
|
|
969
|
+
updateExprOptions.ExpressionAttributeValues = options.expressionAttributeValues;
|
|
970
|
+
return updateExprOptions;
|
|
971
|
+
};
|
|
972
|
+
_extractUpdateExpressionAttributesAndNames = new WeakSet();
|
|
973
|
+
extractUpdateExpressionAttributesAndNames_fn = function(actions, actionType) {
|
|
974
|
+
const actionUpdateExpressions = [];
|
|
975
|
+
actions[actionType].forEach((action) => {
|
|
976
|
+
switch (actionType) {
|
|
977
|
+
case DYNAMO_DB_UPDATE_ACTIONS.DELETE:
|
|
978
|
+
case DYNAMO_DB_UPDATE_ACTIONS.REMOVE:
|
|
979
|
+
actionUpdateExpressions.push(`${action.path}`);
|
|
980
|
+
break;
|
|
981
|
+
case DYNAMO_DB_UPDATE_ACTIONS.ADD:
|
|
982
|
+
case DYNAMO_DB_UPDATE_ACTIONS.SET:
|
|
983
|
+
{
|
|
984
|
+
let operator = "";
|
|
985
|
+
if (actionType == DYNAMO_DB_UPDATE_ACTIONS.SET)
|
|
986
|
+
operator = "=";
|
|
987
|
+
actionUpdateExpressions.push(
|
|
988
|
+
`${action.path} ${operator}${action.value}`
|
|
989
|
+
);
|
|
990
|
+
}
|
|
991
|
+
break;
|
|
992
|
+
}
|
|
993
|
+
});
|
|
994
|
+
const actionUpdateExpression = `${actionType} ${actionUpdateExpressions.join(
|
|
995
|
+
", "
|
|
996
|
+
)}`;
|
|
997
|
+
return actionUpdateExpression;
|
|
998
|
+
};
|
|
999
|
+
var ConnectionService = class {
|
|
1000
|
+
get connectionString() {
|
|
1001
|
+
const connectionString = process.env.MULTIPLATFORM_PG_CONNECTION_STRING || "";
|
|
1002
|
+
if (!connectionString) {
|
|
1003
|
+
throw new Error(
|
|
1004
|
+
"MULTIPLATFORM_PG_CONNECTION_STRING environment variable must be configured"
|
|
1005
|
+
);
|
|
1006
|
+
}
|
|
1007
|
+
return connectionString;
|
|
1008
|
+
}
|
|
1009
|
+
async getClient() {
|
|
1010
|
+
const client = new Client({
|
|
1011
|
+
connectionString: this.connectionString
|
|
1012
|
+
});
|
|
1013
|
+
await client.connect();
|
|
1014
|
+
return client;
|
|
1015
|
+
}
|
|
1016
|
+
releaseClient(client) {
|
|
1017
|
+
try {
|
|
1018
|
+
client.end();
|
|
1019
|
+
} catch (e) {
|
|
1020
|
+
console.log("Error releasing client");
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
};
|
|
1024
|
+
|
|
1025
|
+
// src/services/cruds/postgresql/query.service.ts
|
|
1026
|
+
var QueryService = class {
|
|
1027
|
+
constructor(poolClient) {
|
|
1028
|
+
this.poolClient = poolClient;
|
|
1029
|
+
this.connectionService = new ConnectionService();
|
|
1030
|
+
}
|
|
1031
|
+
async runQuery(queryText, values) {
|
|
1032
|
+
const client = await (this.poolClient ? this.poolClient : this.connectionService.getClient());
|
|
1033
|
+
try {
|
|
1034
|
+
const result = await client.query(queryText, values);
|
|
1035
|
+
return result;
|
|
1036
|
+
} catch (error) {
|
|
1037
|
+
console.log("[Postgresql-Client] Query Execution Failed:", error);
|
|
1038
|
+
throw error;
|
|
1039
|
+
} finally {
|
|
1040
|
+
if (!this.poolClient)
|
|
1041
|
+
this.connectionService.releaseClient(client);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
};
|
|
1045
|
+
|
|
1046
|
+
// src/services/cruds/postgresql/postgreSqlClient.service.ts
|
|
1047
|
+
var PostgresqlClientService = class extends QueryService {
|
|
1048
|
+
constructor(tableSchema, poolClient) {
|
|
1049
|
+
super(poolClient);
|
|
1050
|
+
this.isCompositeFilter = function(value) {
|
|
1051
|
+
return "OR" in value || "AND" in value;
|
|
1052
|
+
};
|
|
1053
|
+
this.crudSchema = tableSchema;
|
|
1054
|
+
}
|
|
1055
|
+
get dbSchema() {
|
|
1056
|
+
return this.crudSchema.schema || DEFAULT_PG_SCHEMA;
|
|
1057
|
+
}
|
|
1058
|
+
get tableName() {
|
|
1059
|
+
return getTableName(this.crudSchema.table, "alias") || getTableName(this.crudSchema.table);
|
|
1060
|
+
}
|
|
1061
|
+
getWildcardValue(operator, value) {
|
|
1062
|
+
if (operator === "CONTAINS" /* CONTAINS */ || operator === "NOT_CONTAINS" /* NOT_CONTAINS */) {
|
|
1063
|
+
return "%" + value + "%";
|
|
1064
|
+
} else if (operator === "STARTS_WITH" /* STARTS_WITH */) {
|
|
1065
|
+
return value + "%";
|
|
1066
|
+
} else {
|
|
1067
|
+
return value;
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
buildClause(operator, attribute, value) {
|
|
1071
|
+
var _a;
|
|
1072
|
+
const formattedValue = format.literal(value);
|
|
1073
|
+
operator = operator ? operator.toUpperCase() : "EQUAL" /* EQUAL */;
|
|
1074
|
+
const postgresOperator = POSTGRES_FILTER_OPERATOR_MAP[operator];
|
|
1075
|
+
if (!postgresOperator)
|
|
1076
|
+
throw new Error(`Unsupported filter operator: ${operator}`);
|
|
1077
|
+
const filterProperty = format.ident(attribute);
|
|
1078
|
+
const columnExists = !!this.crudSchema.columns[attribute];
|
|
1079
|
+
const columnType = columnExists && ((_a = this.crudSchema.columns[attribute]) == null ? void 0 : _a.type);
|
|
1080
|
+
const property = columnExists ? filterProperty : `("qvAttributes" ->> '${attribute}')`;
|
|
1081
|
+
if (operator === "IN" /* IN */) {
|
|
1082
|
+
const formattedValues = Array.isArray(value) ? value.map(format.literal) : [formattedValue];
|
|
1083
|
+
return `${property} ${postgresOperator} (${formattedValues.join(
|
|
1084
|
+
", "
|
|
1085
|
+
)})`;
|
|
1086
|
+
}
|
|
1087
|
+
if (operator === "BETWEEN" /* BETWEEN */) {
|
|
1088
|
+
return `${property} ${postgresOperator} ${value[0]} AND ${value[1]}`;
|
|
1089
|
+
}
|
|
1090
|
+
if (operator === "NOT_EQUAL" /* NOT_EQUAL */ && value !== null) {
|
|
1091
|
+
return `(${property} ${postgresOperator} ${format.literal(
|
|
1092
|
+
value
|
|
1093
|
+
)} OR ${property} IS NULL)`;
|
|
1094
|
+
}
|
|
1095
|
+
if (operator === "NOT_EXIST" /* NOT_EXIST */ || operator === "EXIST" /* EXIST */) {
|
|
1096
|
+
return `${property} ${postgresOperator}`;
|
|
1097
|
+
}
|
|
1098
|
+
if ((operator === "CONTAINS" /* CONTAINS */ || operator === "NOT_CONTAINS" /* NOT_CONTAINS */) && columnType === "array") {
|
|
1099
|
+
const filterValue = typeof value === "number" ? value : `'${value}'`;
|
|
1100
|
+
let filterString = `${filterValue} = ANY(${property})`;
|
|
1101
|
+
if (operator === "NOT_CONTAINS" /* NOT_CONTAINS */) {
|
|
1102
|
+
if (value === null) {
|
|
1103
|
+
filterString = `(NOT (${filterString}))`;
|
|
1104
|
+
} else {
|
|
1105
|
+
filterString = `(NOT (${filterString}) or ${property} IS NULL)`;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
return filterString;
|
|
1109
|
+
}
|
|
1110
|
+
const wildcardValue = this.getWildcardValue(operator, value);
|
|
1111
|
+
return `${property} ${postgresOperator} ${format.literal(
|
|
1112
|
+
wildcardValue
|
|
1113
|
+
)}`;
|
|
1114
|
+
}
|
|
1115
|
+
buildFilterClause(filters, logicOperator) {
|
|
1116
|
+
if (Array.isArray(filters)) {
|
|
1117
|
+
const filterClauses = filters.map((filter) => {
|
|
1118
|
+
return this.buildClause(
|
|
1119
|
+
filter.operator,
|
|
1120
|
+
filter.attribute,
|
|
1121
|
+
filter.value
|
|
1122
|
+
);
|
|
1123
|
+
});
|
|
1124
|
+
return filterClauses.join(
|
|
1125
|
+
` ${logicOperator != null ? logicOperator : "AND" /* AND */} `
|
|
1126
|
+
);
|
|
1127
|
+
} else {
|
|
1128
|
+
return this.buildQueryByClause(filters);
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
buildQueryByClause(filters) {
|
|
1132
|
+
let filterClauses = "";
|
|
1133
|
+
let isFirstFilter = true;
|
|
1134
|
+
for (const [key, value] of Object.entries(filters)) {
|
|
1135
|
+
if (!isFirstFilter) {
|
|
1136
|
+
filterClauses += key === "AND" ? " AND " : " OR ";
|
|
1137
|
+
}
|
|
1138
|
+
if (this.isCompositeFilter(value)) {
|
|
1139
|
+
filterClauses += "(";
|
|
1140
|
+
filterClauses += this.buildQueryByClause(
|
|
1141
|
+
value
|
|
1142
|
+
);
|
|
1143
|
+
filterClauses += ")";
|
|
1144
|
+
} else {
|
|
1145
|
+
value.forEach((filter) => {
|
|
1146
|
+
let clause = "";
|
|
1147
|
+
if (this.isCompositeFilter(filter)) {
|
|
1148
|
+
clause = `(${this.buildQueryByClause(
|
|
1149
|
+
filter
|
|
1150
|
+
)})`;
|
|
1151
|
+
} else {
|
|
1152
|
+
clause = this.buildClause(
|
|
1153
|
+
filter.operator,
|
|
1154
|
+
filter.attribute,
|
|
1155
|
+
filter.value
|
|
1156
|
+
);
|
|
1157
|
+
}
|
|
1158
|
+
filterClauses += `${clause} ${key} `;
|
|
1159
|
+
});
|
|
1160
|
+
}
|
|
1161
|
+
isFirstFilter = false;
|
|
1162
|
+
}
|
|
1163
|
+
filterClauses = filterClauses.replace(/\s+(AND|OR)\s*$/, "");
|
|
1164
|
+
return filterClauses;
|
|
1165
|
+
}
|
|
1166
|
+
formatOrderByItem(sort) {
|
|
1167
|
+
return `${format.ident(sort.column)} ${sort.direction || "ASC" /* ASC */}`;
|
|
1168
|
+
}
|
|
1169
|
+
buildOrderByClause(querySorting) {
|
|
1170
|
+
try {
|
|
1171
|
+
return querySorting.map(this.formatOrderByItem).join(", ");
|
|
1172
|
+
} catch (error) {
|
|
1173
|
+
return "";
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
formatArray(array) {
|
|
1177
|
+
const isNumberArray = typeof array[0] === "number";
|
|
1178
|
+
if (isNumberArray) {
|
|
1179
|
+
return `{${array.join(",")}}`;
|
|
1180
|
+
} else {
|
|
1181
|
+
return `{${array.map((val) => `"${val}"`).join(",")}}`;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
formatValue(value) {
|
|
1185
|
+
if (Array.isArray(value)) {
|
|
1186
|
+
if (!(value == null ? void 0 : value.length))
|
|
1187
|
+
return "{}";
|
|
1188
|
+
const isNumberArray = typeof value[0] === "number";
|
|
1189
|
+
if (isNumberArray) {
|
|
1190
|
+
return `{${value.join(",")}}`;
|
|
1191
|
+
} else {
|
|
1192
|
+
return `{${value.map((val) => `"${val}"`).join(",")}}`;
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
return value;
|
|
1196
|
+
}
|
|
1197
|
+
async createCommand(data) {
|
|
1198
|
+
const keys = Object.keys(data[0]);
|
|
1199
|
+
const values = data.map(
|
|
1200
|
+
(item) => keys.map((key) => this.formatValue(item[key]))
|
|
1201
|
+
);
|
|
1202
|
+
const query = format(
|
|
1203
|
+
`INSERT INTO ${format.ident(this.dbSchema)}.${format.ident(
|
|
1204
|
+
this.tableName
|
|
1205
|
+
)} (%I) VALUES %L RETURNING *;`,
|
|
1206
|
+
keys,
|
|
1207
|
+
values
|
|
1208
|
+
);
|
|
1209
|
+
return this.runQuery(query);
|
|
1210
|
+
}
|
|
1211
|
+
addFiltersToQuery(query, filters) {
|
|
1212
|
+
if (!filters)
|
|
1213
|
+
return query;
|
|
1214
|
+
const isValidArrayFilters = Array.isArray(filters) && (filters == null ? void 0 : filters.length);
|
|
1215
|
+
const isValidCompositeFilters = this.isCompositeFilter(filters);
|
|
1216
|
+
if (isValidArrayFilters || isValidCompositeFilters)
|
|
1217
|
+
query += ` WHERE ${this.buildFilterClause(filters)}`;
|
|
1218
|
+
return query;
|
|
1219
|
+
}
|
|
1220
|
+
addOrderByToQuery(query, orderBy) {
|
|
1221
|
+
if (orderBy)
|
|
1222
|
+
query += ` ORDER BY ${this.buildOrderByClause(orderBy)}`;
|
|
1223
|
+
return query;
|
|
1224
|
+
}
|
|
1225
|
+
addPaginationToQuery(query, pagination) {
|
|
1226
|
+
if (pagination) {
|
|
1227
|
+
const { limit, from } = pagination;
|
|
1228
|
+
if (limit)
|
|
1229
|
+
query += ` LIMIT ${limit}`;
|
|
1230
|
+
if (from)
|
|
1231
|
+
query += ` OFFSET ${from}`;
|
|
1232
|
+
}
|
|
1233
|
+
return query;
|
|
1234
|
+
}
|
|
1235
|
+
getSelectClause(aggregateFunction, fields = []) {
|
|
1236
|
+
if (aggregateFunction)
|
|
1237
|
+
return `CAST(${aggregateFunction}(1) AS INTEGER) AS "${buildAggFunctionAlias(
|
|
1238
|
+
aggregateFunction
|
|
1239
|
+
)}"`;
|
|
1240
|
+
if (!(fields == null ? void 0 : fields.length))
|
|
1241
|
+
return "*";
|
|
1242
|
+
return this.parseFields(fields).join(", ");
|
|
1243
|
+
}
|
|
1244
|
+
parseFields(fields) {
|
|
1245
|
+
const columnsFromSchema = Object.keys(
|
|
1246
|
+
this.crudSchema.columns
|
|
1247
|
+
);
|
|
1248
|
+
const attributes = fields.filter((field) => columnsFromSchema.indexOf(field) !== -1).map((field) => `"${field}"`);
|
|
1249
|
+
fields.filter((field) => columnsFromSchema.indexOf(field) === -1).forEach((field) => {
|
|
1250
|
+
attributes.push(`"qvAttributes" ->> '${field}' as "${field}"`);
|
|
1251
|
+
});
|
|
1252
|
+
return attributes;
|
|
1253
|
+
}
|
|
1254
|
+
async findCommand(options = {}) {
|
|
1255
|
+
let query = `SELECT ${this.getSelectClause(
|
|
1256
|
+
options.aggregateFunction,
|
|
1257
|
+
options.fields
|
|
1258
|
+
)} FROM ${format.ident(this.dbSchema)}.${format.ident(this.tableName)}`;
|
|
1259
|
+
query = this.addFiltersToQuery(query, options.filters);
|
|
1260
|
+
if (!options.aggregateFunction) {
|
|
1261
|
+
query = this.addOrderByToQuery(query, options.sorting);
|
|
1262
|
+
query = this.addPaginationToQuery(query, options.pagination);
|
|
1263
|
+
}
|
|
1264
|
+
return (await this.runQuery(query)).rows;
|
|
1265
|
+
}
|
|
1266
|
+
sanitizeValue(value) {
|
|
1267
|
+
if (Array.isArray(value)) {
|
|
1268
|
+
if (value.length === 0)
|
|
1269
|
+
;
|
|
1270
|
+
const formattedArray = value.map((item) => {
|
|
1271
|
+
if (typeof item === "string") {
|
|
1272
|
+
return `'${item}'`;
|
|
1273
|
+
} else if (typeof item === "object") {
|
|
1274
|
+
return JSON.stringify(item);
|
|
1275
|
+
} else {
|
|
1276
|
+
return item;
|
|
1277
|
+
}
|
|
1278
|
+
}).join(",");
|
|
1279
|
+
return JSON.stringify(formattedArray);
|
|
1280
|
+
} else {
|
|
1281
|
+
return format.literal(value);
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
async updateCommand(filters, data) {
|
|
1285
|
+
let query = `UPDATE ${format.ident(this.dbSchema)}.${format.ident(
|
|
1286
|
+
this.tableName
|
|
1287
|
+
)} SET`;
|
|
1288
|
+
const updateClauses = Object.entries(data).map(([key, value]) => {
|
|
1289
|
+
const dbValue = format.literal(this.formatValue(value));
|
|
1290
|
+
return `${format.ident(key)} = ${dbValue}`;
|
|
1291
|
+
});
|
|
1292
|
+
query += ` ${updateClauses.join(", ")}`;
|
|
1293
|
+
query += " WHERE ";
|
|
1294
|
+
query += this.buildFilterClause(filters);
|
|
1295
|
+
return this.runQuery(query);
|
|
1296
|
+
}
|
|
1297
|
+
buildFilterClauseForFilterGroups(filterGroups) {
|
|
1298
|
+
const filterClauses = filterGroups.map((filterGroup) => {
|
|
1299
|
+
return `(${this.buildFilterClause(filterGroup)})`;
|
|
1300
|
+
});
|
|
1301
|
+
return filterClauses.join(" OR ");
|
|
1302
|
+
}
|
|
1303
|
+
async deleteCommand(filters, useFilterGroups = false) {
|
|
1304
|
+
let query = `DELETE FROM ${format.ident(this.dbSchema)}.${format.ident(
|
|
1305
|
+
this.tableName
|
|
1306
|
+
)}`;
|
|
1307
|
+
if (filters) {
|
|
1308
|
+
query += " WHERE ";
|
|
1309
|
+
if (useFilterGroups) {
|
|
1310
|
+
query += this.buildFilterClauseForFilterGroups(
|
|
1311
|
+
filters
|
|
1312
|
+
);
|
|
1313
|
+
} else {
|
|
1314
|
+
query += this.buildFilterClause(
|
|
1315
|
+
filters
|
|
1316
|
+
);
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
return this.runQuery(query);
|
|
1320
|
+
}
|
|
1321
|
+
query(queryText, values) {
|
|
1322
|
+
return this.runQuery(queryText, values);
|
|
1323
|
+
}
|
|
1324
|
+
async updateExpressionCommand(filters, actions, options = {}) {
|
|
1325
|
+
let query = `UPDATE ${format.ident(this.dbSchema)}.${format.ident(
|
|
1326
|
+
this.tableName
|
|
1327
|
+
)} SET`;
|
|
1328
|
+
const set = actions.SET || [];
|
|
1329
|
+
const add = actions.ADD || [];
|
|
1330
|
+
const columns = this.crudSchema.columns;
|
|
1331
|
+
const setValues = this.replacePathAndValueByAttributeNames(
|
|
1332
|
+
set,
|
|
1333
|
+
options,
|
|
1334
|
+
columns,
|
|
1335
|
+
DYNAMO_DB_UPDATE_ACTIONS.SET
|
|
1336
|
+
);
|
|
1337
|
+
const addValues = this.replacePathAndValueByAttributeNames(
|
|
1338
|
+
add,
|
|
1339
|
+
options,
|
|
1340
|
+
columns,
|
|
1341
|
+
DYNAMO_DB_UPDATE_ACTIONS.ADD
|
|
1342
|
+
);
|
|
1343
|
+
const setValuesAndAddValues = setValues.concat(addValues);
|
|
1344
|
+
const updateClauses = [];
|
|
1345
|
+
const jsonSetExpressionGroup = {};
|
|
1346
|
+
const queryFunctions = [];
|
|
1347
|
+
setValuesAndAddValues.forEach((expression) => {
|
|
1348
|
+
const { path, value, createNewColumn, actionName, dynamoFuncName } = expression;
|
|
1349
|
+
if (dynamoFuncName) {
|
|
1350
|
+
queryFunctions.push({ path, value, dynamoFuncName });
|
|
1351
|
+
}
|
|
1352
|
+
if (path.includes(".") && !dynamoFuncName) {
|
|
1353
|
+
const jsonExpr = this.getJSONBSetExpressionByAction(
|
|
1354
|
+
path,
|
|
1355
|
+
value,
|
|
1356
|
+
{
|
|
1357
|
+
createNewColumn,
|
|
1358
|
+
actionName
|
|
1359
|
+
}
|
|
1360
|
+
);
|
|
1361
|
+
const columnName = jsonExpr.columnName;
|
|
1362
|
+
if (!jsonSetExpressionGroup[columnName]) {
|
|
1363
|
+
jsonSetExpressionGroup[columnName] = [jsonExpr];
|
|
1364
|
+
} else {
|
|
1365
|
+
jsonSetExpressionGroup[columnName].push(jsonExpr);
|
|
1366
|
+
}
|
|
1367
|
+
} else if (!dynamoFuncName) {
|
|
1368
|
+
let expValue;
|
|
1369
|
+
const column = this.crudSchema.columns[path];
|
|
1370
|
+
if ((column == null ? void 0 : column.type) == void 0)
|
|
1371
|
+
throw `Column type definition for column: (${path}) must be in the CrudSchema`;
|
|
1372
|
+
let formattedValue;
|
|
1373
|
+
switch (column.type) {
|
|
1374
|
+
case "object":
|
|
1375
|
+
{
|
|
1376
|
+
const valueSerialized = `${JSON.stringify(
|
|
1377
|
+
value
|
|
1378
|
+
).replace(/'/g, "''")}`;
|
|
1379
|
+
expValue = `'${valueSerialized}'::jsonb`;
|
|
1380
|
+
}
|
|
1381
|
+
break;
|
|
1382
|
+
case "array":
|
|
1383
|
+
formattedValue = format.literal(value);
|
|
1384
|
+
expValue = `ARRAY[${formattedValue}]`;
|
|
1385
|
+
break;
|
|
1386
|
+
default:
|
|
1387
|
+
formattedValue = format.literal(value);
|
|
1388
|
+
expValue = formattedValue;
|
|
1389
|
+
break;
|
|
1390
|
+
}
|
|
1391
|
+
this.crudSchema.columns;
|
|
1392
|
+
updateClauses.push(`${format.ident(path)} = ${expValue}`);
|
|
1393
|
+
}
|
|
1394
|
+
});
|
|
1395
|
+
if (Object.keys(jsonSetExpressionGroup).length > 0) {
|
|
1396
|
+
Object.keys(jsonSetExpressionGroup).forEach((groupIndex) => {
|
|
1397
|
+
const jsonSetExpression = this.buildJSONBExpression(
|
|
1398
|
+
jsonSetExpressionGroup[groupIndex],
|
|
1399
|
+
"jsonb_set"
|
|
1400
|
+
);
|
|
1401
|
+
updateClauses.push(`${groupIndex} = ${jsonSetExpression}`);
|
|
1402
|
+
});
|
|
1403
|
+
}
|
|
1404
|
+
if (queryFunctions.length > 0) {
|
|
1405
|
+
queryFunctions.forEach((queryFunction) => {
|
|
1406
|
+
updateClauses.push(
|
|
1407
|
+
`${format.ident(queryFunction.path)} = ${queryFunction.value}`
|
|
1408
|
+
);
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1411
|
+
query += ` ${updateClauses.join(", ")}`;
|
|
1412
|
+
query += " WHERE ";
|
|
1413
|
+
query += this.buildFilterClause(filters);
|
|
1414
|
+
return this.runQuery(query);
|
|
1415
|
+
}
|
|
1416
|
+
/**
|
|
1417
|
+
* @description Builds a jsonb expression like jsonb_insert, or jsonb_set
|
|
1418
|
+
* @param jsonSetExpressions
|
|
1419
|
+
* @param functionName
|
|
1420
|
+
* @returns
|
|
1421
|
+
*/
|
|
1422
|
+
buildJSONBExpression(jsonSetExpressions, functionName) {
|
|
1423
|
+
let jsonSetStringExpr = "";
|
|
1424
|
+
jsonSetExpressions.forEach((expression, index) => {
|
|
1425
|
+
const { columnName, jsonExpr } = expression;
|
|
1426
|
+
if (index === 0) {
|
|
1427
|
+
jsonSetStringExpr = `${functionName}(${columnName},${jsonExpr})`;
|
|
1428
|
+
} else {
|
|
1429
|
+
jsonSetStringExpr = `${functionName}(${jsonSetStringExpr},${jsonExpr})`;
|
|
1430
|
+
}
|
|
1431
|
+
});
|
|
1432
|
+
return jsonSetStringExpr;
|
|
1433
|
+
}
|
|
1434
|
+
/**
|
|
1435
|
+
* @description Serializes a JSON value
|
|
1436
|
+
* @param value
|
|
1437
|
+
* @returns
|
|
1438
|
+
*/
|
|
1439
|
+
serializeJSONValue(value) {
|
|
1440
|
+
const valueSerialized = typeof value == "object" ? `${JSON.stringify(value).replace(/'/g, "''")}` : value;
|
|
1441
|
+
return valueSerialized;
|
|
1442
|
+
}
|
|
1443
|
+
getJSONBSetExpressionByAction(path, value, options) {
|
|
1444
|
+
path = path.replace(/\[(\d+)\]/g, ".$1");
|
|
1445
|
+
const pathSplitted = path.split(".");
|
|
1446
|
+
const parentPath = pathSplitted[0];
|
|
1447
|
+
const { createNewColumn, actionName } = options;
|
|
1448
|
+
const pathSerialized = pathSplitted.slice(1).join(",");
|
|
1449
|
+
const valueSerialized = `'${JSON.stringify(value).replace(
|
|
1450
|
+
/'/g,
|
|
1451
|
+
"''"
|
|
1452
|
+
)}'`;
|
|
1453
|
+
if (actionName == DYNAMO_DB_UPDATE_ACTIONS.ADD) {
|
|
1454
|
+
if (typeof value != "string" && !isNaN(value)) {
|
|
1455
|
+
const resultExpr = {
|
|
1456
|
+
jsonExpr: `'{${pathSerialized}}',to_jsonb(COALESCE(("${parentPath}"#>'{${pathSerialized}}')::numeric,0) + ${valueSerialized})`,
|
|
1457
|
+
columnName: `"${parentPath}"`
|
|
1458
|
+
};
|
|
1459
|
+
return resultExpr;
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
return {
|
|
1463
|
+
jsonExpr: `'{${pathSerialized}}',${valueSerialized},${createNewColumn}`,
|
|
1464
|
+
columnName: `"${parentPath}"`
|
|
1465
|
+
};
|
|
1466
|
+
}
|
|
1467
|
+
getListAppendDefFromValue(queryValue, columnType) {
|
|
1468
|
+
const regexListAppend = /list_append\(([^)]+)\)/gm;
|
|
1469
|
+
const listAppendString = "list_append(";
|
|
1470
|
+
const matchList = queryValue.match(regexListAppend) || [];
|
|
1471
|
+
const groupResult = matchList[0];
|
|
1472
|
+
if (groupResult) {
|
|
1473
|
+
const attributesFromGroup = groupResult.slice(listAppendString.length, -1).split(",");
|
|
1474
|
+
const attributes = {
|
|
1475
|
+
originalString: groupResult,
|
|
1476
|
+
path: attributesFromGroup[0].trim(),
|
|
1477
|
+
value: attributesFromGroup.slice(1).join(",").trim(),
|
|
1478
|
+
functionExpr: ""
|
|
1479
|
+
};
|
|
1480
|
+
if (columnType == "array") {
|
|
1481
|
+
attributes["functionExpr"] = this.buildArrayAppendExpr(attributes);
|
|
1482
|
+
} else {
|
|
1483
|
+
attributes["functionExpr"] = this.buildJsonbInsertExpr(attributes);
|
|
1484
|
+
}
|
|
1485
|
+
return attributes;
|
|
1486
|
+
}
|
|
1487
|
+
return null;
|
|
1488
|
+
}
|
|
1489
|
+
buildArrayAppendExpr(params) {
|
|
1490
|
+
const arrayPath = params.path.split(".");
|
|
1491
|
+
const columnName = arrayPath.shift();
|
|
1492
|
+
return `ARRAY_APPEND("${columnName}",${params.value})`;
|
|
1493
|
+
}
|
|
1494
|
+
buildJsonbInsertExpr(params) {
|
|
1495
|
+
const arrayPath = params.path.split(".");
|
|
1496
|
+
const columnName = arrayPath.shift();
|
|
1497
|
+
const jsonbInsertExpressions = this.getExpressionsByDefinitionForJSONBInsert(
|
|
1498
|
+
columnName,
|
|
1499
|
+
params.value
|
|
1500
|
+
);
|
|
1501
|
+
const expressions = this.buildJSONBExpression(
|
|
1502
|
+
jsonbInsertExpressions,
|
|
1503
|
+
"jsonb_insert"
|
|
1504
|
+
);
|
|
1505
|
+
return expressions;
|
|
1506
|
+
}
|
|
1507
|
+
getExpressionsByDefinitionForJSONBInsert(columnName, value) {
|
|
1508
|
+
const jsonbInsertExpressions = [];
|
|
1509
|
+
try {
|
|
1510
|
+
const parsedValue = JSON.parse(value);
|
|
1511
|
+
if (Array.isArray(parsedValue)) {
|
|
1512
|
+
parsedValue.forEach((arrayValue) => {
|
|
1513
|
+
jsonbInsertExpressions.push({
|
|
1514
|
+
jsonExpr: `'{0}','${this.serializeJSONValue(
|
|
1515
|
+
arrayValue
|
|
1516
|
+
)}'`,
|
|
1517
|
+
columnName: `"${columnName}"`
|
|
1518
|
+
});
|
|
1519
|
+
});
|
|
1520
|
+
} else {
|
|
1521
|
+
jsonbInsertExpressions.push({
|
|
1522
|
+
jsonExpr: `'{0}','${this.serializeJSONValue(parsedValue)}'`,
|
|
1523
|
+
columnName: `"${columnName}"`
|
|
1524
|
+
});
|
|
1525
|
+
}
|
|
1526
|
+
} catch (error) {
|
|
1527
|
+
jsonbInsertExpressions.push({
|
|
1528
|
+
jsonExpr: `'{0}','${value}'`,
|
|
1529
|
+
columnName: `"${columnName}"`
|
|
1530
|
+
});
|
|
1531
|
+
}
|
|
1532
|
+
return jsonbInsertExpressions;
|
|
1533
|
+
}
|
|
1534
|
+
getInsertExprFromJsonbDef(queryValue, columnType) {
|
|
1535
|
+
const listAppendParams = this.getListAppendDefFromValue(
|
|
1536
|
+
queryValue,
|
|
1537
|
+
columnType
|
|
1538
|
+
);
|
|
1539
|
+
if (listAppendParams != null) {
|
|
1540
|
+
queryValue = queryValue.replace(
|
|
1541
|
+
listAppendParams.originalString,
|
|
1542
|
+
listAppendParams.functionExpr
|
|
1543
|
+
);
|
|
1544
|
+
}
|
|
1545
|
+
return queryValue;
|
|
1546
|
+
}
|
|
1547
|
+
replacePathAndValueByAttributeNames(actions, options, columns, actionName) {
|
|
1548
|
+
return actions.map((action) => {
|
|
1549
|
+
action.path = this.replaceExpressionAttributeNames(
|
|
1550
|
+
action.path,
|
|
1551
|
+
options
|
|
1552
|
+
);
|
|
1553
|
+
if (typeof action.value == "string" && action.value.includes("list_append")) {
|
|
1554
|
+
action.path = action.path.split(".")[0];
|
|
1555
|
+
const column = columns[action.path];
|
|
1556
|
+
action.value = this.replaceExpressionAttributeValuesForDynamoFunctions(
|
|
1557
|
+
action.value,
|
|
1558
|
+
options
|
|
1559
|
+
);
|
|
1560
|
+
action.value = this.getInsertExprFromJsonbDef(
|
|
1561
|
+
action.value,
|
|
1562
|
+
column.type
|
|
1563
|
+
);
|
|
1564
|
+
action.dynamoFuncName = "list_append";
|
|
1565
|
+
} else {
|
|
1566
|
+
action.value = this.replaceExpressionAttributeValues(
|
|
1567
|
+
action.value,
|
|
1568
|
+
options
|
|
1569
|
+
);
|
|
1570
|
+
}
|
|
1571
|
+
action.actionName = actionName;
|
|
1572
|
+
action.createNewColumn = true;
|
|
1573
|
+
return action;
|
|
1574
|
+
});
|
|
1575
|
+
}
|
|
1576
|
+
replaceExpressionAttributeValuesForDynamoFunctions(value, options) {
|
|
1577
|
+
const { expressionAttributeNames, expressionAttributeValues } = options;
|
|
1578
|
+
const exprAttributeNamesKeys = expressionAttributeNames ? Object.keys(expressionAttributeNames) : [];
|
|
1579
|
+
const exprAttributeValuesKeys = expressionAttributeValues ? Object.keys(expressionAttributeValues) : [];
|
|
1580
|
+
if (exprAttributeNamesKeys.length > 0) {
|
|
1581
|
+
exprAttributeNamesKeys.forEach((exprAttribute) => {
|
|
1582
|
+
value = value.replace(
|
|
1583
|
+
exprAttribute,
|
|
1584
|
+
expressionAttributeNames[exprAttribute]
|
|
1585
|
+
);
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
if (exprAttributeValuesKeys.length > 0) {
|
|
1589
|
+
exprAttributeValuesKeys.forEach((exprAttribute) => {
|
|
1590
|
+
const valueSerialized = this.serializeJSONValue(
|
|
1591
|
+
expressionAttributeValues[exprAttribute]
|
|
1592
|
+
);
|
|
1593
|
+
value = value.replace(exprAttribute, `${valueSerialized}`);
|
|
1594
|
+
});
|
|
1595
|
+
}
|
|
1596
|
+
return value;
|
|
1597
|
+
}
|
|
1598
|
+
replaceExpressionAttributeNames(path, options) {
|
|
1599
|
+
const { expressionAttributeNames } = options;
|
|
1600
|
+
if (expressionAttributeNames) {
|
|
1601
|
+
Object.keys(expressionAttributeNames).forEach(
|
|
1602
|
+
(attributeName) => {
|
|
1603
|
+
const attributeNameValue = expressionAttributeNames[attributeName];
|
|
1604
|
+
path = path.replace(attributeName, attributeNameValue);
|
|
1605
|
+
}
|
|
1606
|
+
);
|
|
1607
|
+
}
|
|
1608
|
+
return path;
|
|
1609
|
+
}
|
|
1610
|
+
replaceExpressionAttributeValues(value, options) {
|
|
1611
|
+
const { expressionAttributeValues } = options;
|
|
1612
|
+
if (expressionAttributeValues[value] != void 0) {
|
|
1613
|
+
return expressionAttributeValues[value];
|
|
1614
|
+
}
|
|
1615
|
+
return value;
|
|
1616
|
+
}
|
|
1617
|
+
};
|
|
1618
|
+
|
|
1619
|
+
// src/services/cruds/postgresql/postgreSqlCrud.service.ts
|
|
1620
|
+
var PostgreSqlCrudService = class extends PostgresqlClientService {
|
|
1621
|
+
constructor(tableSchema) {
|
|
1622
|
+
super(tableSchema);
|
|
1623
|
+
this.tableSchema = tableSchema;
|
|
1624
|
+
}
|
|
1625
|
+
get idColumnName() {
|
|
1626
|
+
return findIdColumnName(this.tableSchema.columns);
|
|
1627
|
+
}
|
|
1628
|
+
normalizeInputData(inputData) {
|
|
1629
|
+
var _a;
|
|
1630
|
+
inputData.qvAttributes = {};
|
|
1631
|
+
for (const key in inputData) {
|
|
1632
|
+
if (!this.tableSchema.columns[key] && key !== "qvAttributes") {
|
|
1633
|
+
inputData.qvAttributes[key] = inputData[key];
|
|
1634
|
+
delete inputData[key];
|
|
1635
|
+
} else if (Array.isArray(inputData[key]) && ((_a = this.tableSchema.columns[key]) == null ? void 0 : _a.type) !== "array") {
|
|
1636
|
+
inputData[key] = JSON.stringify(inputData[key]);
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
getItem(data) {
|
|
1641
|
+
const resultItem = __spreadValues(__spreadValues({}, data), data.qvAttributes);
|
|
1642
|
+
delete resultItem["qvAttributes"];
|
|
1643
|
+
return resultItem;
|
|
1644
|
+
}
|
|
1645
|
+
prepareData(data) {
|
|
1646
|
+
const inputData = __spreadValues({}, data);
|
|
1647
|
+
this.normalizeInputData(inputData);
|
|
1648
|
+
return inputData;
|
|
1649
|
+
}
|
|
1650
|
+
create(data) {
|
|
1651
|
+
if (Array.isArray(data)) {
|
|
1652
|
+
const inputDataArray = data.map((item) => this.prepareData(item));
|
|
1653
|
+
return this.createCommand(inputDataArray).then((result) => ({
|
|
1654
|
+
unprocessedItems: result.filter((r) => !r.success).map((r) => r.inputData)
|
|
1655
|
+
}));
|
|
1656
|
+
} else {
|
|
1657
|
+
const inputData = this.prepareData(data);
|
|
1658
|
+
return this.createCommand([inputData]).then(
|
|
1659
|
+
(result) => result.rowCount ? this.getItem(result.rows[0]) : null
|
|
1660
|
+
);
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
findItem(findOptions) {
|
|
1664
|
+
return this.findCommand(findOptions).then((data) => {
|
|
1665
|
+
return (data == null ? void 0 : data.length) ? this.getItem(data[0]) : null;
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1668
|
+
async processQueryResult(findOptions, omitPagination = false) {
|
|
1669
|
+
const rows = await this.findCommand(findOptions);
|
|
1670
|
+
const items = rows.map(
|
|
1671
|
+
(row) => this.getItem(row)
|
|
1672
|
+
);
|
|
1673
|
+
const { limit, from } = (findOptions == null ? void 0 : findOptions.pagination) || {};
|
|
1674
|
+
const hasMoreRecords = items.length && items.length === limit;
|
|
1675
|
+
const newFrom = limit && hasMoreRecords ? limit + (from || 0) : null;
|
|
1676
|
+
const result = {
|
|
1677
|
+
items,
|
|
1678
|
+
pagination: omitPagination ? null : { limit, from: newFrom },
|
|
1679
|
+
count: items.length
|
|
1680
|
+
};
|
|
1681
|
+
return result;
|
|
1682
|
+
}
|
|
1683
|
+
async find(findOptions) {
|
|
1684
|
+
return this.processQueryResult(findOptions);
|
|
1685
|
+
}
|
|
1686
|
+
async findAll(findOptions) {
|
|
1687
|
+
return this.processQueryResult(findOptions, true);
|
|
1688
|
+
}
|
|
1689
|
+
async findCount(findOptions) {
|
|
1690
|
+
const items = await this.findCommand(__spreadProps(__spreadValues({}, findOptions), {
|
|
1691
|
+
aggregateFunction: "COUNT" /* COUNT */
|
|
1692
|
+
}));
|
|
1693
|
+
const aggFunctionProperty = buildAggFunctionAlias(
|
|
1694
|
+
"COUNT" /* COUNT */
|
|
1695
|
+
);
|
|
1696
|
+
const item = items.length ? items[0] : {};
|
|
1697
|
+
return item[aggFunctionProperty] || 0;
|
|
1698
|
+
}
|
|
1699
|
+
async update(filters, data) {
|
|
1700
|
+
const savedRecord = await this.findItem({ filters });
|
|
1701
|
+
const inputData = __spreadValues(__spreadValues({}, savedRecord), data);
|
|
1702
|
+
await this.updateCommand(filters, this.prepareData(inputData));
|
|
1703
|
+
return this.getItem(inputData);
|
|
1704
|
+
}
|
|
1705
|
+
async remove(filters, options) {
|
|
1706
|
+
await this.deleteCommand(filters, options == null ? void 0 : options.filterGroups);
|
|
1707
|
+
}
|
|
1708
|
+
runQuery(querySentence, values) {
|
|
1709
|
+
return super.runQuery(querySentence, values);
|
|
1710
|
+
}
|
|
1711
|
+
async updateExpressions(filters, actions, options) {
|
|
1712
|
+
const result = await this.updateExpressionCommand(
|
|
1713
|
+
filters,
|
|
1714
|
+
actions,
|
|
1715
|
+
options
|
|
1716
|
+
);
|
|
1717
|
+
return PersistenceErrorWrapper(result);
|
|
1718
|
+
}
|
|
1719
|
+
};
|
|
24
1720
|
|
|
25
1721
|
// src/services/crudFactory.service.ts
|
|
26
1722
|
var CrudFactory = class {
|
|
27
|
-
static
|
|
1723
|
+
static databaseClientService(crudSchema) {
|
|
28
1724
|
var _a;
|
|
29
1725
|
const isMultiPlatformMode2 = ((_a = process.env.PLATFORM_TYPE) == null ? void 0 : _a.toLowerCase()) === "container";
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
DatabaseCrudService = module.PostgreSqlCrudService;
|
|
34
|
-
} else {
|
|
35
|
-
const module = await import('./dynamoDbCrud.service-EFYPBZKN.mjs');
|
|
36
|
-
DatabaseCrudService = module.DynamoDbCrudService;
|
|
37
|
-
}
|
|
38
|
-
return new DatabaseCrudService(crudSchema, poolClient);
|
|
1726
|
+
if (isMultiPlatformMode2)
|
|
1727
|
+
return new PostgreSqlCrudService(crudSchema);
|
|
1728
|
+
return new DynamoDbCrudService(crudSchema);
|
|
39
1729
|
}
|
|
40
1730
|
};
|
|
41
1731
|
|
|
@@ -47,8 +1737,7 @@ var CrudService = class {
|
|
|
47
1737
|
}
|
|
48
1738
|
async getCrudServiceInstance() {
|
|
49
1739
|
const crudService = await CrudFactory.databaseClientService(
|
|
50
|
-
this.crudSchema
|
|
51
|
-
this.poolClient
|
|
1740
|
+
this.crudSchema
|
|
52
1741
|
);
|
|
53
1742
|
return crudService;
|
|
54
1743
|
}
|