@steedos/objectql 3.0.13-beta.3 → 3.0.13-beta.32
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/actions/field_updates.js +84 -153
- package/lib/actions/field_updates.js.map +1 -1
- package/lib/actions/index.js +1 -1
- package/lib/actions/workflow_notifications.js +50 -111
- package/lib/actions/workflow_notifications.js.map +1 -1
- package/lib/actions/workflow_outbound_messages.js +43 -94
- package/lib/actions/workflow_outbound_messages.js.map +1 -1
- package/lib/actions/workflow_rule.js +80 -177
- package/lib/actions/workflow_rule.js.map +1 -1
- package/lib/broker.js +19 -49
- package/lib/broker.js.map +1 -1
- package/lib/driver/field-encrytion/index.js +1 -1
- package/lib/driver/field-encrytion/mongosharedconst.js +17 -17
- package/lib/driver/field-encrytion/mongosharedconst.js.map +1 -1
- package/lib/driver/format.js +3 -3
- package/lib/driver/format.js.map +1 -1
- package/lib/driver/index.js +1 -1
- package/lib/driver/metadata.js +283 -387
- package/lib/driver/metadata.js.map +1 -1
- package/lib/driver/metadataOld.js +104 -105
- package/lib/driver/metadataOld.js.map +1 -1
- package/lib/driver/meteorMongo.js +5 -8
- package/lib/driver/meteorMongo.js.map +1 -1
- package/lib/driver/mongo.js +321 -506
- package/lib/driver/mongo.js.map +1 -1
- package/lib/driver/mysql.js +16 -20
- package/lib/driver/mysql.js.map +1 -1
- package/lib/driver/oracle.js +25 -38
- package/lib/driver/oracle.js.map +1 -1
- package/lib/driver/postgres.js +16 -20
- package/lib/driver/postgres.js.map +1 -1
- package/lib/driver/sqlite3.js +15 -19
- package/lib/driver/sqlite3.js.map +1 -1
- package/lib/driver/sqlserver.js +20 -33
- package/lib/driver/sqlserver.js.map +1 -1
- package/lib/errors/index.js +10 -11
- package/lib/errors/index.js.map +1 -1
- package/lib/formula/core.js +307 -594
- package/lib/formula/core.js.map +1 -1
- package/lib/formula/field_formula.js +80 -126
- package/lib/formula/field_formula.js.map +1 -1
- package/lib/formula/index.js +56 -97
- package/lib/formula/index.js.map +1 -1
- package/lib/formula/params.js +11 -11
- package/lib/formula/params.js.map +1 -1
- package/lib/formula/recompute.js +41 -166
- package/lib/formula/recompute.js.map +1 -1
- package/lib/formula/simple_params.js +12 -12
- package/lib/formula/simple_params.js.map +1 -1
- package/lib/formula/util.js +43 -67
- package/lib/formula/util.js.map +1 -1
- package/lib/functions/function.js +62 -87
- package/lib/functions/function.js.map +1 -1
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/lib/services/datasourceServiceFactory.js +77 -111
- package/lib/services/datasourceServiceFactory.js.map +1 -1
- package/lib/services/index.js +3 -3
- package/lib/services/index.js.map +1 -1
- package/lib/summary/core.js +162 -355
- package/lib/summary/core.js.map +1 -1
- package/lib/summary/field_summary.js +44 -71
- package/lib/summary/field_summary.js.map +1 -1
- package/lib/summary/index.js +65 -80
- package/lib/summary/index.js.map +1 -1
- package/lib/summary/recompute.js +19 -47
- package/lib/summary/recompute.js.map +1 -1
- package/lib/triggers/trigger.js +101 -142
- package/lib/triggers/trigger.js.map +1 -1
- package/lib/ts-types/index.js +1 -1
- package/lib/typeorm/driver.js +250 -450
- package/lib/typeorm/driver.js.map +1 -1
- package/lib/typeorm/index.js +1 -1
- package/lib/typeorm/util.js +28 -28
- package/lib/typeorm/util.js.map +1 -1
- package/lib/types/action.js +24 -33
- package/lib/types/action.js.map +1 -1
- package/lib/types/app.js +210 -355
- package/lib/types/app.js.map +1 -1
- package/lib/types/connection.js +42 -78
- package/lib/types/connection.js.map +1 -1
- package/lib/types/dashboard.js +56 -77
- package/lib/types/dashboard.js.map +1 -1
- package/lib/types/datasource.js +359 -705
- package/lib/types/datasource.js.map +1 -1
- package/lib/types/defaultValue.js +53 -65
- package/lib/types/defaultValue.js.map +1 -1
- package/lib/types/field.js +165 -137
- package/lib/types/field.js.map +1 -1
- package/lib/types/field_permission.js +35 -66
- package/lib/types/field_permission.js.map +1 -1
- package/lib/types/index.js +1 -1
- package/lib/types/list_view.js +36 -43
- package/lib/types/list_view.js.map +1 -1
- package/lib/types/metadata.js +6 -6
- package/lib/types/metadata.js.map +1 -1
- package/lib/types/method_base.js +95 -128
- package/lib/types/method_base.js.map +1 -1
- package/lib/types/object.js +2005 -3015
- package/lib/types/object.js.map +1 -1
- package/lib/types/object_events.js +24 -37
- package/lib/types/object_events.js.map +1 -1
- package/lib/types/object_layouts.js +15 -38
- package/lib/types/object_layouts.js.map +1 -1
- package/lib/types/object_permission.js +99 -85
- package/lib/types/object_permission.js.map +1 -1
- package/lib/types/report.js +70 -98
- package/lib/types/report.js.map +1 -1
- package/lib/types/restrictionRule.js +47 -96
- package/lib/types/restrictionRule.js.map +1 -1
- package/lib/types/schema.js +115 -177
- package/lib/types/schema.js.map +1 -1
- package/lib/types/shareRule.js +53 -102
- package/lib/types/shareRule.js.map +1 -1
- package/lib/types/trigger.js +43 -56
- package/lib/types/trigger.js.map +1 -1
- package/lib/types/validation_rules.js +18 -56
- package/lib/types/validation_rules.js.map +1 -1
- package/lib/util/convert.js +24 -24
- package/lib/util/convert.js.map +1 -1
- package/lib/util/field.js +16 -28
- package/lib/util/field.js.map +1 -1
- package/lib/util/function_expression.js +7 -8
- package/lib/util/function_expression.js.map +1 -1
- package/lib/util/index.js +79 -97
- package/lib/util/index.js.map +1 -1
- package/lib/util/locale.js +4 -4
- package/lib/util/locale.js.map +1 -1
- package/lib/util/permission_shares.js +7 -7
- package/lib/util/permission_shares.js.map +1 -1
- package/lib/util/suffix.js +19 -19
- package/lib/util/suffix.js.map +1 -1
- package/lib/util/transform.js +1 -1
- package/lib/validators/index.js +10 -10
- package/lib/validators/index.js.map +1 -1
- package/package.json +12 -12
package/lib/formula/core.js
CHANGED
|
@@ -1,244 +1,177 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isFormulaFieldQuotingObjectAndFields = exports.updateQuotedByDocsForFormulaType = exports.updateDocsFieldFormulaValue = exports.updateQuotedByObjectFieldFormulaValue = exports.getCurrentObjectFieldFormulasDoc = exports.runQuotedByObjectFieldFormulas = exports.runAmisFormula = exports.isAmisFormula = exports.getAmisGlobalVariables = exports.runFormula = exports.evalFieldFormula = exports.computeFieldFormulaValue = exports.computeFormulaParams = exports.pickFormulaVarFields = exports.pickFieldFormulaVarFields = exports.pickFormulaVars = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var amis_formula_1 = require("amis-formula");
|
|
4
|
+
const index_1 = require("../index");
|
|
5
|
+
const type_1 = require("./type");
|
|
6
|
+
const field_formula_1 = require("./field_formula");
|
|
7
|
+
const summary_1 = require("../summary");
|
|
8
|
+
const util_1 = require("./util");
|
|
9
|
+
const _ = require("lodash");
|
|
10
|
+
const formula_1 = require("@steedos/formula");
|
|
11
|
+
const params_1 = require("./params");
|
|
12
|
+
const simple_params_1 = require("./simple_params");
|
|
13
|
+
const amis_formula_1 = require("amis-formula");
|
|
15
14
|
function convertToNestedObject(flatObject) {
|
|
16
|
-
|
|
17
|
-
for (
|
|
15
|
+
const nestedObject = {};
|
|
16
|
+
for (const flatKey in flatObject) {
|
|
18
17
|
_.set(nestedObject, flatKey, flatObject[flatKey]);
|
|
19
18
|
}
|
|
20
19
|
return nestedObject;
|
|
21
20
|
}
|
|
22
|
-
|
|
21
|
+
const pickFormulaVars = (formula) => {
|
|
23
22
|
return (0, formula_1.extract)(formula);
|
|
24
23
|
};
|
|
25
24
|
exports.pickFormulaVars = pickFormulaVars;
|
|
26
|
-
|
|
25
|
+
const pickFieldFormulaVarFields = (fieldFormulaConfigs) => {
|
|
27
26
|
if (!_.isArray(fieldFormulaConfigs)) {
|
|
28
27
|
fieldFormulaConfigs = [fieldFormulaConfigs];
|
|
29
28
|
}
|
|
30
|
-
|
|
31
|
-
fieldFormulaConfigs.forEach(
|
|
32
|
-
|
|
29
|
+
let result = [];
|
|
30
|
+
fieldFormulaConfigs.forEach((fieldFormulaConfig) => {
|
|
31
|
+
let { vars } = fieldFormulaConfig;
|
|
33
32
|
result = _.union(result, (0, exports.pickFormulaVarFields)(vars));
|
|
34
33
|
});
|
|
35
34
|
return _.uniq(result);
|
|
36
35
|
};
|
|
37
36
|
exports.pickFieldFormulaVarFields = pickFieldFormulaVarFields;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
vars.forEach(
|
|
37
|
+
const pickFormulaVarFields = (vars) => {
|
|
38
|
+
let result = [];
|
|
39
|
+
vars.forEach((varItem) => {
|
|
41
40
|
if (varItem.paths.length) {
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
let firstPath = varItem.paths[0];
|
|
42
|
+
let firstKey = firstPath.field_name;
|
|
44
43
|
result.push(firstKey);
|
|
45
44
|
}
|
|
46
45
|
});
|
|
47
46
|
return _.uniq(result);
|
|
48
47
|
};
|
|
49
48
|
exports.pickFormulaVarFields = pickFormulaVarFields;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (!
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return [4, (0, index_1.getSteedosSchema)()
|
|
111
|
-
.getObject("space_users")
|
|
112
|
-
.find({
|
|
113
|
-
filters: [
|
|
114
|
-
["user", "=", currentUserId],
|
|
115
|
-
["space", "=", spaceId],
|
|
116
|
-
],
|
|
117
|
-
fields: [next.field_name],
|
|
118
|
-
})];
|
|
119
|
-
case 2:
|
|
120
|
-
sus = _a.sent();
|
|
121
|
-
reslut = sus && sus.length && sus[0];
|
|
122
|
-
if (reslut) {
|
|
123
|
-
reslut = reslut[next.field_name];
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
reslut = null;
|
|
127
|
-
}
|
|
128
|
-
return [3, 4];
|
|
129
|
-
case 3:
|
|
130
|
-
reslut = doc[next.field_name];
|
|
131
|
-
_a.label = 4;
|
|
132
|
-
case 4: return [3, 10];
|
|
133
|
-
case 5:
|
|
134
|
-
if (!reslut) {
|
|
135
|
-
return [3, 11];
|
|
136
|
-
}
|
|
137
|
-
found = void 0;
|
|
138
|
-
if (!(lastReferenceToField && lastReferenceToField !== "_id")) return [3, 7];
|
|
139
|
-
return [4, (0, index_1.getSteedosSchema)()
|
|
140
|
-
.getObject(next.reference_from)
|
|
141
|
-
.findOne({ filters: [lastReferenceToField, "=", reslut] }, { fields: [next.field_name] })];
|
|
142
|
-
case 6:
|
|
143
|
-
found = _a.sent();
|
|
144
|
-
return [3, 9];
|
|
145
|
-
case 7: return [4, (0, index_1.getSteedosSchema)()
|
|
146
|
-
.getObject(next.reference_from)
|
|
147
|
-
.findOne(reslut, { fields: [next.field_name] })];
|
|
148
|
-
case 8:
|
|
149
|
-
found = _a.sent();
|
|
150
|
-
_a.label = 9;
|
|
151
|
-
case 9:
|
|
152
|
-
lastReferenceToField = next.reference_to_field;
|
|
153
|
-
if (found) {
|
|
154
|
-
reslut = found[next.field_name];
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
reslut = null;
|
|
158
|
-
}
|
|
159
|
-
_a.label = 10;
|
|
160
|
-
case 10:
|
|
161
|
-
index++;
|
|
162
|
-
return [3, 1];
|
|
163
|
-
case 11: return [2, reslut];
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
}); })()];
|
|
167
|
-
case 1:
|
|
168
|
-
tempValue = _d.sent();
|
|
169
|
-
params.push({
|
|
170
|
-
key: key,
|
|
171
|
-
path: _.last(paths),
|
|
172
|
-
value: tempValue,
|
|
173
|
-
});
|
|
174
|
-
return [2];
|
|
49
|
+
const computeFormulaParams = async (doc, vars, userSession) => {
|
|
50
|
+
let params = [];
|
|
51
|
+
const spaceId = userSession?.spaceId;
|
|
52
|
+
const currentUserId = userSession?.userId;
|
|
53
|
+
if (vars && vars.length) {
|
|
54
|
+
for (let { key, paths, is_user_var: isUserVar, is_user_session_var: isUserSessionVar, is_simple_var: isSimpleVar, } of vars) {
|
|
55
|
+
key = key.trim();
|
|
56
|
+
let tempValue;
|
|
57
|
+
if (isUserVar || isUserSessionVar) {
|
|
58
|
+
if (!userSession) {
|
|
59
|
+
throw new Error(`computeFormulaParams:The param 'userSession' is required for the formula var key ${key} while running`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (isSimpleVar) {
|
|
63
|
+
tempValue = doc[key];
|
|
64
|
+
params.push({
|
|
65
|
+
key: key,
|
|
66
|
+
value: tempValue,
|
|
67
|
+
});
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (isUserSessionVar) {
|
|
71
|
+
tempValue = _.reduce(key.split("."), function (reslut, next, index) {
|
|
72
|
+
if (index === 0) {
|
|
73
|
+
return reslut;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
return reslut[next];
|
|
77
|
+
}
|
|
78
|
+
}, userSession);
|
|
79
|
+
params.push({
|
|
80
|
+
key: key,
|
|
81
|
+
value: tempValue,
|
|
82
|
+
});
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
tempValue = await (async () => {
|
|
86
|
+
let reslut = null;
|
|
87
|
+
let lastReferenceToField = null;
|
|
88
|
+
for (let index = 0; index < paths.length; index++) {
|
|
89
|
+
let next = paths[index];
|
|
90
|
+
if (index === 0) {
|
|
91
|
+
lastReferenceToField = next.reference_to_field;
|
|
92
|
+
if (isUserVar) {
|
|
93
|
+
const sus = await (0, index_1.getSteedosSchema)()
|
|
94
|
+
.getObject("space_users")
|
|
95
|
+
.find({
|
|
96
|
+
filters: [
|
|
97
|
+
["user", "=", currentUserId],
|
|
98
|
+
["space", "=", spaceId],
|
|
99
|
+
],
|
|
100
|
+
fields: [next.field_name],
|
|
101
|
+
});
|
|
102
|
+
reslut = sus && sus.length && sus[0];
|
|
103
|
+
if (reslut) {
|
|
104
|
+
reslut = reslut[next.field_name];
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
reslut = null;
|
|
108
|
+
}
|
|
175
109
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
110
|
+
else {
|
|
111
|
+
reslut = doc[next.field_name];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
if (!reslut) {
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
let found;
|
|
119
|
+
if (lastReferenceToField && lastReferenceToField !== "_id") {
|
|
120
|
+
found = await (0, index_1.getSteedosSchema)()
|
|
121
|
+
.getObject(next.reference_from)
|
|
122
|
+
.findOne({ filters: [lastReferenceToField, "=", reslut] }, { fields: [next.field_name] });
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
found = await (0, index_1.getSteedosSchema)()
|
|
126
|
+
.getObject(next.reference_from)
|
|
127
|
+
.findOne(reslut, { fields: [next.field_name] });
|
|
128
|
+
}
|
|
129
|
+
lastReferenceToField = next.reference_to_field;
|
|
130
|
+
if (found) {
|
|
131
|
+
reslut = found[next.field_name];
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
reslut = null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
201
137
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
138
|
+
return reslut;
|
|
139
|
+
})();
|
|
140
|
+
params.push({
|
|
141
|
+
key: key,
|
|
142
|
+
path: _.last(paths),
|
|
143
|
+
value: tempValue,
|
|
144
|
+
});
|
|
205
145
|
}
|
|
206
|
-
}
|
|
207
|
-
|
|
146
|
+
}
|
|
147
|
+
return params;
|
|
148
|
+
};
|
|
208
149
|
exports.computeFormulaParams = computeFormulaParams;
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
returnType: data_type,
|
|
223
|
-
blankValue: formula_blank_value,
|
|
224
|
-
record: doc,
|
|
225
|
-
userSession: userSession,
|
|
226
|
-
}, fieldFormulaConfig)];
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
}); };
|
|
150
|
+
const computeFieldFormulaValue = async (doc, fieldFormulaConfig, userSession) => {
|
|
151
|
+
if (!userSession) {
|
|
152
|
+
(0, util_1.checkUserSessionNotRequiredForFieldFormulas)(fieldFormulaConfig);
|
|
153
|
+
}
|
|
154
|
+
const { formula, vars, data_type, formula_blank_value } = fieldFormulaConfig;
|
|
155
|
+
let params = await (0, exports.computeFormulaParams)(doc, vars, userSession);
|
|
156
|
+
return (0, exports.runFormula)(formula, params, {
|
|
157
|
+
returnType: data_type,
|
|
158
|
+
blankValue: formula_blank_value,
|
|
159
|
+
record: doc,
|
|
160
|
+
userSession: userSession,
|
|
161
|
+
}, fieldFormulaConfig);
|
|
162
|
+
};
|
|
230
163
|
exports.computeFieldFormulaValue = computeFieldFormulaValue;
|
|
231
|
-
|
|
164
|
+
const evalFieldFormula = function (formula, formulaParams) {
|
|
232
165
|
try {
|
|
233
166
|
return (0, formula_1.parse)(formula, formulaParams);
|
|
234
167
|
}
|
|
235
168
|
catch (ex) {
|
|
236
169
|
formulaParams[type_1.FormulaUserKey] = "{...}";
|
|
237
|
-
throw new Error(
|
|
170
|
+
throw new Error(`evalFieldFormula:Catch an error "${ex}" while eval formula "${formula}" with params "${JSON.stringify(formulaParams)}"`);
|
|
238
171
|
}
|
|
239
172
|
};
|
|
240
173
|
exports.evalFieldFormula = evalFieldFormula;
|
|
241
|
-
|
|
174
|
+
const runFormula = function (formula, params, options, messageTag) {
|
|
242
175
|
if ((0, exports.isAmisFormula)(formula)) {
|
|
243
176
|
return (0, exports.runAmisFormula)(formula, params, options, messageTag);
|
|
244
177
|
}
|
|
@@ -247,7 +180,7 @@ var runFormula = function (formula, params, options, messageTag) {
|
|
|
247
180
|
}
|
|
248
181
|
};
|
|
249
182
|
exports.runFormula = runFormula;
|
|
250
|
-
|
|
183
|
+
const getAmisGlobalVariables = (userSession) => {
|
|
251
184
|
if (!userSession) {
|
|
252
185
|
return {};
|
|
253
186
|
}
|
|
@@ -260,40 +193,39 @@ var getAmisGlobalVariables = function (userSession) {
|
|
|
260
193
|
};
|
|
261
194
|
};
|
|
262
195
|
exports.getAmisGlobalVariables = getAmisGlobalVariables;
|
|
263
|
-
|
|
196
|
+
const isAmisFormula = (formula) => {
|
|
264
197
|
return /\$\{.+\}/.test(formula);
|
|
265
198
|
};
|
|
266
199
|
exports.isAmisFormula = isAmisFormula;
|
|
267
|
-
|
|
268
|
-
|
|
200
|
+
const runAmisFormula = function (formula, params, options, messageTag) {
|
|
201
|
+
const { record, userSession } = options;
|
|
269
202
|
try {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
_.each(params,
|
|
273
|
-
|
|
203
|
+
const globalVariables = (0, exports.getAmisGlobalVariables)(userSession);
|
|
204
|
+
let data = {};
|
|
205
|
+
_.each(params, (item) => {
|
|
206
|
+
data[item.key] = item.value;
|
|
274
207
|
});
|
|
275
|
-
|
|
276
|
-
|
|
208
|
+
data = convertToNestedObject(data);
|
|
209
|
+
const amisFormulaValue = (0, amis_formula_1.evaluate)(formula, Object.assign({}, globalVariables, record, data), {});
|
|
277
210
|
if (formula === amisFormulaValue) {
|
|
278
|
-
throw new Error(
|
|
211
|
+
throw new Error(`Amis formula "${formula}" evaluate failed "Function is not defined".`);
|
|
279
212
|
}
|
|
280
213
|
else {
|
|
281
214
|
return amisFormulaValue;
|
|
282
215
|
}
|
|
283
216
|
}
|
|
284
217
|
catch (e) {
|
|
285
|
-
throw new Error(
|
|
218
|
+
throw new Error(`Catch an error "${e.message}" while evaluate amis formula "${formula}".`);
|
|
286
219
|
}
|
|
287
220
|
};
|
|
288
221
|
exports.runAmisFormula = runAmisFormula;
|
|
289
|
-
|
|
222
|
+
const runSFFormula = function (formula, params, options, messageTag) {
|
|
290
223
|
if (!options) {
|
|
291
224
|
options = {};
|
|
292
225
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
params.forEach(
|
|
296
|
-
var key = _a.key, path = _a.path, value = _a.value;
|
|
226
|
+
let { returnType, blankValue } = options;
|
|
227
|
+
let formulaParams = {};
|
|
228
|
+
params.forEach(({ key, path, value }) => {
|
|
297
229
|
if (path) {
|
|
298
230
|
formulaParams[key] = (0, params_1.getFieldSubstitution)(path.reference_from, path.field_name, value, blankValue);
|
|
299
231
|
}
|
|
@@ -301,12 +233,12 @@ var runSFFormula = function (formula, params, options, messageTag) {
|
|
|
301
233
|
formulaParams[key] = (0, simple_params_1.getSimpleParamSubstitution)(value, blankValue);
|
|
302
234
|
}
|
|
303
235
|
});
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
236
|
+
let result = (0, exports.evalFieldFormula)(formula, formulaParams);
|
|
237
|
+
let formulaValue = result.value;
|
|
238
|
+
let formulaValueType = result.dataType;
|
|
307
239
|
if (result.type === "error") {
|
|
308
240
|
console.error(formula, formulaParams);
|
|
309
|
-
throw new Error(
|
|
241
|
+
throw new Error(`runFormula:Catch an error "${result.message}" while eval formula "${formula}" with params: "${JSON.stringify(formulaParams)}" for "${JSON.stringify(messageTag)}"`);
|
|
310
242
|
}
|
|
311
243
|
if (formulaValueType === "number" && _.isNaN(formulaValue)) {
|
|
312
244
|
formulaValue = null;
|
|
@@ -315,46 +247,46 @@ var runSFFormula = function (formula, params, options, messageTag) {
|
|
|
315
247
|
switch (returnType) {
|
|
316
248
|
case "boolean":
|
|
317
249
|
if (formulaValueType !== "checkbox") {
|
|
318
|
-
throw new Error(
|
|
250
|
+
throw new Error(`runFormula:The field formula "${formula}" with params "${JSON.stringify(formulaParams)}" should return a boolean type result but got a ${formulaValueType} type value '${formulaValue}'.`);
|
|
319
251
|
}
|
|
320
252
|
break;
|
|
321
253
|
case "number":
|
|
322
254
|
if (formulaValueType !== "number") {
|
|
323
|
-
throw new Error(
|
|
255
|
+
throw new Error(`runFormula:The field formula "${formula}" with params "${JSON.stringify(formulaParams)}" should return a number type result but got a ${formulaValueType} type value '${formulaValue}'.`);
|
|
324
256
|
}
|
|
325
257
|
break;
|
|
326
258
|
case "currency":
|
|
327
259
|
if (formulaValueType !== "number") {
|
|
328
|
-
throw new Error(
|
|
260
|
+
throw new Error(`runFormula:The field formula "${formula}" with params "${JSON.stringify(formulaParams)}" should return a number type result but got a ${formulaValueType} type value '${formulaValue}'.`);
|
|
329
261
|
}
|
|
330
262
|
break;
|
|
331
263
|
case "percent":
|
|
332
264
|
if (formulaValueType !== "number") {
|
|
333
|
-
throw new Error(
|
|
265
|
+
throw new Error(`runFormula:The field formula "${formula}" with params "${JSON.stringify(formulaParams)}" should return a number type result but got a ${formulaValueType} type value '${formulaValue}'.`);
|
|
334
266
|
}
|
|
335
267
|
break;
|
|
336
268
|
case "text":
|
|
337
269
|
if (formulaValueType !== "text") {
|
|
338
|
-
throw new Error(
|
|
270
|
+
throw new Error(`runFormula:The field formula "${formula}" with params "${JSON.stringify(formulaParams)}" should return a string type result but got a ${formulaValueType} type value '${formulaValue}'.`);
|
|
339
271
|
}
|
|
340
272
|
break;
|
|
341
273
|
case "date":
|
|
342
274
|
if (formulaValueType !== "date") {
|
|
343
|
-
throw new Error(
|
|
275
|
+
throw new Error(`runFormula:The field formula "${formula}" with params "${JSON.stringify(formulaParams)}" should return a date type result but got a ${formulaValueType} type value '${formulaValue}'.`);
|
|
344
276
|
}
|
|
345
277
|
break;
|
|
346
278
|
case "datetime":
|
|
347
279
|
if (formulaValueType !== "datetime") {
|
|
348
|
-
throw new Error(
|
|
280
|
+
throw new Error(`runFormula:The field formula "${formula}" with params "${JSON.stringify(formulaParams)}" should return a date type result but got a ${formulaValueType} type value '${formulaValue}'.`);
|
|
349
281
|
}
|
|
350
282
|
break;
|
|
351
283
|
}
|
|
352
284
|
}
|
|
353
285
|
return formulaValue;
|
|
354
286
|
};
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
287
|
+
const addToAggregatePaths = (varItemToAggregatePaths, toAggregatePaths) => {
|
|
288
|
+
const pathLength = varItemToAggregatePaths.length;
|
|
289
|
+
let existPath = toAggregatePaths.find((item) => {
|
|
358
290
|
return (JSON.stringify(item.slice(0, pathLength)) ===
|
|
359
291
|
JSON.stringify(varItemToAggregatePaths.slice(0, pathLength)));
|
|
360
292
|
});
|
|
@@ -362,378 +294,159 @@ var addToAggregatePaths = function (varItemToAggregatePaths, toAggregatePaths) {
|
|
|
362
294
|
toAggregatePaths.push(varItemToAggregatePaths);
|
|
363
295
|
}
|
|
364
296
|
};
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
case 2:
|
|
380
|
-
if (!quotedByConfigs.allConfigs.length) {
|
|
381
|
-
return [2];
|
|
382
|
-
}
|
|
383
|
-
if (!userSession) {
|
|
384
|
-
(0, util_1.checkUserSessionNotRequiredForFieldFormulas)(quotedByConfigs.allConfigs);
|
|
385
|
-
}
|
|
386
|
-
_d.label = 3;
|
|
387
|
-
case 3:
|
|
388
|
-
_d.trys.push([3, 8, 9, 10]);
|
|
389
|
-
_a = tslib_1.__values(quotedByConfigs.allConfigs), _b = _a.next();
|
|
390
|
-
_d.label = 4;
|
|
391
|
-
case 4:
|
|
392
|
-
if (!!_b.done) return [3, 7];
|
|
393
|
-
config = _b.value;
|
|
394
|
-
return [4, (0, exports.updateQuotedByObjectFieldFormulaValue)(objectName, recordId, config, userSession, quotedByConfigs.ownConfigs)];
|
|
395
|
-
case 5:
|
|
396
|
-
_d.sent();
|
|
397
|
-
_d.label = 6;
|
|
398
|
-
case 6:
|
|
399
|
-
_b = _a.next();
|
|
400
|
-
return [3, 4];
|
|
401
|
-
case 7: return [3, 10];
|
|
402
|
-
case 8:
|
|
403
|
-
e_2_1 = _d.sent();
|
|
404
|
-
e_2 = { error: e_2_1 };
|
|
405
|
-
return [3, 10];
|
|
406
|
-
case 9:
|
|
407
|
-
try {
|
|
408
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
409
|
-
}
|
|
410
|
-
finally { if (e_2) throw e_2.error; }
|
|
411
|
-
return [7];
|
|
412
|
-
case 10: return [2];
|
|
413
|
-
}
|
|
414
|
-
});
|
|
415
|
-
});
|
|
297
|
+
const runQuotedByObjectFieldFormulas = async function (objectName, recordId, userSession, options = {}) {
|
|
298
|
+
let { fieldNames, escapeConfigs, quotedByConfigs, onlyForOwn, withoutCurrent, } = options;
|
|
299
|
+
if (!quotedByConfigs) {
|
|
300
|
+
quotedByConfigs = await (0, field_formula_1.getObjectQuotedByFieldFormulaConfigs)(objectName, fieldNames, escapeConfigs, { onlyForOwn, withoutCurrent });
|
|
301
|
+
}
|
|
302
|
+
if (!quotedByConfigs.allConfigs.length) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
if (!userSession) {
|
|
306
|
+
(0, util_1.checkUserSessionNotRequiredForFieldFormulas)(quotedByConfigs.allConfigs);
|
|
307
|
+
}
|
|
308
|
+
for (const config of quotedByConfigs.allConfigs) {
|
|
309
|
+
await (0, exports.updateQuotedByObjectFieldFormulaValue)(objectName, recordId, config, userSession, quotedByConfigs.ownConfigs);
|
|
310
|
+
}
|
|
416
311
|
};
|
|
417
312
|
exports.runQuotedByObjectFieldFormulas = runQuotedByObjectFieldFormulas;
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
if (!userSession) {
|
|
435
|
-
(0, util_1.checkUserSessionNotRequiredForFieldFormulas)(configs);
|
|
436
|
-
}
|
|
437
|
-
setDoc = {};
|
|
438
|
-
_d.label = 3;
|
|
439
|
-
case 3:
|
|
440
|
-
_d.trys.push([3, 8, 9, 10]);
|
|
441
|
-
configs_1 = tslib_1.__values(configs), configs_1_1 = configs_1.next();
|
|
442
|
-
_d.label = 4;
|
|
443
|
-
case 4:
|
|
444
|
-
if (!!configs_1_1.done) return [3, 7];
|
|
445
|
-
config = configs_1_1.value;
|
|
446
|
-
doc = Object.assign({}, doc, setDoc);
|
|
447
|
-
_a = setDoc;
|
|
448
|
-
_b = config.field_name;
|
|
449
|
-
return [4, (0, exports.computeFieldFormulaValue)(doc, config, userSession)];
|
|
450
|
-
case 5:
|
|
451
|
-
_a[_b] = _d.sent();
|
|
452
|
-
_d.label = 6;
|
|
453
|
-
case 6:
|
|
454
|
-
configs_1_1 = configs_1.next();
|
|
455
|
-
return [3, 4];
|
|
456
|
-
case 7: return [3, 10];
|
|
457
|
-
case 8:
|
|
458
|
-
e_3_1 = _d.sent();
|
|
459
|
-
e_3 = { error: e_3_1 };
|
|
460
|
-
return [3, 10];
|
|
461
|
-
case 9:
|
|
462
|
-
try {
|
|
463
|
-
if (configs_1_1 && !configs_1_1.done && (_c = configs_1.return)) _c.call(configs_1);
|
|
464
|
-
}
|
|
465
|
-
finally { if (e_3) throw e_3.error; }
|
|
466
|
-
return [7];
|
|
467
|
-
case 10: return [2, setDoc];
|
|
468
|
-
}
|
|
469
|
-
});
|
|
470
|
-
});
|
|
313
|
+
const getCurrentObjectFieldFormulasDoc = async function (objectName, doc, userSession, configs) {
|
|
314
|
+
if (!configs) {
|
|
315
|
+
configs = await (0, field_formula_1.getObjectFieldFormulaConfigs)(objectName);
|
|
316
|
+
}
|
|
317
|
+
if (!configs.length) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (!userSession) {
|
|
321
|
+
(0, util_1.checkUserSessionNotRequiredForFieldFormulas)(configs);
|
|
322
|
+
}
|
|
323
|
+
let setDoc = {};
|
|
324
|
+
for (const config of configs) {
|
|
325
|
+
doc = Object.assign({}, doc, setDoc);
|
|
326
|
+
setDoc[config.field_name] = await (0, exports.computeFieldFormulaValue)(doc, config, userSession);
|
|
327
|
+
}
|
|
328
|
+
return setDoc;
|
|
471
329
|
};
|
|
472
330
|
exports.getCurrentObjectFieldFormulasDoc = getCurrentObjectFieldFormulasDoc;
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
512
|
-
finally {
|
|
513
|
-
try {
|
|
514
|
-
if (vars_2_1 && !vars_2_1.done && (_a = vars_2.return)) _a.call(vars_2);
|
|
515
|
-
}
|
|
516
|
-
finally { if (e_5) throw e_5.error; }
|
|
517
|
-
}
|
|
518
|
-
formulaVarFields = (0, exports.pickFieldFormulaVarFields)(fieldFormulaConfig);
|
|
519
|
-
_d.label = 1;
|
|
520
|
-
case 1:
|
|
521
|
-
_d.trys.push([1, 18, 19, 20]);
|
|
522
|
-
toAggregatePaths_1 = tslib_1.__values(toAggregatePaths), toAggregatePaths_1_1 = toAggregatePaths_1.next();
|
|
523
|
-
_d.label = 2;
|
|
524
|
-
case 2:
|
|
525
|
-
if (!!toAggregatePaths_1_1.done) return [3, 17];
|
|
526
|
-
toAggregatePathsItem = toAggregatePaths_1_1.value;
|
|
527
|
-
if (!(toAggregatePathsItem.length < 3)) return [3, 11];
|
|
528
|
-
tempPath = toAggregatePathsItem[0];
|
|
529
|
-
if (!(fieldFormulaObjectName === objectName &&
|
|
530
|
-
tempPath.reference_from === objectName)) return [3, 5];
|
|
531
|
-
return [4, fieldFormulaObject.findOne(recordId, {
|
|
532
|
-
fields: formulaVarFields,
|
|
533
|
-
})];
|
|
534
|
-
case 3:
|
|
535
|
-
doc = _d.sent();
|
|
536
|
-
return [4, (0, exports.updateDocsFieldFormulaValue)(doc, fieldFormulaConfig, userSession, escapeConfigs)];
|
|
537
|
-
case 4:
|
|
538
|
-
_d.sent();
|
|
539
|
-
return [3, 10];
|
|
540
|
-
case 5:
|
|
541
|
-
referenceToValue = recordId;
|
|
542
|
-
if (!(tempPath.reference_to_field &&
|
|
543
|
-
tempPath.reference_to_field !== "_id")) return [3, 7];
|
|
544
|
-
return [4, currentObject.findOne(recordId, {
|
|
331
|
+
const updateQuotedByObjectFieldFormulaValue = async (objectName, recordId, fieldFormulaConfig, userSession, escapeConfigs) => {
|
|
332
|
+
const { vars, object_name: fieldFormulaObjectName } = fieldFormulaConfig;
|
|
333
|
+
const currentObject = (0, index_1.getSteedosSchema)().getObject(objectName);
|
|
334
|
+
const fieldFormulaObject = (0, index_1.getSteedosSchema)().getObject(fieldFormulaObjectName);
|
|
335
|
+
let toAggregatePaths = [];
|
|
336
|
+
for (let varItem of vars) {
|
|
337
|
+
const { paths } = varItem;
|
|
338
|
+
let isInPaths = false;
|
|
339
|
+
let varItemToAggregatePaths = [];
|
|
340
|
+
for (let pathItem of paths) {
|
|
341
|
+
varItemToAggregatePaths.push(pathItem);
|
|
342
|
+
if (pathItem.reference_from === objectName) {
|
|
343
|
+
isInPaths = true;
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (isInPaths) {
|
|
348
|
+
addToAggregatePaths(varItemToAggregatePaths, toAggregatePaths);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
const formulaVarFields = (0, exports.pickFieldFormulaVarFields)(fieldFormulaConfig);
|
|
352
|
+
for (let toAggregatePathsItem of toAggregatePaths) {
|
|
353
|
+
if (toAggregatePathsItem.length < 3) {
|
|
354
|
+
let tempPath = toAggregatePathsItem[0];
|
|
355
|
+
if (fieldFormulaObjectName === objectName &&
|
|
356
|
+
tempPath.reference_from === objectName) {
|
|
357
|
+
let doc = await fieldFormulaObject.findOne(recordId, {
|
|
358
|
+
fields: formulaVarFields,
|
|
359
|
+
});
|
|
360
|
+
await (0, exports.updateDocsFieldFormulaValue)(doc, fieldFormulaConfig, userSession, escapeConfigs);
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
let referenceToValue = recordId;
|
|
364
|
+
if (tempPath.reference_to_field &&
|
|
365
|
+
tempPath.reference_to_field !== "_id") {
|
|
366
|
+
let record = await currentObject.findOne(recordId, {
|
|
545
367
|
fields: [tempPath.reference_to_field],
|
|
546
|
-
})
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
_d.label = 7;
|
|
551
|
-
case 7: return [4, fieldFormulaObject.find({
|
|
368
|
+
});
|
|
369
|
+
referenceToValue = record && record[tempPath.reference_to_field];
|
|
370
|
+
}
|
|
371
|
+
let docs = await fieldFormulaObject.find({
|
|
552
372
|
filters: [[tempPath.field_name, "=", referenceToValue]],
|
|
553
373
|
fields: formulaVarFields,
|
|
554
|
-
})
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
if (!(lastLookup.foreignField && lastLookup.foreignField !== "_id")) return [3, 13];
|
|
567
|
-
return [4, currentObject.findOne(recordId, {
|
|
568
|
-
fields: [lastLookup.foreignField],
|
|
569
|
-
})];
|
|
570
|
-
case 12:
|
|
571
|
-
record = _d.sent();
|
|
374
|
+
});
|
|
375
|
+
await (0, exports.updateDocsFieldFormulaValue)(docs, fieldFormulaConfig, userSession, escapeConfigs);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
let aggregateLookups = (0, util_1.getFormulaVarPathsAggregateLookups)(toAggregatePathsItem);
|
|
380
|
+
let lastLookup = aggregateLookups[aggregateLookups.length - 1]["$lookup"];
|
|
381
|
+
let referenceToValue = recordId;
|
|
382
|
+
if (lastLookup.foreignField && lastLookup.foreignField !== "_id") {
|
|
383
|
+
let record = await currentObject.findOne(recordId, {
|
|
384
|
+
fields: [lastLookup.foreignField],
|
|
385
|
+
});
|
|
572
386
|
referenceToValue = record && record[lastLookup.foreignField];
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
case 14:
|
|
583
|
-
docs = _d.sent();
|
|
584
|
-
return [4, (0, exports.updateDocsFieldFormulaValue)(docs, fieldFormulaConfig, userSession, escapeConfigs)];
|
|
585
|
-
case 15:
|
|
586
|
-
_d.sent();
|
|
587
|
-
_d.label = 16;
|
|
588
|
-
case 16:
|
|
589
|
-
toAggregatePaths_1_1 = toAggregatePaths_1.next();
|
|
590
|
-
return [3, 2];
|
|
591
|
-
case 17: return [3, 20];
|
|
592
|
-
case 18:
|
|
593
|
-
e_4_1 = _d.sent();
|
|
594
|
-
e_4 = { error: e_4_1 };
|
|
595
|
-
return [3, 20];
|
|
596
|
-
case 19:
|
|
597
|
-
try {
|
|
598
|
-
if (toAggregatePaths_1_1 && !toAggregatePaths_1_1.done && (_c = toAggregatePaths_1.return)) _c.call(toAggregatePaths_1);
|
|
599
|
-
}
|
|
600
|
-
finally { if (e_4) throw e_4.error; }
|
|
601
|
-
return [7];
|
|
602
|
-
case 20: return [2];
|
|
387
|
+
}
|
|
388
|
+
let aggregateFilters = [
|
|
389
|
+
[`${lastLookup.as}.${lastLookup.foreignField}`, "=", referenceToValue],
|
|
390
|
+
];
|
|
391
|
+
const docs = await fieldFormulaObject.directAggregatePrefixalPipeline({
|
|
392
|
+
filters: aggregateFilters,
|
|
393
|
+
fields: formulaVarFields,
|
|
394
|
+
}, aggregateLookups);
|
|
395
|
+
await (0, exports.updateDocsFieldFormulaValue)(docs, fieldFormulaConfig, userSession, escapeConfigs);
|
|
603
396
|
}
|
|
604
|
-
}
|
|
605
|
-
}
|
|
397
|
+
}
|
|
398
|
+
};
|
|
606
399
|
exports.updateQuotedByObjectFieldFormulaValue = updateQuotedByObjectFieldFormulaValue;
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
docs_1 = tslib_1.__values(docs), docs_1_1 = docs_1.next();
|
|
625
|
-
_b.label = 2;
|
|
626
|
-
case 2:
|
|
627
|
-
if (!!docs_1_1.done) return [3, 6];
|
|
628
|
-
doc = docs_1_1.value;
|
|
629
|
-
return [4, (0, exports.computeFieldFormulaValue)(doc, fieldFormulaConfig, userSession)];
|
|
630
|
-
case 3:
|
|
631
|
-
value = _b.sent();
|
|
632
|
-
setDoc = {};
|
|
633
|
-
setDoc[fieldFormulaConfig.field_name] = value;
|
|
634
|
-
return [4, fieldFormulaObject.directUpdate(doc._id, setDoc)];
|
|
635
|
-
case 4:
|
|
636
|
-
_b.sent();
|
|
637
|
-
_b.label = 5;
|
|
638
|
-
case 5:
|
|
639
|
-
docs_1_1 = docs_1.next();
|
|
640
|
-
return [3, 2];
|
|
641
|
-
case 6: return [3, 9];
|
|
642
|
-
case 7:
|
|
643
|
-
e_7_1 = _b.sent();
|
|
644
|
-
e_7 = { error: e_7_1 };
|
|
645
|
-
return [3, 9];
|
|
646
|
-
case 8:
|
|
647
|
-
try {
|
|
648
|
-
if (docs_1_1 && !docs_1_1.done && (_a = docs_1.return)) _a.call(docs_1);
|
|
649
|
-
}
|
|
650
|
-
finally { if (e_7) throw e_7.error; }
|
|
651
|
-
return [7];
|
|
652
|
-
case 9: return [4, (0, exports.updateQuotedByDocsForFormulaType)(docs, fieldFormulaConfig, userSession, escapeConfigs)];
|
|
653
|
-
case 10:
|
|
654
|
-
_b.sent();
|
|
655
|
-
return [2];
|
|
656
|
-
}
|
|
657
|
-
});
|
|
658
|
-
}); };
|
|
400
|
+
const updateDocsFieldFormulaValue = async (docs, fieldFormulaConfig, userSession, escapeConfigs) => {
|
|
401
|
+
const { object_name: fieldFormulaObjectName } = fieldFormulaConfig;
|
|
402
|
+
if (!_.isArray(docs)) {
|
|
403
|
+
docs = [docs];
|
|
404
|
+
}
|
|
405
|
+
if (!docs.length) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
const fieldFormulaObject = (0, index_1.getSteedosSchema)().getObject(fieldFormulaObjectName);
|
|
409
|
+
for (let doc of docs) {
|
|
410
|
+
let value = await (0, exports.computeFieldFormulaValue)(doc, fieldFormulaConfig, userSession);
|
|
411
|
+
let setDoc = {};
|
|
412
|
+
setDoc[fieldFormulaConfig.field_name] = value;
|
|
413
|
+
await fieldFormulaObject.directUpdate(doc._id, setDoc);
|
|
414
|
+
}
|
|
415
|
+
await (0, exports.updateQuotedByDocsForFormulaType)(docs, fieldFormulaConfig, userSession, escapeConfigs);
|
|
416
|
+
};
|
|
659
417
|
exports.updateDocsFieldFormulaValue = updateDocsFieldFormulaValue;
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
docs_2 = tslib_1.__values(docs), docs_2_1 = docs_2.next();
|
|
684
|
-
_b.label = 4;
|
|
685
|
-
case 4:
|
|
686
|
-
if (!!docs_2_1.done) return [3, 8];
|
|
687
|
-
doc = docs_2_1.value;
|
|
688
|
-
return [4, (0, exports.runQuotedByObjectFieldFormulas)(fieldFormulaObjectName, doc._id, userSession, {
|
|
689
|
-
fieldNames: fieldNames,
|
|
690
|
-
quotedByConfigs: formulaQuotedByConfigs,
|
|
691
|
-
escapeConfigs: escapeConfigs,
|
|
692
|
-
})];
|
|
693
|
-
case 5:
|
|
694
|
-
_b.sent();
|
|
695
|
-
return [4, (0, summary_1.runQuotedByObjectFieldSummaries)(fieldFormulaObjectName, doc._id, null, userSession, {
|
|
696
|
-
fieldNames: fieldNames,
|
|
697
|
-
quotedByConfigs: summaryQuotedByConfigs,
|
|
698
|
-
})];
|
|
699
|
-
case 6:
|
|
700
|
-
_b.sent();
|
|
701
|
-
_b.label = 7;
|
|
702
|
-
case 7:
|
|
703
|
-
docs_2_1 = docs_2.next();
|
|
704
|
-
return [3, 4];
|
|
705
|
-
case 8: return [3, 11];
|
|
706
|
-
case 9:
|
|
707
|
-
e_8_1 = _b.sent();
|
|
708
|
-
e_8 = { error: e_8_1 };
|
|
709
|
-
return [3, 11];
|
|
710
|
-
case 10:
|
|
711
|
-
try {
|
|
712
|
-
if (docs_2_1 && !docs_2_1.done && (_a = docs_2.return)) _a.call(docs_2);
|
|
713
|
-
}
|
|
714
|
-
finally { if (e_8) throw e_8.error; }
|
|
715
|
-
return [7];
|
|
716
|
-
case 11: return [2];
|
|
717
|
-
}
|
|
718
|
-
});
|
|
719
|
-
}); };
|
|
418
|
+
const updateQuotedByDocsForFormulaType = async (docs, fieldFormulaConfig, userSession, escapeConfigs) => {
|
|
419
|
+
const { object_name: fieldFormulaObjectName } = fieldFormulaConfig;
|
|
420
|
+
if (!_.isArray(docs)) {
|
|
421
|
+
docs = [docs];
|
|
422
|
+
}
|
|
423
|
+
if (!docs.length) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
const fieldNames = [fieldFormulaConfig.field_name];
|
|
427
|
+
const formulaQuotedByConfigs = await (0, field_formula_1.getObjectQuotedByFieldFormulaConfigs)(fieldFormulaObjectName, fieldNames, escapeConfigs);
|
|
428
|
+
const summaryQuotedByConfigs = await (0, summary_1.getObjectQuotedByFieldSummaryConfigs)(fieldFormulaObjectName, fieldNames);
|
|
429
|
+
for (let doc of docs) {
|
|
430
|
+
await (0, exports.runQuotedByObjectFieldFormulas)(fieldFormulaObjectName, doc._id, userSession, {
|
|
431
|
+
fieldNames,
|
|
432
|
+
quotedByConfigs: formulaQuotedByConfigs,
|
|
433
|
+
escapeConfigs,
|
|
434
|
+
});
|
|
435
|
+
await (0, summary_1.runQuotedByObjectFieldSummaries)(fieldFormulaObjectName, doc._id, null, userSession, {
|
|
436
|
+
fieldNames,
|
|
437
|
+
quotedByConfigs: summaryQuotedByConfigs,
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
};
|
|
720
441
|
exports.updateQuotedByDocsForFormulaType = updateQuotedByDocsForFormulaType;
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
}
|
|
731
|
-
else {
|
|
732
|
-
return [2, false];
|
|
733
|
-
}
|
|
734
|
-
return [2];
|
|
735
|
-
}
|
|
736
|
-
});
|
|
737
|
-
}); };
|
|
442
|
+
const isFormulaFieldQuotingObjectAndFields = async (formulaObjectName, formulaFieldName, objectName, fieldNames) => {
|
|
443
|
+
const configs = await (0, field_formula_1.getObjectFieldFormulaConfigs)(formulaObjectName, formulaFieldName);
|
|
444
|
+
if (configs && configs.length) {
|
|
445
|
+
return (0, util_1.isFieldFormulaConfigQuotingObjectAndFields)(configs[0], objectName, fieldNames);
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
};
|
|
738
451
|
exports.isFormulaFieldQuotingObjectAndFields = isFormulaFieldQuotingObjectAndFields;
|
|
739
452
|
//# sourceMappingURL=core.js.map
|