drapcode-utility 1.3.0 → 1.3.2

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.
@@ -72,6 +72,12 @@ export declare const prepareCollectionQuery: (matchQuery: object, filterId: stri
72
72
  isPrivate: {
73
73
  $first: string;
74
74
  };
75
+ enableLookup: {
76
+ $first: string;
77
+ };
78
+ lookups: {
79
+ $first: string;
80
+ };
75
81
  finder: {
76
82
  $first: string;
77
83
  };
@@ -116,6 +122,8 @@ export declare const prepareCollectionQuery: (matchQuery: object, filterId: stri
116
122
  noOfExternalParams: number;
117
123
  finder: string;
118
124
  isInMemory: number;
125
+ lookups: number;
126
+ enableLookup: number;
119
127
  lastRefreshTime: number;
120
128
  constants: number;
121
129
  collectionName: number;
@@ -130,3 +138,6 @@ export declare const prepareCollectionQuery: (matchQuery: object, filterId: stri
130
138
  $unwind?: undefined;
131
139
  $group?: undefined;
132
140
  })[];
141
+ export declare const prepareCreatedByLookup: (lookupConfig: any, aggregateQuery: any[], field: any) => void;
142
+ export declare const prepareChildRefCreatedByLookup: (collectionName: string, findCollInLookup: any, lookupConfig: any, field: any, aggregateQuery: any[]) => void;
143
+ export declare const commonLookupSetting: (field: any, lookupConfig: any, aggregateQuery: any) => void;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prepareCollectionQuery = void 0;
3
+ exports.commonLookupSetting = exports.prepareChildRefCreatedByLookup = exports.prepareCreatedByLookup = exports.prepareCollectionQuery = void 0;
4
+ var drapcode_constant_1 = require("drapcode-constant");
4
5
  var prepareCollectionQuery = function (matchQuery, filterId) {
5
6
  var query = [
6
7
  { $match: matchQuery },
@@ -46,6 +47,8 @@ var prepareCollectionQuery = function (matchQuery, filterId) {
46
47
  fields: { $first: "$fields" },
47
48
  noOfExternalParams: { $first: "$finder.noOfExternalParams" },
48
49
  isPrivate: { $first: "$finder.isPrivate" },
50
+ enableLookup: { $first: "$finder.enableLookup" },
51
+ lookups: { $first: "$finder.lookups" },
49
52
  finder: { $first: "$finder" },
50
53
  refCollectionFields: { $first: "$refCollectionFields" },
51
54
  constants: { $first: "$constants" },
@@ -78,6 +81,8 @@ var prepareCollectionQuery = function (matchQuery, filterId) {
78
81
  noOfExternalParams: 1,
79
82
  finder: "$filterFinder",
80
83
  isInMemory: 1,
84
+ lookups: 1,
85
+ enableLookup: 1,
81
86
  lastRefreshTime: 1,
82
87
  constants: 1,
83
88
  collectionName: 1,
@@ -92,3 +97,121 @@ var prepareCollectionQuery = function (matchQuery, filterId) {
92
97
  return query;
93
98
  };
94
99
  exports.prepareCollectionQuery = prepareCollectionQuery;
100
+ var prepareCreatedByLookup = function (lookupConfig, aggregateQuery, field) {
101
+ var _a;
102
+ var enableLookup = lookupConfig.enableLookup, lookups = lookupConfig.lookups;
103
+ var findCollInLookup = lookups
104
+ ? lookups.find(function (lkp) { return lkp.collectionName === "createdBy"; })
105
+ : null;
106
+ if (!enableLookup || findCollInLookup) {
107
+ aggregateQuery.push({
108
+ $lookup: {
109
+ from: "user",
110
+ let: (_a = {}, _a["" + field.fieldName] = "$" + field.fieldName, _a),
111
+ pipeline: [
112
+ {
113
+ $match: {
114
+ $expr: { $eq: ["$uuid", "$$" + field.fieldName] },
115
+ },
116
+ },
117
+ { $project: { _id: 0, password: 0 } },
118
+ ],
119
+ as: field.fieldName,
120
+ },
121
+ });
122
+ }
123
+ };
124
+ exports.prepareCreatedByLookup = prepareCreatedByLookup;
125
+ var prepareChildRefCreatedByLookup = function (collectionName, findCollInLookup, lookupConfig, field, aggregateQuery) {
126
+ var _a;
127
+ var enableLookup = lookupConfig.enableLookup;
128
+ var pPipeline = [];
129
+ pPipeline.push({
130
+ $match: {
131
+ $expr: {
132
+ $in: [
133
+ "$uuid",
134
+ {
135
+ $cond: {
136
+ if: {
137
+ $in: ["$$" + field.fieldName, ["", null]],
138
+ },
139
+ then: [],
140
+ else: {
141
+ $ifNull: ["$$" + field.fieldName, []],
142
+ },
143
+ },
144
+ },
145
+ ],
146
+ },
147
+ },
148
+ });
149
+ var findChildLookup = findCollInLookup && findCollInLookup.childLookups
150
+ ? findCollInLookup.childLookups.find(function (chlkp) { return chlkp.collectionName === "createdBy"; })
151
+ : null;
152
+ if (!enableLookup || findChildLookup) {
153
+ pPipeline.push({
154
+ $lookup: {
155
+ from: "user",
156
+ let: { createdBy: "$createdBy" },
157
+ pipeline: [
158
+ {
159
+ $match: {
160
+ $expr: { $eq: ["$uuid", "$$createdBy"] },
161
+ },
162
+ },
163
+ { $project: { _id: 0, password: 0 } },
164
+ ],
165
+ as: "createdBy",
166
+ },
167
+ });
168
+ }
169
+ aggregateQuery.push({
170
+ $lookup: {
171
+ from: "" + collectionName,
172
+ let: (_a = {}, _a["" + field.fieldName] = "$" + field.fieldName, _a),
173
+ pipeline: pPipeline,
174
+ as: field.fieldName,
175
+ },
176
+ });
177
+ };
178
+ exports.prepareChildRefCreatedByLookup = prepareChildRefCreatedByLookup;
179
+ var commonLookupSetting = function (field, lookupConfig, aggregateQuery) {
180
+ var _a;
181
+ console.log("lookupConfig commonLookupSetting", lookupConfig);
182
+ var enableLookup = lookupConfig.enableLookup, lookups = lookupConfig.lookups;
183
+ if (drapcode_constant_1.BelongsToReferenceField.includes(field.type)) {
184
+ var collectionName_1 = field.refCollection
185
+ ? field.refCollection["collectionName"]
186
+ : null;
187
+ if (collectionName_1) {
188
+ var findCollInLookup = lookups
189
+ ? lookups.find(function (lkp) { return lkp.collectionName === collectionName_1; })
190
+ : null;
191
+ if (!enableLookup || findCollInLookup) {
192
+ if (field.type === "belongsTo") {
193
+ aggregateQuery.push({
194
+ $lookup: {
195
+ from: "" + collectionName_1,
196
+ localField: field.fieldName,
197
+ foreignField: "uuid",
198
+ as: field.fieldName,
199
+ },
200
+ });
201
+ aggregateQuery.push({
202
+ $addFields: (_a = {},
203
+ _a["_$belongsToMetaData"] = field,
204
+ _a),
205
+ });
206
+ }
207
+ else {
208
+ exports.prepareChildRefCreatedByLookup(collectionName_1, findCollInLookup, lookupConfig, field, aggregateQuery);
209
+ }
210
+ }
211
+ }
212
+ }
213
+ if (field.type === "createdBy") {
214
+ exports.prepareCreatedByLookup(lookupConfig, aggregateQuery, field);
215
+ }
216
+ };
217
+ exports.commonLookupSetting = commonLookupSetting;
@@ -1,4 +1,4 @@
1
- export declare const queryParser: (collectionName: string, query: any, constants: any[], externalParams: any, currentUser: any, timezone: string, searchObj?: any, refCollectionFieldsInItems?: any, searchQueryTypeObj?: any, currentTenant?: any) => Promise<string>;
1
+ export declare const queryParser: (collectionName: string, query: any, constants: any[], externalParams: any, currentUser: any, timezone: string, searchObj?: any, refCollectionFieldsInItems?: any, searchQueryTypeObj?: any, currentTenant?: any, lookupConfig?: any) => Promise<string>;
2
2
  export declare const isEntityInCondition: (value: any) => boolean;
3
3
  export declare const getMinMaxValue: (value: any) => {
4
4
  startValue: any;
@@ -49,12 +49,14 @@ var moment_1 = __importDefault(require("moment"));
49
49
  var drapcode_constant_1 = require("drapcode-constant");
50
50
  var date_util_1 = require("./date-util");
51
51
  var util_1 = require("./util");
52
- var queryParser = function (collectionName, query, constants, externalParams, currentUser, timezone, searchObj, refCollectionFieldsInItems, searchQueryTypeObj, currentTenant) {
52
+ var prepare_query_1 = require("./prepare-query");
53
+ var queryParser = function (collectionName, query, constants, externalParams, currentUser, timezone, searchObj, refCollectionFieldsInItems, searchQueryTypeObj, currentTenant, lookupConfig) {
53
54
  if (currentUser === void 0) { currentUser = {}; }
54
55
  if (searchObj === void 0) { searchObj = null; }
55
56
  if (refCollectionFieldsInItems === void 0) { refCollectionFieldsInItems = null; }
56
57
  if (searchQueryTypeObj === void 0) { searchQueryTypeObj = {}; }
57
58
  if (currentTenant === void 0) { currentTenant = {}; }
59
+ if (lookupConfig === void 0) { lookupConfig = []; }
58
60
  return __awaiter(void 0, void 0, void 0, function () {
59
61
  var filterQuery, aggregateQuery, queryStr, searchQueryObj, _a, searchAggregateQuery, likeQuery, finalQuery, _b, searchAggregateQuery, likeQuery, projection, finder, sortBy, orderBy, offset, limit, direction, str;
60
62
  var _c, _d;
@@ -105,97 +107,17 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
105
107
  _b = getSearchObjQuery(searchObj, searchQueryTypeObj, timezone), searchAggregateQuery = _b.searchAggregateQuery, likeQuery = _b.likeQuery;
106
108
  aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery), searchAggregateQuery);
107
109
  if (likeQuery.length) {
108
- // aggregateQuery.push({ $match: { $or: likeQuery } });
109
110
  aggregateQuery.push({ $match: { $and: likeQuery } });
110
111
  }
111
112
  }
112
113
  console.log("aggregateQuery", JSON.stringify(aggregateQuery));
113
114
  console.log("==> query", query);
115
+ console.log("lookupConfig", lookupConfig);
114
116
  projection = mongoSelectQuery(query);
115
117
  finder = query.finder, sortBy = query.sortBy, orderBy = query.orderBy;
116
118
  if (!(finder != "COUNT" && refCollectionFieldsInItems)) return [3 /*break*/, 2];
117
119
  return [4 /*yield*/, Promise.all(refCollectionFieldsInItems.map(function (field) {
118
- var _a, _b, _c;
119
- if (["reference", "multi_reference", "belongsTo"].includes(field.type)) {
120
- var collectionName_1 = field.refCollection
121
- ? field.refCollection["collectionName"]
122
- : null;
123
- if (collectionName_1) {
124
- if (field.type === "belongsTo") {
125
- aggregateQuery.push({
126
- $lookup: {
127
- from: "" + collectionName_1,
128
- localField: field.fieldName,
129
- foreignField: "uuid",
130
- as: field.fieldName,
131
- },
132
- });
133
- aggregateQuery.push({
134
- $addFields: (_a = {},
135
- _a["_$belongsToMetaData"] = field,
136
- _a),
137
- });
138
- }
139
- else {
140
- aggregateQuery.push({
141
- $lookup: {
142
- from: "" + collectionName_1,
143
- let: (_b = {}, _b["" + field.fieldName] = "$" + field.fieldName, _b),
144
- pipeline: [
145
- {
146
- $match: {
147
- $expr: {
148
- $in: [
149
- "$uuid",
150
- {
151
- $cond: {
152
- if: {
153
- $in: ["$$" + field.fieldName, ["", null]],
154
- },
155
- then: [],
156
- else: { $ifNull: ["$$" + field.fieldName, []] },
157
- },
158
- },
159
- ],
160
- },
161
- },
162
- },
163
- {
164
- $lookup: {
165
- from: "user",
166
- let: { createdBy: "$createdBy" },
167
- pipeline: [
168
- {
169
- $match: {
170
- $expr: { $eq: ["$uuid", "$$createdBy"] },
171
- },
172
- },
173
- { $project: { _id: 0, password: 0 } },
174
- ],
175
- as: "createdBy",
176
- },
177
- },
178
- ],
179
- as: field.fieldName,
180
- },
181
- });
182
- }
183
- }
184
- }
185
- if (field.type === "createdBy")
186
- aggregateQuery.push({
187
- $lookup: {
188
- from: "user",
189
- let: (_c = {}, _c["" + field.fieldName] = "$" + field.fieldName, _c),
190
- pipeline: [
191
- {
192
- $match: { $expr: { $eq: ["$uuid", "$$" + field.fieldName] } },
193
- },
194
- { $project: { _id: 0, password: 0 } },
195
- ],
196
- as: field.fieldName,
197
- },
198
- });
120
+ return prepare_query_1.commonLookupSetting(field, lookupConfig, aggregateQuery);
199
121
  }))];
200
122
  case 1:
201
123
  _e.sent();
@@ -1 +1 @@
1
- export declare const queryParserNew: (collectionName: string, query: any, constants: any[], externalParams: any, currentUser: any, timezone: string, searchObj?: any, refCollectionFieldsInItems?: any, searchQueryTypeObj?: any) => Promise<string>;
1
+ export declare const queryParserNew: (collectionName: string, query: any, constants: any[], externalParams: any, currentUser: any, timezone: string, searchObj?: any, refCollectionFieldsInItems?: any, searchQueryTypeObj?: any, lookupConfig?: any) => Promise<string>;
@@ -45,11 +45,13 @@ exports.queryParserNew = void 0;
45
45
  var drapcode_constant_1 = require("drapcode-constant");
46
46
  var date_util_1 = require("./date-util");
47
47
  var util_1 = require("./util");
48
- var queryParserNew = function (collectionName, query, constants, externalParams, currentUser, timezone, searchObj, refCollectionFieldsInItems, searchQueryTypeObj) {
48
+ var prepare_query_1 = require("./prepare-query");
49
+ var queryParserNew = function (collectionName, query, constants, externalParams, currentUser, timezone, searchObj, refCollectionFieldsInItems, searchQueryTypeObj, lookupConfig) {
49
50
  if (currentUser === void 0) { currentUser = {}; }
50
51
  if (searchObj === void 0) { searchObj = null; }
51
52
  if (refCollectionFieldsInItems === void 0) { refCollectionFieldsInItems = null; }
52
53
  if (searchQueryTypeObj === void 0) { searchQueryTypeObj = {}; }
54
+ if (lookupConfig === void 0) { lookupConfig = []; }
53
55
  return __awaiter(void 0, void 0, void 0, function () {
54
56
  var filterQuery, aggregateQuery, queryStr, searchQueryObj_1, finalQuery, likeQuery_1, projection, finder, sortBy, orderBy, aggregateFunctionField, offset, limit, direction, str;
55
57
  var _a;
@@ -64,7 +66,7 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
64
66
  filterQuery = mongoFilterQuery(query, externalParams, constants, currentUser);
65
67
  console.log("**************************");
66
68
  console.log("**************************");
67
- console.log("filterQuery", filterQuery);
69
+ console.log("filterQuery", JSON.stringify(filterQuery));
68
70
  console.log("==> searchQueryTypeObj :>>", searchQueryTypeObj);
69
71
  aggregateQuery = [];
70
72
  queryStr = ".aggregate([])";
@@ -197,7 +199,6 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
197
199
  }
198
200
  });
199
201
  if (likeQuery_1.length) {
200
- // aggregateQuery.push({ $match: { $or: likeQuery } });
201
202
  aggregateQuery.push({ $match: { $and: likeQuery_1 } });
202
203
  }
203
204
  }
@@ -205,87 +206,7 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
205
206
  finder = query.finder, sortBy = query.sortBy, orderBy = query.orderBy, aggregateFunctionField = query.aggregateFunctionField;
206
207
  if (!(finder != "COUNT" && refCollectionFieldsInItems)) return [3 /*break*/, 2];
207
208
  return [4 /*yield*/, Promise.all(refCollectionFieldsInItems.map(function (field) {
208
- var _a, _b, _c;
209
- if (["reference", "multi_reference", "belongsTo"].includes(field.type)) {
210
- var collectionName_1 = field.refCollection
211
- ? field.refCollection["collectionName"]
212
- : null;
213
- if (collectionName_1) {
214
- if (field.type === "belongsTo") {
215
- aggregateQuery.push({
216
- $lookup: {
217
- from: "" + collectionName_1,
218
- localField: field.fieldName,
219
- foreignField: "uuid",
220
- as: field.fieldName,
221
- },
222
- });
223
- aggregateQuery.push({
224
- $addFields: (_a = {},
225
- _a["_$belongsToMetaData"] = field,
226
- _a),
227
- });
228
- }
229
- else {
230
- aggregateQuery.push({
231
- $lookup: {
232
- from: "" + collectionName_1,
233
- let: (_b = {}, _b["" + field.fieldName] = "$" + field.fieldName, _b),
234
- pipeline: [
235
- {
236
- $match: {
237
- $expr: {
238
- $in: [
239
- "$uuid",
240
- {
241
- $cond: {
242
- if: {
243
- $in: ["$$" + field.fieldName, ["", null]],
244
- },
245
- then: [],
246
- else: { $ifNull: ["$$" + field.fieldName, []] },
247
- },
248
- },
249
- ],
250
- },
251
- },
252
- },
253
- {
254
- $lookup: {
255
- from: "user",
256
- let: { createdBy: "$createdBy" },
257
- pipeline: [
258
- {
259
- $match: {
260
- $expr: { $eq: ["$uuid", "$$createdBy"] },
261
- },
262
- },
263
- { $project: { _id: 0, password: 0 } },
264
- ],
265
- as: "createdBy",
266
- },
267
- },
268
- ],
269
- as: field.fieldName,
270
- },
271
- });
272
- }
273
- }
274
- }
275
- if (field.type === "createdBy")
276
- aggregateQuery.push({
277
- $lookup: {
278
- from: "user",
279
- let: (_c = {}, _c["" + field.fieldName] = "$" + field.fieldName, _c),
280
- pipeline: [
281
- {
282
- $match: { $expr: { $eq: ["$uuid", "$$" + field.fieldName] } },
283
- },
284
- { $project: { _id: 0, password: 0 } },
285
- ],
286
- as: field.fieldName,
287
- },
288
- });
209
+ return prepare_query_1.commonLookupSetting(field, lookupConfig, aggregateQuery);
289
210
  }))];
290
211
  case 1:
291
212
  _b.sent();
@@ -19,7 +19,7 @@ export declare const checkAndCompareValue: (input1: any, input2: any) => boolean
19
19
  export declare const arraysEqual: (array1: any, array2: any) => boolean;
20
20
  export declare const convertItemToArray: (itemValue: any) => any[];
21
21
  export declare const validateAlphanumericString: (str: string) => false | "String should contain only numbers and letters";
22
- export declare const formatCustomCSSClasses: (projectCustomCSSClasses: any) => string;
22
+ export declare const formatCustomCSSClasses: (customClasses: any) => string;
23
23
  export declare const replaceDataValueIntoExpression: (expression: string, data: any, user: any, tenant: any, sessionValue: any, envConstants: any, sessionFormValue: any) => string;
24
24
  export declare const parseJsonString: (str: string) => any;
25
25
  export declare const parseValueFromData: (data: any, fieldName: string) => any;
@@ -27,3 +27,4 @@ export declare const unflattenObject: (obj: any) => {};
27
27
  export declare const replaceTransferObjectValueIntoExpression: (expression: string, transferObject: any) => string;
28
28
  export declare const removeMongoDbId: (result: any[]) => any[];
29
29
  export declare const processFieldsInlcude: (fieldsInclude: any) => any;
30
+ export declare const replaceValueFromSource: (variableName: any, environment: any, tenant: any) => any;
@@ -30,8 +30,39 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
30
30
  return (mod && mod.__esModule) ? mod : { "default": mod };
31
31
  };
32
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
- exports.processFieldsInlcude = 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.stringToExpression = exports.expressionToString = exports.getSpecialCharectorReplacedExpression = exports.validateUuidString = exports.validateEmail = exports.snakeCaseToTitleCase = exports.dynamicSort = exports.checkValidArray = exports.isObject = exports.isEmptyObject = exports.isEmpty = exports.clearSpaceAndReformat = exports.camelize = exports.validateString = void 0;
33
+ exports.replaceValueFromSource = exports.processFieldsInlcude = 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.stringToExpression = exports.expressionToString = exports.getSpecialCharectorReplacedExpression = exports.validateUuidString = exports.validateEmail = exports.snakeCaseToTitleCase = exports.dynamicSort = exports.checkValidArray = exports.isObject = exports.isEmptyObject = exports.isEmpty = exports.clearSpaceAndReformat = exports.camelize = exports.validateString = void 0;
34
34
  var lodash_1 = __importDefault(require("lodash"));
35
+ // TODO: Refactor
36
+ var derivedFieldExcludes = [
37
+ "formatType",
38
+ "restToLower",
39
+ "whitespace",
40
+ "type",
41
+ "noSplitopt",
42
+ "length",
43
+ "endopt",
44
+ "startLength",
45
+ "endLength",
46
+ "startString",
47
+ "endString",
48
+ "separator",
49
+ "expression",
50
+ "unixType",
51
+ "currency",
52
+ "maxFraction",
53
+ "position",
54
+ "refField",
55
+ "condition",
56
+ "match",
57
+ "refFieldType",
58
+ "index",
59
+ "positionOfRecords",
60
+ "numberOfRecords",
61
+ "elementToRender",
62
+ "indexNum",
63
+ ];
64
+ var environmentFixKey = "environment_variable.";
65
+ var tenantFixKey = "current_tenant.";
35
66
  var validateString = function (str) {
36
67
  var specialChar = /[`!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/;
37
68
  var isNumber = str.match(/\d+/g);
@@ -235,12 +266,12 @@ var validateAlphanumericString = function (str) {
235
266
  return false;
236
267
  };
237
268
  exports.validateAlphanumericString = validateAlphanumericString;
238
- var formatCustomCSSClasses = function (projectCustomCSSClasses) {
239
- if (!projectCustomCSSClasses || !Array.isArray(projectCustomCSSClasses)) {
269
+ var formatCustomCSSClasses = function (customClasses) {
270
+ if (!customClasses || !Array.isArray(customClasses)) {
240
271
  return "";
241
272
  }
242
273
  var projectCustomCSSClassesData = "";
243
- projectCustomCSSClasses.forEach(function (element) {
274
+ customClasses.forEach(function (element) {
244
275
  if (element.classProperty) {
245
276
  var classWithProp = JSON.stringify(element.classProperty);
246
277
  var unquotedClassWithProp = classWithProp
@@ -430,35 +461,6 @@ var removeMongoDbId = function (result) {
430
461
  return result.map(moveUuidToTopLevel);
431
462
  };
432
463
  exports.removeMongoDbId = removeMongoDbId;
433
- // TODO: Refactor
434
- var derivedFieldExcludes = [
435
- "formatType",
436
- "restToLower",
437
- "whitespace",
438
- "type",
439
- "noSplitopt",
440
- "length",
441
- "endopt",
442
- "startLength",
443
- "endLength",
444
- "startString",
445
- "endString",
446
- "separator",
447
- "expression",
448
- "unixType",
449
- "currency",
450
- "maxFraction",
451
- "position",
452
- "refField",
453
- "condition",
454
- "match",
455
- "refFieldType",
456
- "index",
457
- "positionOfRecords",
458
- "numberOfRecords",
459
- "elementToRender",
460
- "indexNum",
461
- ];
462
464
  var processFieldsInlcude = function (fieldsInclude) {
463
465
  var result = fieldsInclude;
464
466
  var refFieldsInclude = fieldsInclude.filter(function (field) {
@@ -509,3 +511,40 @@ var processDerivedFieldInclude = function (derivedFieldsInclude) {
509
511
  });
510
512
  return derivedFields;
511
513
  };
514
+ var replaceValueFromSource = function (variableName, environment, tenant) {
515
+ if (variableName && typeof variableName === "string") {
516
+ if (variableName.startsWith(environmentFixKey)) {
517
+ return replaceValueFromEnvironment(variableName, environment);
518
+ }
519
+ else if (variableName.startsWith(tenantFixKey)) {
520
+ return replaceValueFromTenant(variableName, tenant);
521
+ }
522
+ else {
523
+ return variableName;
524
+ }
525
+ }
526
+ else {
527
+ return variableName;
528
+ }
529
+ };
530
+ exports.replaceValueFromSource = replaceValueFromSource;
531
+ var replaceValueFromEnvironment = function (variableName, environment) {
532
+ if (variableName &&
533
+ typeof variableName === "string" &&
534
+ variableName.startsWith(environmentFixKey) &&
535
+ environment &&
536
+ environment.constants) {
537
+ var envConstant = environment.constants.find(function (env) { return env.name === variableName.replace(environmentFixKey, ""); });
538
+ return envConstant.value;
539
+ }
540
+ else {
541
+ return variableName;
542
+ }
543
+ };
544
+ var replaceValueFromTenant = function (variableName, tenant) {
545
+ if (!tenant) {
546
+ return variableName;
547
+ }
548
+ variableName = variableName.replace(tenantFixKey, "");
549
+ return lodash_1.default.get(tenant, variableName);
550
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drapcode-utility",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -33,8 +33,8 @@
33
33
  "@types/express": "^4.17.7",
34
34
  "@types/voca": "^1.4.2",
35
35
  "axios": "^1.1.2",
36
- "drapcode-constant": "^1.2.9",
37
- "drapcode-logger": "^1.0.7",
36
+ "drapcode-constant": "^1.3.1",
37
+ "drapcode-logger": "^1.0.8",
38
38
  "drapcode-redis": "^1.0.4",
39
39
  "express": "^4.17.1",
40
40
  "lodash": "^4.17.21",