@steedos/service-metadata-objects 3.0.13-beta.9 → 3.0.14-beta.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/lib/actionsHandler.js +182 -224
- package/lib/actionsHandler.js.map +1 -1
- package/lib/formula/core.js +3 -4
- package/lib/formula/core.js.map +1 -1
- package/lib/formula/formulaActionHandler.js +265 -402
- package/lib/formula/formulaActionHandler.js.map +1 -1
- package/lib/lookup/LookupActionHandler.js +76 -134
- package/lib/lookup/LookupActionHandler.js.map +1 -1
- package/lib/master-detail/masterDetailActionHandler.js +184 -305
- package/lib/master-detail/masterDetailActionHandler.js.map +1 -1
- package/lib/objects/fields/index.js +2 -5
- package/lib/objects/fields/index.js.map +1 -1
- package/lib/objects/index.js +175 -185
- package/lib/objects/index.js.map +1 -1
- package/lib/objects/translationTemplate.js +3 -4
- package/lib/objects/translationTemplate.js.map +1 -1
- package/lib/objects.service.js +104 -169
- package/lib/objects.service.js.map +1 -1
- package/lib/summary/summaryActionHandler.js +156 -231
- package/lib/summary/summaryActionHandler.js.map +1 -1
- package/package.json +5 -5
- package/tsconfig.json +3 -7
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FormulaActionHandler = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const type_1 = require("./type");
|
|
6
5
|
const core_1 = require("./core");
|
|
7
6
|
const metadata_registrar_1 = require("@steedos/metadata-registrar");
|
|
@@ -15,32 +14,28 @@ function getDynamicCalcMapCacherKey(objectApiName, mainObjectApiName) {
|
|
|
15
14
|
return `$dynamic_calc_map.${objectApiName}.${mainObjectApiName}`;
|
|
16
15
|
}
|
|
17
16
|
class FormulaActionHandler {
|
|
17
|
+
broker = null;
|
|
18
18
|
constructor(broker) {
|
|
19
|
-
this.broker = null;
|
|
20
19
|
this.broker = broker;
|
|
21
20
|
}
|
|
22
|
-
deleteAll(objectConfig) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
yield metadata_registrar_1.Register.fuzzyDelete(this.broker, `${this.cacherKey(objectConfig.name)}.*`);
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
this.broker.logger.error(error);
|
|
21
|
+
async deleteAll(objectConfig) {
|
|
22
|
+
try {
|
|
23
|
+
if (!objectConfig) {
|
|
24
|
+
return;
|
|
33
25
|
}
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
await metadata_registrar_1.Register.fuzzyDelete(this.broker, `${this.cacherKey(objectConfig.name)}.*`);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
this.broker.logger.error(error);
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
36
33
|
}
|
|
37
|
-
getObjectConfig(objectApiName) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
objectApiName: objectApiName,
|
|
41
|
-
});
|
|
42
|
-
return data ? data.metadata : null;
|
|
34
|
+
async getObjectConfig(objectApiName) {
|
|
35
|
+
const data = await this.broker.call("objects.get", {
|
|
36
|
+
objectApiName: objectApiName,
|
|
43
37
|
});
|
|
38
|
+
return data ? data.metadata : null;
|
|
44
39
|
}
|
|
45
40
|
addFieldFormulaQuotesConfig(quote, quotes) {
|
|
46
41
|
if (quote.field_name === "_id") {
|
|
@@ -54,220 +49,173 @@ class FormulaActionHandler {
|
|
|
54
49
|
quotes.push(quote);
|
|
55
50
|
}
|
|
56
51
|
}
|
|
57
|
-
computeFormulaVarAndQuotes(formulaVar, objectConfig, quotes, vars) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
52
|
+
async computeFormulaVarAndQuotes(formulaVar, objectConfig, quotes, vars) {
|
|
53
|
+
let isSimpleVar = objectConfig === null;
|
|
54
|
+
let isAmisGlobalVar = /^global\./.test(formulaVar);
|
|
55
|
+
if (isAmisGlobalVar) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
let isUserVar = new RegExp(`^${type_1.FormulaUserKey.replace("$", "\\$")}\\b`).test(formulaVar);
|
|
59
|
+
let isUserSessionVar = new RegExp(`^${type_1.FormulaUserSessionKey.replace("$", "\\$")}\\b`).test(formulaVar);
|
|
60
|
+
let varItems = formulaVar.split(".");
|
|
61
|
+
let paths = [];
|
|
62
|
+
let formulaVarItem = {
|
|
63
|
+
key: formulaVar,
|
|
64
|
+
paths: paths,
|
|
65
|
+
};
|
|
66
|
+
if (isUserVar || isUserSessionVar) {
|
|
67
|
+
isSimpleVar = false;
|
|
68
|
+
objectConfig = "space_users";
|
|
69
|
+
}
|
|
70
|
+
if (isSimpleVar) {
|
|
71
|
+
formulaVarItem.is_simple_var = true;
|
|
72
|
+
vars.push(formulaVarItem);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (isUserSessionVar) {
|
|
76
|
+
formulaVarItem.is_user_session_var = true;
|
|
77
|
+
vars.push(formulaVarItem);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (isUserVar) {
|
|
81
|
+
formulaVarItem.is_user_var = true;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
if (formulaVar.startsWith("$")) {
|
|
85
|
+
throw new Error(`computeFormulaVarAndQuotes:The formula var '${formulaVar}' is starts with '$' but not a user session var that starts with $user.`);
|
|
64
86
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
let varItems = formulaVar.split(".");
|
|
68
|
-
let paths = [];
|
|
69
|
-
let formulaVarItem = {
|
|
70
|
-
key: formulaVar,
|
|
71
|
-
paths: paths,
|
|
72
|
-
};
|
|
73
|
-
if (isUserVar || isUserSessionVar) {
|
|
74
|
-
isSimpleVar = false;
|
|
75
|
-
objectConfig = "space_users";
|
|
87
|
+
if (!objectConfig) {
|
|
88
|
+
throw new Error(`computeFormulaVarAndQuotes:The 'objectConfig' is required for the formula var '${formulaVar}'`);
|
|
76
89
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
90
|
+
}
|
|
91
|
+
let tempObjectConfig = objectConfig;
|
|
92
|
+
let i = -1;
|
|
93
|
+
for await (let varItem of varItems) {
|
|
94
|
+
i++;
|
|
95
|
+
let tempFieldConfig;
|
|
96
|
+
const isUserKey = varItem === type_1.FormulaUserKey;
|
|
97
|
+
if (varItem === "_id") {
|
|
98
|
+
tempFieldConfig = {
|
|
99
|
+
name: varItem,
|
|
100
|
+
type: "text",
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
else if (isUserKey) {
|
|
104
|
+
tempFieldConfig = {
|
|
105
|
+
name: varItem,
|
|
106
|
+
type: "lookup",
|
|
107
|
+
reference_to: "space_users",
|
|
108
|
+
};
|
|
81
109
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
vars.push(formulaVarItem);
|
|
85
|
-
return;
|
|
110
|
+
else {
|
|
111
|
+
tempFieldConfig = tempObjectConfig.fields[varItem];
|
|
86
112
|
}
|
|
87
|
-
if (
|
|
88
|
-
|
|
113
|
+
if (!tempFieldConfig) {
|
|
114
|
+
return;
|
|
89
115
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
116
|
+
let isFormulaType = tempFieldConfig.type === "formula";
|
|
117
|
+
if (!isUserKey) {
|
|
118
|
+
let tempFieldFormulaVarPath = {
|
|
119
|
+
field_name: varItem,
|
|
120
|
+
reference_from: tempObjectConfig.name,
|
|
121
|
+
};
|
|
122
|
+
if (isFormulaType) {
|
|
123
|
+
tempFieldFormulaVarPath.is_formula = true;
|
|
93
124
|
}
|
|
94
|
-
|
|
95
|
-
|
|
125
|
+
paths.push(tempFieldFormulaVarPath);
|
|
126
|
+
}
|
|
127
|
+
if (!isUserVar) {
|
|
128
|
+
let tempFieldFormulaQuote = {
|
|
129
|
+
object_name: tempObjectConfig.name,
|
|
130
|
+
field_name: tempFieldConfig.name,
|
|
131
|
+
};
|
|
132
|
+
if (i === 0 && i === varItems.length - 1) {
|
|
133
|
+
tempFieldFormulaQuote.is_own = true;
|
|
96
134
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
let i = -1;
|
|
100
|
-
try {
|
|
101
|
-
for (var _d = true, varItems_1 = tslib_1.__asyncValues(varItems), varItems_1_1; varItems_1_1 = yield varItems_1.next(), _a = varItems_1_1.done, !_a; _d = true) {
|
|
102
|
-
_c = varItems_1_1.value;
|
|
103
|
-
_d = false;
|
|
104
|
-
let varItem = _c;
|
|
105
|
-
i++;
|
|
106
|
-
let tempFieldConfig;
|
|
107
|
-
const isUserKey = varItem === type_1.FormulaUserKey;
|
|
108
|
-
if (varItem === "_id") {
|
|
109
|
-
tempFieldConfig = {
|
|
110
|
-
name: varItem,
|
|
111
|
-
type: "text",
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
else if (isUserKey) {
|
|
115
|
-
tempFieldConfig = {
|
|
116
|
-
name: varItem,
|
|
117
|
-
type: "lookup",
|
|
118
|
-
reference_to: "space_users",
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
tempFieldConfig = tempObjectConfig.fields[varItem];
|
|
123
|
-
}
|
|
124
|
-
if (!tempFieldConfig) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
let isFormulaType = tempFieldConfig.type === "formula";
|
|
128
|
-
if (!isUserKey) {
|
|
129
|
-
let tempFieldFormulaVarPath = {
|
|
130
|
-
field_name: varItem,
|
|
131
|
-
reference_from: tempObjectConfig.name,
|
|
132
|
-
};
|
|
133
|
-
if (isFormulaType) {
|
|
134
|
-
tempFieldFormulaVarPath.is_formula = true;
|
|
135
|
-
}
|
|
136
|
-
paths.push(tempFieldFormulaVarPath);
|
|
137
|
-
}
|
|
138
|
-
if (!isUserVar) {
|
|
139
|
-
let tempFieldFormulaQuote = {
|
|
140
|
-
object_name: tempObjectConfig.name,
|
|
141
|
-
field_name: tempFieldConfig.name,
|
|
142
|
-
};
|
|
143
|
-
if (i === 0 && i === varItems.length - 1) {
|
|
144
|
-
tempFieldFormulaQuote.is_own = true;
|
|
145
|
-
}
|
|
146
|
-
if (isFormulaType) {
|
|
147
|
-
tempFieldFormulaQuote.is_formula = true;
|
|
148
|
-
}
|
|
149
|
-
this.addFieldFormulaQuotesConfig(tempFieldFormulaQuote, quotes);
|
|
150
|
-
}
|
|
151
|
-
if (tempFieldConfig.type === "lookup" ||
|
|
152
|
-
tempFieldConfig.type === "master_detail") {
|
|
153
|
-
if (tempFieldConfig.reference_to_field && paths.length) {
|
|
154
|
-
paths[paths.length - 1].reference_to_field =
|
|
155
|
-
tempFieldConfig.reference_to_field;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
if (i < varItems.length - 1) {
|
|
160
|
-
formulaVarItem.key = formulaVarItem.key.replace(new RegExp(`((.+)?${varItem})..+`), "$1");
|
|
161
|
-
}
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
if (typeof tempFieldConfig.reference_to !== "string") {
|
|
165
|
-
throw new Error(`Field ${tempFieldConfig.name} in formula ${formulaVar} does not define the "Reference Object" property or its "Reference Object" property is a function.`);
|
|
166
|
-
}
|
|
167
|
-
tempObjectConfig = yield this.getObjectConfig(tempFieldConfig.reference_to);
|
|
168
|
-
if (!tempObjectConfig) {
|
|
169
|
-
if (isCodeObject(tempFieldConfig.reference_to)) {
|
|
170
|
-
throw new Error(`computeFormulaVarAndQuotes:Can't find the object reference_to '${tempFieldConfig.reference_to}' by the field '${tempFieldConfig.name}' for the formula var '${formulaVar}'`);
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
yield metadata_registrar_1.Register.add(this.broker, {
|
|
174
|
-
key: this.cacherKey(getDynamicCalcMapCacherKey(tempFieldConfig.reference_to, objectConfig.name)),
|
|
175
|
-
data: { objectApiName: objectConfig.name },
|
|
176
|
-
}, {});
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
135
|
+
if (isFormulaType) {
|
|
136
|
+
tempFieldFormulaQuote.is_formula = true;
|
|
180
137
|
}
|
|
138
|
+
this.addFieldFormulaQuotesConfig(tempFieldFormulaQuote, quotes);
|
|
181
139
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
140
|
+
if (tempFieldConfig.type === "lookup" ||
|
|
141
|
+
tempFieldConfig.type === "master_detail") {
|
|
142
|
+
if (tempFieldConfig.reference_to_field && paths.length) {
|
|
143
|
+
paths[paths.length - 1].reference_to_field =
|
|
144
|
+
tempFieldConfig.reference_to_field;
|
|
186
145
|
}
|
|
187
|
-
finally { if (e_1) throw e_1.error; }
|
|
188
146
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
var _a, e_2, _b, _c;
|
|
195
|
-
let quotes = [];
|
|
196
|
-
let vars = [];
|
|
197
|
-
let formulaVars = [];
|
|
198
|
-
try {
|
|
199
|
-
formulaVars = (0, core_1.pickFormulaVars)(formula);
|
|
147
|
+
else {
|
|
148
|
+
if (i < varItems.length - 1) {
|
|
149
|
+
formulaVarItem.key = formulaVarItem.key.replace(new RegExp(`((.+)?${varItem})..+`), "$1");
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
200
152
|
}
|
|
201
|
-
|
|
202
|
-
throw new Error(`
|
|
153
|
+
if (typeof tempFieldConfig.reference_to !== "string") {
|
|
154
|
+
throw new Error(`Field ${tempFieldConfig.name} in formula ${formulaVar} does not define the "Reference Object" property or its "Reference Object" property is a function.`);
|
|
203
155
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const formulaVar = _c;
|
|
209
|
-
yield this.computeFormulaVarAndQuotes(formulaVar, objectConfig, quotes, vars);
|
|
156
|
+
tempObjectConfig = await this.getObjectConfig(tempFieldConfig.reference_to);
|
|
157
|
+
if (!tempObjectConfig) {
|
|
158
|
+
if (isCodeObject(tempFieldConfig.reference_to)) {
|
|
159
|
+
throw new Error(`computeFormulaVarAndQuotes:Can't find the object reference_to '${tempFieldConfig.reference_to}' by the field '${tempFieldConfig.name}' for the formula var '${formulaVar}'`);
|
|
210
160
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
161
|
+
else {
|
|
162
|
+
await metadata_registrar_1.Register.add(this.broker, {
|
|
163
|
+
key: this.cacherKey(getDynamicCalcMapCacherKey(tempFieldConfig.reference_to, objectConfig.name)),
|
|
164
|
+
data: { objectApiName: objectConfig.name },
|
|
165
|
+
}, {});
|
|
166
|
+
return;
|
|
216
167
|
}
|
|
217
|
-
finally { if (e_2) throw e_2.error; }
|
|
218
168
|
}
|
|
219
|
-
|
|
220
|
-
|
|
169
|
+
}
|
|
170
|
+
vars.push(formulaVarItem);
|
|
171
|
+
}
|
|
172
|
+
async computeFormulaVarsAndQuotes(formula, objectConfig) {
|
|
173
|
+
let quotes = [];
|
|
174
|
+
let vars = [];
|
|
175
|
+
let formulaVars = [];
|
|
176
|
+
try {
|
|
177
|
+
formulaVars = (0, core_1.pickFormulaVars)(formula);
|
|
178
|
+
}
|
|
179
|
+
catch (ex) {
|
|
180
|
+
throw new Error(`pickFormulaVars:Catch an error "${ex}" while pick vars from the formula "${formula}" for "${JSON.stringify(objectConfig)}"`);
|
|
181
|
+
}
|
|
182
|
+
for await (const formulaVar of formulaVars) {
|
|
183
|
+
await this.computeFormulaVarAndQuotes(formulaVar, objectConfig, quotes, vars);
|
|
184
|
+
}
|
|
185
|
+
return { quotes, vars };
|
|
221
186
|
}
|
|
222
187
|
cacherKey(APIName) {
|
|
223
188
|
return `$steedos.#formula.${APIName}`;
|
|
224
189
|
}
|
|
225
|
-
getObjectFieldFormulaConfig(fieldConfig, objectConfig) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
return formulaConfig;
|
|
240
|
-
});
|
|
190
|
+
async getObjectFieldFormulaConfig(fieldConfig, objectConfig) {
|
|
191
|
+
const formula = fieldConfig.formula;
|
|
192
|
+
let result = await this.computeFormulaVarsAndQuotes(formula, objectConfig);
|
|
193
|
+
let formulaConfig = {
|
|
194
|
+
_id: `${objectConfig.name}.${fieldConfig.name}`,
|
|
195
|
+
object_name: objectConfig.name,
|
|
196
|
+
field_name: fieldConfig.name,
|
|
197
|
+
formula: formula,
|
|
198
|
+
data_type: fieldConfig.data_type,
|
|
199
|
+
formula_blank_value: (fieldConfig.formula_blank_value),
|
|
200
|
+
quotes: result.quotes,
|
|
201
|
+
vars: result.vars,
|
|
202
|
+
};
|
|
203
|
+
return formulaConfig;
|
|
241
204
|
}
|
|
242
|
-
getObjectFieldsFormulaConfig(config, datasource) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
try {
|
|
247
|
-
for (var _d = true, _e = tslib_1.__asyncValues(_.values(config.fields)), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
|
|
248
|
-
_c = _f.value;
|
|
249
|
-
_d = false;
|
|
250
|
-
const field = _c;
|
|
251
|
-
if (field.type === "formula") {
|
|
252
|
-
try {
|
|
253
|
-
const fieldFormulaConfig = yield this.getObjectFieldFormulaConfig(clone(field), config);
|
|
254
|
-
objectFieldsFormulaConfig.push(fieldFormulaConfig);
|
|
255
|
-
}
|
|
256
|
-
catch (error) {
|
|
257
|
-
console.error(error);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
263
|
-
finally {
|
|
205
|
+
async getObjectFieldsFormulaConfig(config, datasource) {
|
|
206
|
+
const objectFieldsFormulaConfig = [];
|
|
207
|
+
for await (const field of _.values(config.fields)) {
|
|
208
|
+
if (field.type === "formula") {
|
|
264
209
|
try {
|
|
265
|
-
|
|
210
|
+
const fieldFormulaConfig = await this.getObjectFieldFormulaConfig(clone(field), config);
|
|
211
|
+
objectFieldsFormulaConfig.push(fieldFormulaConfig);
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
console.error(error);
|
|
266
215
|
}
|
|
267
|
-
finally { if (e_3) throw e_3.error; }
|
|
268
216
|
}
|
|
269
|
-
|
|
270
|
-
|
|
217
|
+
}
|
|
218
|
+
return objectFieldsFormulaConfig;
|
|
271
219
|
}
|
|
272
220
|
checkRefMapData(maps, data) {
|
|
273
221
|
let refs = [];
|
|
@@ -286,212 +234,127 @@ class FormulaActionHandler {
|
|
|
286
234
|
throw new Error(`Infinite Loop: ${JSON.stringify(data)}`);
|
|
287
235
|
}
|
|
288
236
|
}
|
|
289
|
-
getFormulaReferenceMaps(broker) {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
try {
|
|
296
|
-
for (var _d = true, records_1 = tslib_1.__asyncValues(records), records_1_1; records_1_1 = yield records_1.next(), _a = records_1_1.done, !_a; _d = true) {
|
|
297
|
-
_c = records_1_1.value;
|
|
298
|
-
_d = false;
|
|
299
|
-
const item = _c;
|
|
300
|
-
const metadata = item === null || item === void 0 ? void 0 : item.metadata;
|
|
301
|
-
if (metadata) {
|
|
302
|
-
maps.push(item);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
307
|
-
finally {
|
|
308
|
-
try {
|
|
309
|
-
if (!_d && !_a && (_b = records_1.return)) yield _b.call(records_1);
|
|
310
|
-
}
|
|
311
|
-
finally { if (e_4) throw e_4.error; }
|
|
312
|
-
}
|
|
313
|
-
return { metadata: maps };
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
addFormulaReferenceMaps(broker, key, value) {
|
|
317
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
318
|
-
let { metadata } = (yield this.getFormulaReferenceMaps(broker)) || [];
|
|
319
|
-
let maps = [];
|
|
237
|
+
async getFormulaReferenceMaps(broker) {
|
|
238
|
+
const maps = [];
|
|
239
|
+
let records = (await metadata_registrar_1.Register.filter(this.broker, this.cacherKey(`${refMapName}.*`))) ||
|
|
240
|
+
{};
|
|
241
|
+
for await (const item of records) {
|
|
242
|
+
const metadata = item?.metadata;
|
|
320
243
|
if (metadata) {
|
|
321
|
-
maps
|
|
244
|
+
maps.push(item);
|
|
322
245
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
value: value,
|
|
326
|
-
};
|
|
327
|
-
this.checkRefMapData(maps, data);
|
|
328
|
-
yield metadata_registrar_1.Register.add(this.broker, { key: this.cacherKey(`${refMapName}.${key}.${value}`), data: data }, {});
|
|
329
|
-
});
|
|
246
|
+
}
|
|
247
|
+
return { metadata: maps };
|
|
330
248
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
_c = objectFieldsFormulaConfig_1_1.value;
|
|
344
|
-
_g = false;
|
|
345
|
-
const fieldFormula = _c;
|
|
346
|
-
try {
|
|
347
|
-
for (var _h = true, _j = (e_6 = void 0, tslib_1.__asyncValues(fieldFormula.quotes)), _k; _k = yield _j.next(), _d = _k.done, !_d; _h = true) {
|
|
348
|
-
_f = _k.value;
|
|
349
|
-
_h = false;
|
|
350
|
-
const quote = _f;
|
|
351
|
-
yield this.addFormulaReferenceMaps(this.broker, `${fieldFormula._id}`, `${quote.object_name}.${quote.field_name}`);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
355
|
-
finally {
|
|
356
|
-
try {
|
|
357
|
-
if (!_h && !_d && (_e = _j.return)) yield _e.call(_j);
|
|
358
|
-
}
|
|
359
|
-
finally { if (e_6) throw e_6.error; }
|
|
360
|
-
}
|
|
361
|
-
yield metadata_registrar_1.Register.add(this.broker, { key: this.cacherKey(fieldFormula._id), data: fieldFormula }, {});
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
365
|
-
finally {
|
|
366
|
-
try {
|
|
367
|
-
if (!_g && !_a && (_b = objectFieldsFormulaConfig_1.return)) yield _b.call(objectFieldsFormulaConfig_1);
|
|
368
|
-
}
|
|
369
|
-
finally { if (e_5) throw e_5.error; }
|
|
370
|
-
}
|
|
371
|
-
for (const deletedFieldName of diff) {
|
|
372
|
-
if (deletedFieldName) {
|
|
373
|
-
yield metadata_registrar_1.Register.delete(this.broker, this.cacherKey(`${config.name}.${deletedFieldName}`));
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
return true;
|
|
377
|
-
});
|
|
249
|
+
async addFormulaReferenceMaps(broker, key, value) {
|
|
250
|
+
let { metadata } = (await this.getFormulaReferenceMaps(broker)) || [];
|
|
251
|
+
let maps = [];
|
|
252
|
+
if (metadata) {
|
|
253
|
+
maps = metadata;
|
|
254
|
+
}
|
|
255
|
+
let data = {
|
|
256
|
+
key: key,
|
|
257
|
+
value: value,
|
|
258
|
+
};
|
|
259
|
+
this.checkRefMapData(maps, data);
|
|
260
|
+
await metadata_registrar_1.Register.add(this.broker, { key: this.cacherKey(`${refMapName}.${key}.${value}`), data: data }, {});
|
|
378
261
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
262
|
+
async addFormulaMetadata(config, datasource) {
|
|
263
|
+
const objectFieldsFormulaConfig = await this.getObjectFieldsFormulaConfig(config, datasource);
|
|
264
|
+
const objectFormulas = await this.filter({
|
|
265
|
+
params: { objectApiName: config.name },
|
|
382
266
|
});
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
const recalcObjectApiName = (_d = item === null || item === void 0 ? void 0 : item.metadata) === null || _d === void 0 ? void 0 : _d.objectApiName;
|
|
396
|
-
if (recalcObjectApiName) {
|
|
397
|
-
const recalcObjectConfig = yield this.getObjectConfig(recalcObjectApiName);
|
|
398
|
-
if (recalcObjectConfig) {
|
|
399
|
-
recalcObjects[recalcObjectApiName] = recalcObjectConfig;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
267
|
+
const formulaFieldsName = _.map(objectFormulas, "field_name");
|
|
268
|
+
const objectFields = _.map(config.fields, "name");
|
|
269
|
+
const diff = _.difference(formulaFieldsName, objectFields);
|
|
270
|
+
for await (const fieldFormula of objectFieldsFormulaConfig) {
|
|
271
|
+
for await (const quote of fieldFormula.quotes) {
|
|
272
|
+
await this.addFormulaReferenceMaps(this.broker, `${fieldFormula._id}`, `${quote.object_name}.${quote.field_name}`);
|
|
273
|
+
}
|
|
274
|
+
await metadata_registrar_1.Register.add(this.broker, { key: this.cacherKey(fieldFormula._id), data: fieldFormula }, {});
|
|
275
|
+
}
|
|
276
|
+
for (const deletedFieldName of diff) {
|
|
277
|
+
if (deletedFieldName) {
|
|
278
|
+
await metadata_registrar_1.Register.delete(this.broker, this.cacherKey(`${config.name}.${deletedFieldName}`));
|
|
403
279
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
280
|
+
}
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
async getObjectDynamicCalcFormulaMap(objectApiName) {
|
|
284
|
+
return await metadata_registrar_1.Register.filter(this.broker, this.cacherKey(getDynamicCalcMapCacherKey(objectApiName, "*")));
|
|
285
|
+
}
|
|
286
|
+
async recalcObjectsFormulaMap(objectConfig) {
|
|
287
|
+
const recalcObjects = {};
|
|
288
|
+
const dynamicCalcFormulaMap = await this.getObjectDynamicCalcFormulaMap(objectConfig.name);
|
|
289
|
+
for await (const item of dynamicCalcFormulaMap) {
|
|
290
|
+
const recalcObjectApiName = item?.metadata?.objectApiName;
|
|
291
|
+
if (recalcObjectApiName) {
|
|
292
|
+
const recalcObjectConfig = await this.getObjectConfig(recalcObjectApiName);
|
|
293
|
+
if (recalcObjectConfig) {
|
|
294
|
+
recalcObjects[recalcObjectApiName] = recalcObjectConfig;
|
|
408
295
|
}
|
|
409
|
-
finally { if (e_7) throw e_7.error; }
|
|
410
296
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
297
|
+
}
|
|
298
|
+
for (const objectName in recalcObjects) {
|
|
299
|
+
if (Object.prototype.hasOwnProperty.call(recalcObjects, objectName)) {
|
|
300
|
+
const recalcObjectConfig = recalcObjects[objectName];
|
|
301
|
+
await this.addFormulaMetadata(recalcObjectConfig, recalcObjectConfig.datasource);
|
|
302
|
+
await metadata_registrar_1.Register.delete(this.broker, this.cacherKey(getDynamicCalcMapCacherKey(objectConfig.name, objectName)));
|
|
417
303
|
}
|
|
418
|
-
}
|
|
304
|
+
}
|
|
419
305
|
}
|
|
420
|
-
add(objectConfig) {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
return false;
|
|
430
|
-
});
|
|
306
|
+
async add(objectConfig) {
|
|
307
|
+
try {
|
|
308
|
+
await this.addFormulaMetadata(objectConfig, objectConfig.datasource);
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
catch (error) {
|
|
312
|
+
this.broker.logger.error(error);
|
|
313
|
+
}
|
|
314
|
+
return false;
|
|
431
315
|
}
|
|
432
|
-
filter(ctx) {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
configs.push(item === null || item === void 0 ? void 0 : item.metadata);
|
|
446
|
-
});
|
|
447
|
-
return configs;
|
|
316
|
+
async filter(ctx) {
|
|
317
|
+
let { objectApiName, fieldApiName } = ctx.params;
|
|
318
|
+
if (!objectApiName) {
|
|
319
|
+
objectApiName = "*";
|
|
320
|
+
}
|
|
321
|
+
if (!fieldApiName) {
|
|
322
|
+
fieldApiName = "*";
|
|
323
|
+
}
|
|
324
|
+
const key = this.cacherKey(`${objectApiName}.${fieldApiName}`);
|
|
325
|
+
const configs = [];
|
|
326
|
+
const res = await metadata_registrar_1.Register.filter(this.broker, key);
|
|
327
|
+
_.forEach(res, (item) => {
|
|
328
|
+
configs.push(item?.metadata);
|
|
448
329
|
});
|
|
330
|
+
return configs;
|
|
449
331
|
}
|
|
450
|
-
get(ctx) {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
return res === null || res === void 0 ? void 0 : res.metadata;
|
|
456
|
-
});
|
|
332
|
+
async get(ctx) {
|
|
333
|
+
let { fieldApiFullName } = ctx.params;
|
|
334
|
+
const key = this.cacherKey(fieldApiFullName);
|
|
335
|
+
const res = await metadata_registrar_1.Register.get(this.broker, key);
|
|
336
|
+
return res?.metadata;
|
|
457
337
|
}
|
|
458
|
-
verifyObjectFieldFormulaConfig(ctx) {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
key: fieldFormula._id,
|
|
475
|
-
value: `${quote.object_name}.${quote.field_name}`,
|
|
476
|
-
};
|
|
477
|
-
this.checkRefMapData(maps, data);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
481
|
-
finally {
|
|
482
|
-
try {
|
|
483
|
-
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
484
|
-
}
|
|
485
|
-
finally { if (e_8) throw e_8.error; }
|
|
486
|
-
}
|
|
487
|
-
return yield this.getObjectFieldFormulaConfig(fieldConfig, objectConfig);
|
|
488
|
-
});
|
|
338
|
+
async verifyObjectFieldFormulaConfig(ctx) {
|
|
339
|
+
let { fieldConfig, objectConfig } = ctx.params;
|
|
340
|
+
const fieldFormula = await this.getObjectFieldFormulaConfig(fieldConfig, objectConfig);
|
|
341
|
+
let { metadata } = (await this.getFormulaReferenceMaps(ctx.broker)) || [];
|
|
342
|
+
let maps = [];
|
|
343
|
+
if (metadata) {
|
|
344
|
+
maps = metadata;
|
|
345
|
+
}
|
|
346
|
+
for await (const quote of fieldFormula.quotes) {
|
|
347
|
+
let data = {
|
|
348
|
+
key: fieldFormula._id,
|
|
349
|
+
value: `${quote.object_name}.${quote.field_name}`,
|
|
350
|
+
};
|
|
351
|
+
this.checkRefMapData(maps, data);
|
|
352
|
+
}
|
|
353
|
+
return await this.getObjectFieldFormulaConfig(fieldConfig, objectConfig);
|
|
489
354
|
}
|
|
490
|
-
getFormulaVarsAndQuotes(ctx) {
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
return yield this.computeFormulaVarsAndQuotes(formula, objectConfig);
|
|
494
|
-
});
|
|
355
|
+
async getFormulaVarsAndQuotes(ctx) {
|
|
356
|
+
let { formula, objectConfig } = ctx.params;
|
|
357
|
+
return await this.computeFormulaVarsAndQuotes(formula, objectConfig);
|
|
495
358
|
}
|
|
496
359
|
}
|
|
497
360
|
exports.FormulaActionHandler = FormulaActionHandler;
|