drapcode-utility 2.3.9 → 2.4.1
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/build/utils/rest-client.js +15 -1
- package/build/utils/util.d.ts +11 -4
- package/build/utils/util.js +24 -26
- package/package.json +3 -3
|
@@ -306,7 +306,7 @@ const makeMySqlCall = async (projectId, data, extDbSetting) => {
|
|
|
306
306
|
database: mysqlDbName,
|
|
307
307
|
port: mysqlDbPort,
|
|
308
308
|
};
|
|
309
|
-
console.log(`==> Final MySQL
|
|
309
|
+
console.log(`==> Final MySQL projectID: ${projectId} ~ data:>> `, data, " ~ query type :>> ", operation, " ~ finalSql:>> ", finalSql, " ~ values:>> ", values);
|
|
310
310
|
const connection = await (0, util_1.createMySqlConnection)(mysqlDBConfig);
|
|
311
311
|
try {
|
|
312
312
|
const [rows] = await connection.execute(finalSql, values);
|
|
@@ -314,12 +314,26 @@ const makeMySqlCall = async (projectId, data, extDbSetting) => {
|
|
|
314
314
|
if (sqlPagination?.getTotal) {
|
|
315
315
|
total = await (0, util_1.getTotalRecords)(connection, sqlQuery, sqlParams);
|
|
316
316
|
}
|
|
317
|
+
let insertedId = null;
|
|
318
|
+
let updatedId = null;
|
|
319
|
+
if (operation === 'insert') {
|
|
320
|
+
insertedId = rows?.insertId || null;
|
|
321
|
+
}
|
|
322
|
+
else if (operation === 'update') {
|
|
323
|
+
const hasLastInsertId = finalSql.toLowerCase().includes("last_insert_id(");
|
|
324
|
+
console.log(`==> MySQL projectID: ${projectId} ~ hasLastInsertId:`, hasLastInsertId);
|
|
325
|
+
if (hasLastInsertId) {
|
|
326
|
+
updatedId = await (0, util_1.getLastUpdatedId)(connection, sqlParams);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
317
329
|
result = {
|
|
318
330
|
status: 200,
|
|
319
331
|
success: true,
|
|
320
332
|
data: {
|
|
321
333
|
content: rows,
|
|
322
334
|
totalRecords: total,
|
|
335
|
+
lastInsertedId: insertedId,
|
|
336
|
+
lastUpdatedId: updatedId,
|
|
323
337
|
returned: Array.isArray(rows) ? rows.length : 0
|
|
324
338
|
},
|
|
325
339
|
totalRecords: total,
|
package/build/utils/util.d.ts
CHANGED
|
@@ -155,21 +155,28 @@ type responseDataType = {
|
|
|
155
155
|
data: any;
|
|
156
156
|
};
|
|
157
157
|
export declare const getAwsSignature: (axiosConfig: any, awsSignPluginConfig: any) => Promise<responseDataType>;
|
|
158
|
+
/**
|
|
159
|
+
* MySQL Helper to create connection
|
|
160
|
+
*/
|
|
158
161
|
export declare const createMySqlConnection: (config: any) => Promise<any>;
|
|
159
162
|
/**
|
|
160
|
-
* Helper to parse search query string into SQL WHERE clause
|
|
163
|
+
* MySQL Helper to parse search query string into SQL WHERE clause
|
|
161
164
|
*/
|
|
162
165
|
export declare const buildWhereClause: (searchQuery: string) => string;
|
|
163
166
|
/**
|
|
164
|
-
* Helper to build ORDER BY clause
|
|
167
|
+
* MySQL Helper to build ORDER BY clause
|
|
165
168
|
*/
|
|
166
169
|
export declare const buildOrderByClause: (sqlSort: any) => string;
|
|
167
170
|
/**
|
|
168
|
-
* Helper to build LIMIT/OFFSET clause and update values array
|
|
171
|
+
* MySQL Helper to build LIMIT/OFFSET clause and update values array
|
|
169
172
|
*/
|
|
170
173
|
export declare const buildLimitOffsetClause: (sqlPagination: any, values: any[]) => string;
|
|
171
174
|
/**
|
|
172
|
-
* Helper to get total record count for pagination
|
|
175
|
+
* MySQL Helper to get total record count for pagination
|
|
173
176
|
*/
|
|
174
177
|
export declare const getTotalRecords: (connection: any, sqlQuery: string, sqlParams: any[]) => Promise<number | null>;
|
|
178
|
+
/**
|
|
179
|
+
* MySQL Helper to get last updated ID
|
|
180
|
+
*/
|
|
181
|
+
export declare const getLastUpdatedId: (connection: any, sqlParams: any[]) => Promise<number | null>;
|
|
175
182
|
export {};
|
package/build/utils/util.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.multiply = exports.average = exports.substraction = exports.addition = exports.validateNumbers = exports.checkAndConvertNumber = exports.evaluateCustomSentence = exports.strJoin = exports.markdownToHtml = exports.substr = exports.truncate = exports.titleCase = exports.trim = exports.slugify = exports.upperCase = exports.lowerCase = exports.capitalize = exports.replaceUnderscoreWithSlash = exports.replaceSlashWithUnderscore = exports.toggleConsoleLogs = exports.validateUrl = exports.validateData = exports.fillDefaultValues = exports.replaceValueFromSource = exports.processFieldsInclude = exports.removeMongoDbId = exports.replaceTransferObjectValueIntoExpression = exports.unflattenObject = exports.parseValueFromData = exports.parseJsonString = exports.replaceDataValueIntoExpression = exports.formatCustomCSSClasses = exports.validateAlphanumericString = exports.convertItemToArray = exports.arraysEqual = exports.checkAndCompareValue = exports.restructureData = exports.formatCollectionAndFieldName = exports.cleanCollectionAndFieldName = exports.getSpecialCharectorReplacedExpression = exports.validateUuidString = exports.validateEmail = exports.dynamicSort = exports.isObject = exports.isEmptyObject = exports.isEmpty = exports.clearSpaceAndReformat = exports.camelize = exports.validateString = exports.nonFindQuery = void 0;
|
|
7
|
-
exports.getTotalRecords = exports.buildLimitOffsetClause = exports.buildOrderByClause = exports.buildWhereClause = exports.createMySqlConnection = exports.getAwsSignature = exports.replaceValuesFromRequestMapping = exports.replaceValuesFromObjArr = exports.checkFieldValueType = exports.getPrimaryFieldNameOfDataSource = exports.getFieldSchemaForDataSourcePrimaryId = exports.getMappingObjKey = exports.getItemDataForArrayFields = exports.getFileObjectList = exports.getFindQuery = exports.mergeObjects = exports.dateDifference = exports.formatDate = exports.evaluateJSLogic = exports.evaluateCurrency = exports.evaluateExpression = exports.divide = void 0;
|
|
7
|
+
exports.getLastUpdatedId = exports.getTotalRecords = exports.buildLimitOffsetClause = exports.buildOrderByClause = exports.buildWhereClause = exports.createMySqlConnection = exports.getAwsSignature = exports.replaceValuesFromRequestMapping = exports.replaceValuesFromObjArr = exports.checkFieldValueType = exports.getPrimaryFieldNameOfDataSource = exports.getFieldSchemaForDataSourcePrimaryId = exports.getMappingObjKey = exports.getItemDataForArrayFields = exports.getFileObjectList = exports.getFindQuery = exports.mergeObjects = exports.dateDifference = exports.formatDate = exports.evaluateJSLogic = exports.evaluateCurrency = exports.evaluateExpression = exports.divide = void 0;
|
|
8
8
|
const drapcode_constant_1 = require("drapcode-constant");
|
|
9
9
|
const lodash_1 = __importDefault(require("lodash"));
|
|
10
10
|
const showdown_1 = __importDefault(require("showdown"));
|
|
@@ -302,37 +302,32 @@ const replaceDataValueIntoExpression = (expression, data, user, tenant, userSett
|
|
|
302
302
|
console.log("1 replaceDataValueIntoExpression");
|
|
303
303
|
contentList?.forEach((prop) => {
|
|
304
304
|
const needle = `{{${prop}}}`;
|
|
305
|
-
console.log("needle :>> ", needle);
|
|
306
305
|
let dataOfItem = "";
|
|
307
|
-
if (prop.includes("current_user")) {
|
|
308
|
-
console.log("Current User");
|
|
306
|
+
if (prop.includes("current_user") && user) {
|
|
309
307
|
prop = prop.replace("current_user.", "");
|
|
310
308
|
if (Object.keys(user).length > 0) {
|
|
311
309
|
dataOfItem = (0, exports.parseValueFromData)(user, prop);
|
|
312
310
|
}
|
|
313
311
|
}
|
|
314
|
-
else if (prop.includes("current_tenant")) {
|
|
315
|
-
console.log("Current Tenant");
|
|
312
|
+
else if (prop.includes("current_tenant") && tenant) {
|
|
316
313
|
prop = prop.replace("current_tenant.", "");
|
|
317
314
|
if (Object.keys(tenant).length > 0) {
|
|
318
315
|
dataOfItem = (0, exports.parseValueFromData)(tenant, prop);
|
|
319
316
|
}
|
|
320
317
|
}
|
|
321
|
-
else if (prop.includes("current_settings")) {
|
|
322
|
-
console.log("Current Setting");
|
|
318
|
+
else if (prop.includes("current_settings") && userSetting) {
|
|
323
319
|
prop = prop.replace("current_settings.", "");
|
|
324
320
|
if (Object.keys(userSetting).length > 0) {
|
|
325
321
|
dataOfItem = (0, exports.parseValueFromData)(userSetting, prop);
|
|
326
322
|
}
|
|
327
323
|
}
|
|
328
|
-
else if (prop.includes("current_sub_tenant")) {
|
|
324
|
+
else if (prop.includes("current_sub_tenant") && subTenant) {
|
|
329
325
|
prop = prop.replace("current_sub_tenant.", "");
|
|
330
326
|
if (Object.keys(userSetting).length > 0) {
|
|
331
327
|
dataOfItem = (0, exports.parseValueFromData)(subTenant, prop);
|
|
332
328
|
}
|
|
333
329
|
}
|
|
334
330
|
else if (prop.includes("current_session")) {
|
|
335
|
-
console.log("Current Session");
|
|
336
331
|
prop = prop.replace("current_session.", "");
|
|
337
332
|
if (Object.keys(sessionValue).length > 0) {
|
|
338
333
|
//Session will contain multi level data
|
|
@@ -340,7 +335,6 @@ const replaceDataValueIntoExpression = (expression, data, user, tenant, userSett
|
|
|
340
335
|
}
|
|
341
336
|
}
|
|
342
337
|
else if (prop.includes("form_data_session")) {
|
|
343
|
-
console.log("Form Data Session");
|
|
344
338
|
prop = prop.replace("form_data_session.", "");
|
|
345
339
|
if (Object.keys(sessionFormValue).length > 0) {
|
|
346
340
|
//Form Session will contain multi level data
|
|
@@ -348,7 +342,6 @@ const replaceDataValueIntoExpression = (expression, data, user, tenant, userSett
|
|
|
348
342
|
}
|
|
349
343
|
}
|
|
350
344
|
else if (prop.includes("SESSION_STORAGE")) {
|
|
351
|
-
console.log("Session Storage");
|
|
352
345
|
prop = prop.replace("SESSION_STORAGE.", "");
|
|
353
346
|
if (Object.keys(sessionValue).length > 0) {
|
|
354
347
|
//Session will contain multi level data
|
|
@@ -356,7 +349,6 @@ const replaceDataValueIntoExpression = (expression, data, user, tenant, userSett
|
|
|
356
349
|
}
|
|
357
350
|
}
|
|
358
351
|
else if (prop.includes("LOCAL_STORAGE")) {
|
|
359
|
-
console.log("Local Storage");
|
|
360
352
|
prop = prop.replace("LOCAL_STORAGE.", "");
|
|
361
353
|
if (Object.keys(localStorageValue).length > 0) {
|
|
362
354
|
//Session will contain multi level data
|
|
@@ -364,7 +356,6 @@ const replaceDataValueIntoExpression = (expression, data, user, tenant, userSett
|
|
|
364
356
|
}
|
|
365
357
|
}
|
|
366
358
|
else if (prop.includes("COOKIES")) {
|
|
367
|
-
console.log("Cookies");
|
|
368
359
|
prop = prop.replace("COOKIES.", "");
|
|
369
360
|
if (Object.keys(cookiesValue).length > 0) {
|
|
370
361
|
//Session will contain multi level data
|
|
@@ -372,7 +363,6 @@ const replaceDataValueIntoExpression = (expression, data, user, tenant, userSett
|
|
|
372
363
|
}
|
|
373
364
|
}
|
|
374
365
|
else if (prop.includes("environment_variable")) {
|
|
375
|
-
console.log("Environment Variable");
|
|
376
366
|
prop = prop.replace("environment_variable.", "");
|
|
377
367
|
if (Object.keys(envConstants).length > 0) {
|
|
378
368
|
const selectedConstant = envConstants.find((constant) => constant.name === prop);
|
|
@@ -380,16 +370,11 @@ const replaceDataValueIntoExpression = (expression, data, user, tenant, userSett
|
|
|
380
370
|
}
|
|
381
371
|
}
|
|
382
372
|
else {
|
|
383
|
-
console.log("Nothing Matches");
|
|
384
373
|
if (Object.keys(data).length > 0) {
|
|
385
374
|
dataOfItem = (0, exports.parseValueFromData)(data, prop);
|
|
386
|
-
//TODO: Need better way
|
|
387
|
-
delete data[prop];
|
|
388
375
|
}
|
|
389
376
|
}
|
|
390
|
-
console.log("dataOfItem :>> ", dataOfItem);
|
|
391
377
|
expression = replaceValueInExpression(needle, dataOfItem, expression);
|
|
392
|
-
console.log("expression :>> ", expression);
|
|
393
378
|
});
|
|
394
379
|
return expression;
|
|
395
380
|
};
|
|
@@ -448,7 +433,6 @@ const parseValueFromData = (data, fieldName) => {
|
|
|
448
433
|
else {
|
|
449
434
|
value = data ? data[fieldName] : "";
|
|
450
435
|
}
|
|
451
|
-
console.log("value :>> ", value);
|
|
452
436
|
if (value && Array.isArray(value) && typeof value[0] === "string") {
|
|
453
437
|
return value.join(", ");
|
|
454
438
|
}
|
|
@@ -1224,6 +1208,9 @@ const getAwsSignature = async (axiosConfig, awsSignPluginConfig) => {
|
|
|
1224
1208
|
return response;
|
|
1225
1209
|
};
|
|
1226
1210
|
exports.getAwsSignature = getAwsSignature;
|
|
1211
|
+
/**
|
|
1212
|
+
* MySQL Helper to create connection
|
|
1213
|
+
*/
|
|
1227
1214
|
const createMySqlConnection = async (config) => {
|
|
1228
1215
|
try {
|
|
1229
1216
|
const { host, user, password, database, port } = config || {};
|
|
@@ -1245,7 +1232,7 @@ const createMySqlConnection = async (config) => {
|
|
|
1245
1232
|
};
|
|
1246
1233
|
exports.createMySqlConnection = createMySqlConnection;
|
|
1247
1234
|
/**
|
|
1248
|
-
* Helper to parse search query string into SQL WHERE clause
|
|
1235
|
+
* MySQL Helper to parse search query string into SQL WHERE clause
|
|
1249
1236
|
*/
|
|
1250
1237
|
const buildWhereClause = (searchQuery) => {
|
|
1251
1238
|
if (!searchQuery)
|
|
@@ -1258,7 +1245,7 @@ const buildWhereClause = (searchQuery) => {
|
|
|
1258
1245
|
};
|
|
1259
1246
|
exports.buildWhereClause = buildWhereClause;
|
|
1260
1247
|
/**
|
|
1261
|
-
* Helper to build ORDER BY clause
|
|
1248
|
+
* MySQL Helper to build ORDER BY clause
|
|
1262
1249
|
*/
|
|
1263
1250
|
const buildOrderByClause = (sqlSort) => {
|
|
1264
1251
|
if (sqlSort?.column && sqlSort?.order) {
|
|
@@ -1269,18 +1256,20 @@ const buildOrderByClause = (sqlSort) => {
|
|
|
1269
1256
|
};
|
|
1270
1257
|
exports.buildOrderByClause = buildOrderByClause;
|
|
1271
1258
|
/**
|
|
1272
|
-
* Helper to build LIMIT/OFFSET clause and update values array
|
|
1259
|
+
* MySQL Helper to build LIMIT/OFFSET clause and update values array
|
|
1273
1260
|
*/
|
|
1274
1261
|
const buildLimitOffsetClause = (sqlPagination, values) => {
|
|
1275
1262
|
if (sqlPagination?.limit && sqlPagination?.offset !== undefined) {
|
|
1263
|
+
const limit = Math.max(Number(sqlPagination.limit) || 10, 1);
|
|
1264
|
+
const offset = Math.max(Number(sqlPagination.offset) || 0, 0);
|
|
1276
1265
|
values.push(parseInt(sqlPagination.limit), parseInt(sqlPagination.offset));
|
|
1277
|
-
return
|
|
1266
|
+
return ` LIMIT ${limit} OFFSET ${offset}`;
|
|
1278
1267
|
}
|
|
1279
1268
|
return "";
|
|
1280
1269
|
};
|
|
1281
1270
|
exports.buildLimitOffsetClause = buildLimitOffsetClause;
|
|
1282
1271
|
/**
|
|
1283
|
-
* Helper to get total record count for pagination
|
|
1272
|
+
* MySQL Helper to get total record count for pagination
|
|
1284
1273
|
*/
|
|
1285
1274
|
const getTotalRecords = async (connection, sqlQuery, sqlParams) => {
|
|
1286
1275
|
const countSql = `SELECT COUNT(*) as total FROM (${sqlQuery}) as count_table`;
|
|
@@ -1288,3 +1277,12 @@ const getTotalRecords = async (connection, sqlQuery, sqlParams) => {
|
|
|
1288
1277
|
return countRows[0]?.total ?? null;
|
|
1289
1278
|
};
|
|
1290
1279
|
exports.getTotalRecords = getTotalRecords;
|
|
1280
|
+
/**
|
|
1281
|
+
* MySQL Helper to get last updated ID
|
|
1282
|
+
*/
|
|
1283
|
+
const getLastUpdatedId = async (connection, sqlParams) => {
|
|
1284
|
+
const lastUpdatedIdSql = `SELECT LAST_INSERT_ID() as lastId`;
|
|
1285
|
+
const [lastUpdatedIdRows] = await connection.execute(lastUpdatedIdSql, sqlParams);
|
|
1286
|
+
return lastUpdatedIdRows[0]?.lastId ?? null;
|
|
1287
|
+
};
|
|
1288
|
+
exports.getLastUpdatedId = getLastUpdatedId;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drapcode-utility",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "DrapCode Utility",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"axios": "^1.1.2",
|
|
43
43
|
"date-fns": "^4.1.0",
|
|
44
44
|
"dompurify": "^3.1.7",
|
|
45
|
-
"drapcode-constant": "^1.9.
|
|
45
|
+
"drapcode-constant": "^1.9.8",
|
|
46
46
|
"drapcode-logger": "^1.3.5",
|
|
47
|
-
"drapcode-redis": "^1.4.
|
|
47
|
+
"drapcode-redis": "^1.4.4",
|
|
48
48
|
"exiftool-vendored": "^28.2.1",
|
|
49
49
|
"express": "^4.17.1",
|
|
50
50
|
"gm": "^1.25.0",
|