@steedos/objectql 2.2.50 → 2.2.51-beta.4
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/services/helpers/graphql/consts.d.ts +17 -0
- package/lib/services/helpers/graphql/consts.js +28 -0
- package/lib/services/helpers/graphql/consts.js.map +1 -0
- package/lib/services/helpers/graphql/getQueryFields.js +17 -2
- package/lib/services/helpers/graphql/getQueryFields.js.map +1 -1
- package/lib/services/helpers/graphql/index.d.ts +1 -1
- package/lib/services/helpers/graphql/index.js +31 -46
- package/lib/services/helpers/graphql/index.js.map +1 -1
- package/lib/util/index.js +7 -0
- package/lib/util/index.js.map +1 -1
- package/package.json +11 -12
- package/src/actions/field_updates.ts +0 -118
- package/src/actions/index.ts +0 -3
- package/src/actions/types/field_update_target.ts +0 -7
- package/src/actions/types/workflow_notification.ts +0 -9
- package/src/actions/types/workflow_rule.ts +0 -11
- package/src/actions/workflow_notifications.ts +0 -81
- package/src/actions/workflow_rule.ts +0 -136
- package/src/driver/driver.ts +0 -102
- package/src/driver/field-encrytion/index.ts +0 -8
- package/src/driver/field-encrytion/sharedconst.ts +0 -34
- package/src/driver/fieldDBType.ts +0 -14
- package/src/driver/format.ts +0 -36
- package/src/driver/index.ts +0 -20
- package/src/driver/metadata.ts +0 -226
- package/src/driver/meteorMongo.ts +0 -639
- package/src/driver/mongo.ts +0 -416
- package/src/driver/mysql.ts +0 -47
- package/src/driver/oracle.ts +0 -60
- package/src/driver/postgres.ts +0 -46
- package/src/driver/sqlite3.ts +0 -40
- package/src/driver/sqlserver.ts +0 -52
- package/src/dynamic-load/actions.ts +0 -146
- package/src/dynamic-load/approval_process.ts +0 -73
- package/src/dynamic-load/button.ts +0 -75
- package/src/dynamic-load/chart.ts +0 -22
- package/src/dynamic-load/client_script.ts +0 -65
- package/src/dynamic-load/field.ts +0 -77
- package/src/dynamic-load/flow_role.ts +0 -46
- package/src/dynamic-load/index.ts +0 -21
- package/src/dynamic-load/layout.ts +0 -53
- package/src/dynamic-load/listview.ts +0 -57
- package/src/dynamic-load/method.ts +0 -63
- package/src/dynamic-load/object_translations.ts +0 -61
- package/src/dynamic-load/originalObject.ts +0 -8
- package/src/dynamic-load/package.ts +0 -312
- package/src/dynamic-load/page.ts +0 -23
- package/src/dynamic-load/permission.ts +0 -71
- package/src/dynamic-load/permissionset.ts +0 -78
- package/src/dynamic-load/preload_data.ts +0 -104
- package/src/dynamic-load/profile.ts +0 -90
- package/src/dynamic-load/query.ts +0 -22
- package/src/dynamic-load/restrictionRules.ts +0 -23
- package/src/dynamic-load/role.ts +0 -46
- package/src/dynamic-load/shareRules.ts +0 -23
- package/src/dynamic-load/tab.ts +0 -17
- package/src/dynamic-load/tabs.ts +0 -13
- package/src/dynamic-load/translations.ts +0 -54
- package/src/dynamic-load/trigger.ts +0 -236
- package/src/dynamic-load/validation_rule.ts +0 -77
- package/src/dynamic-load/workflow.ts +0 -114
- package/src/errors/index.ts +0 -111
- package/src/formula/core.ts +0 -490
- package/src/formula/field_formula.ts +0 -107
- package/src/formula/index.ts +0 -81
- package/src/formula/params.ts +0 -197
- package/src/formula/recompute.ts +0 -65
- package/src/formula/simple_params.ts +0 -92
- package/src/formula/type.ts +0 -107
- package/src/formula/util.ts +0 -207
- package/src/index.ts +0 -24
- package/src/metadata-register/_base.ts +0 -85
- package/src/metadata-register/app.ts +0 -30
- package/src/metadata-register/chart.ts +0 -9
- package/src/metadata-register/index.ts +0 -123
- package/src/metadata-register/layout.ts +0 -38
- package/src/metadata-register/object.ts +0 -68
- package/src/metadata-register/page.ts +0 -9
- package/src/metadata-register/permissionFields.ts +0 -13
- package/src/metadata-register/permissionset.ts +0 -25
- package/src/metadata-register/process.ts +0 -16
- package/src/metadata-register/processTrigger.ts +0 -24
- package/src/metadata-register/profile.ts +0 -25
- package/src/metadata-register/query.ts +0 -9
- package/src/metadata-register/restrictionRules.ts +0 -12
- package/src/metadata-register/shareRules.ts +0 -13
- package/src/metadata-register/tab.ts +0 -9
- package/src/metadata-register/tabs.ts +0 -43
- package/src/services/datasourceServiceFactory.ts +0 -55
- package/src/services/helpers/graphql/getPrimaryFieldType.ts +0 -48
- package/src/services/helpers/graphql/getQueryFields.ts +0 -36
- package/src/services/helpers/graphql/index.ts +0 -681
- package/src/services/helpers/rest.ts +0 -57
- package/src/services/index.ts +0 -13
- package/src/services/objectService.ts +0 -846
- package/src/services/objectServiceDispatcher.ts +0 -209
- package/src/services/objectServiceFactory.ts +0 -29
- package/src/summary/core.ts +0 -263
- package/src/summary/field_summary.ts +0 -71
- package/src/summary/index.ts +0 -96
- package/src/summary/recompute.ts +0 -31
- package/src/summary/type.ts +0 -60
- package/src/ts-types/index.ts +0 -3
- package/src/ts-types/permissionset.ts +0 -8
- package/src/ts-types/profile.ts +0 -11
- package/src/ts-types/triggerActionParams.ts +0 -22
- package/src/typeorm/driver.ts +0 -379
- package/src/typeorm/index.ts +0 -3
- package/src/typeorm/util.ts +0 -147
- package/src/types/action.ts +0 -52
- package/src/types/app.ts +0 -280
- package/src/types/config.ts +0 -152
- package/src/types/connection.ts +0 -87
- package/src/types/dashboard.ts +0 -91
- package/src/types/datasource.ts +0 -570
- package/src/types/field.ts +0 -370
- package/src/types/field_permission.ts +0 -42
- package/src/types/field_types.ts +0 -1
- package/src/types/index.ts +0 -21
- package/src/types/list_view.ts +0 -56
- package/src/types/listeners.ts +0 -18
- package/src/types/object.ts +0 -2076
- package/src/types/object_dynamic_load.ts +0 -426
- package/src/types/object_events.ts +0 -43
- package/src/types/object_layouts.ts +0 -20
- package/src/types/object_permission.ts +0 -134
- package/src/types/query.ts +0 -28
- package/src/types/report.ts +0 -128
- package/src/types/restrictionRule.ts +0 -57
- package/src/types/schema.ts +0 -273
- package/src/types/shareRule.ts +0 -57
- package/src/types/trigger.ts +0 -88
- package/src/types/userSession.ts +0 -45
- package/src/types/validation_rules.ts +0 -29
- package/src/util/convert.ts +0 -131
- package/src/util/field.ts +0 -93
- package/src/util/function_expression.ts +0 -63
- package/src/util/index.ts +0 -1058
- package/src/util/locale.ts +0 -24
- package/src/util/permission_shares.ts +0 -25
- package/src/util/suffix.ts +0 -78
- package/src/util/transform.ts +0 -239
- package/src/validators/index.ts +0 -36
package/src/formula/index.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { SteedosObjectTypeConfig, getObjectConfig, getSteedosSchema } from '../types';
|
|
2
|
-
import { SteedosFormulaOptions } from './type';
|
|
3
|
-
import { computeFormulaParams, pickFormulaVarFields, runFormula } from './core';
|
|
4
|
-
import { isCurrentUserIdRequiredForFormulaVars } from './util';
|
|
5
|
-
import { JsonMap } from "@salesforce/ts-types";
|
|
6
|
-
|
|
7
|
-
export * from './type'
|
|
8
|
-
export * from './util'
|
|
9
|
-
export * from './field_formula'
|
|
10
|
-
export * from './core'
|
|
11
|
-
// export * from './triggers'
|
|
12
|
-
export * from './recompute'
|
|
13
|
-
/**
|
|
14
|
-
* 根据公式内容,取出其中{}中的变量,返回计算后的公式引用集合
|
|
15
|
-
* @param formula
|
|
16
|
-
* @param fieldConfig
|
|
17
|
-
* @param objectConfigs
|
|
18
|
-
*/
|
|
19
|
-
const computeFormulaVarsAndQuotes = async (formula: string, objectConfig: SteedosObjectTypeConfig) => {
|
|
20
|
-
return await getSteedosSchema().metadataBroker.call(`objects.getFormulaVarsAndQuotes`, {formula, objectConfig})
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function checkFormula(formula: string, mainObjectName: string){
|
|
24
|
-
|
|
25
|
-
const mainObjectConfig = getObjectConfig(mainObjectName);
|
|
26
|
-
|
|
27
|
-
await computeFormulaVarsAndQuotes(formula, mainObjectConfig);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async function _computeFormula(formula: string, objectName:string, record: JsonMap, currentUserId: string, spaceId: string, options?: SteedosFormulaOptions)
|
|
31
|
-
async function _computeFormula(formula: string, objectName:string, recordId: string, currentUserId: string, spaceId: string, options?: SteedosFormulaOptions)
|
|
32
|
-
async function _computeFormula(formula: string, objectName:string, data: any, currentUserId: string, spaceId: string, options?: SteedosFormulaOptions) {
|
|
33
|
-
// 允许参数objectName为空,此时formula应该最多只引用了$user变量,未引用任何对象字段相关变量。
|
|
34
|
-
const objectConfig = objectName ? getObjectConfig(objectName) : null;
|
|
35
|
-
const varsAndQuotes = await computeFormulaVarsAndQuotes(formula, objectConfig);
|
|
36
|
-
const vars = varsAndQuotes.vars;
|
|
37
|
-
if (!currentUserId) {
|
|
38
|
-
const required = isCurrentUserIdRequiredForFormulaVars(vars);
|
|
39
|
-
if(required){
|
|
40
|
-
throw new Error(`The param 'currentUserId' is required for formula ${formula.replace("$", "\\$")}`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
let doc: any = {};
|
|
44
|
-
|
|
45
|
-
if(typeof data == "object" && data){
|
|
46
|
-
doc = data;
|
|
47
|
-
}else if(typeof data == "string"){
|
|
48
|
-
if(objectName && data){
|
|
49
|
-
const formulaVarFields = pickFormulaVarFields(vars);
|
|
50
|
-
doc = await getSteedosSchema().getObject(objectName).findOne(data, { fields: formulaVarFields });
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if(spaceId){
|
|
55
|
-
doc.space = spaceId;
|
|
56
|
-
}
|
|
57
|
-
let params = await computeFormulaParams(doc, vars, currentUserId);
|
|
58
|
-
return runFormula(formula, params, options, {objectName});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const computeFormula = _computeFormula
|
|
62
|
-
|
|
63
|
-
async function _computeSimpleFormula(formula: string, data: any, currentUserId?: string, spaceId?: string, options?: SteedosFormulaOptions) {
|
|
64
|
-
// objectConfig参数值设置为null传入computeFormulaVarsAndQuotes表示计算不带objectConfig参数的普通公式变量
|
|
65
|
-
const varsAndQuotes = await computeFormulaVarsAndQuotes(formula, null);
|
|
66
|
-
const vars = varsAndQuotes.vars;
|
|
67
|
-
if (!currentUserId) {
|
|
68
|
-
const required = isCurrentUserIdRequiredForFormulaVars(vars);
|
|
69
|
-
if(required){
|
|
70
|
-
throw new Error(`The param 'currentUserId' is required for formula ${formula.replace("$", "\\$")}`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if(spaceId){
|
|
74
|
-
data.space = spaceId;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
let params = await computeFormulaParams(data, vars, currentUserId);
|
|
78
|
-
return runFormula(formula, params, options);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export const computeSimpleFormula = _computeSimpleFormula
|
package/src/formula/params.ts
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import _ = require('underscore');
|
|
2
|
-
import { getObject } from '../types/object';
|
|
3
|
-
import { SteedosFormulaBlankValue } from './type';
|
|
4
|
-
|
|
5
|
-
export const enum FormulonDataType {
|
|
6
|
-
Text = 'text',
|
|
7
|
-
Number = 'number',
|
|
8
|
-
Date = 'date',
|
|
9
|
-
Datetime = 'datetime',
|
|
10
|
-
Time = 'time',
|
|
11
|
-
Checkbox = 'checkbox',
|
|
12
|
-
Picklist = 'picklist',
|
|
13
|
-
Multipicklist = 'multipicklist',
|
|
14
|
-
Geolocation = 'geolocation',
|
|
15
|
-
Null = 'null'
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function getFieldSteedosType(field: any){
|
|
19
|
-
if(_.include(['formula', 'summary'], field.type)){
|
|
20
|
-
return field.data_type
|
|
21
|
-
}
|
|
22
|
-
return field.type
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function getField(objectName: string, fieldName: string){
|
|
26
|
-
if(fieldName === '_id'){
|
|
27
|
-
return {type: 'text'}
|
|
28
|
-
}
|
|
29
|
-
return getObject(objectName).getField(fieldName);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function getSubstitutionDataType(objectName: string, fieldName: string, value: any){
|
|
33
|
-
const field: any = getField(objectName, fieldName);
|
|
34
|
-
const steedosType = getFieldSteedosType(field);
|
|
35
|
-
let dateType: FormulonDataType;
|
|
36
|
-
switch (steedosType) {
|
|
37
|
-
case 'text':
|
|
38
|
-
dateType = FormulonDataType.Text;
|
|
39
|
-
break;
|
|
40
|
-
case 'textarea':
|
|
41
|
-
dateType = FormulonDataType.Text;
|
|
42
|
-
break;
|
|
43
|
-
case 'html':
|
|
44
|
-
dateType = FormulonDataType.Text;
|
|
45
|
-
break;
|
|
46
|
-
case 'password':
|
|
47
|
-
dateType = FormulonDataType.Text;
|
|
48
|
-
break;
|
|
49
|
-
case 'autonumber':
|
|
50
|
-
dateType = FormulonDataType.Text;
|
|
51
|
-
break;
|
|
52
|
-
case 'url':
|
|
53
|
-
dateType = FormulonDataType.Text;
|
|
54
|
-
break;
|
|
55
|
-
case 'email':
|
|
56
|
-
dateType = FormulonDataType.Text;
|
|
57
|
-
break;
|
|
58
|
-
case 'number':
|
|
59
|
-
dateType = FormulonDataType.Number;
|
|
60
|
-
break;
|
|
61
|
-
case 'currency':
|
|
62
|
-
dateType = FormulonDataType.Number;
|
|
63
|
-
break;
|
|
64
|
-
case 'percent':
|
|
65
|
-
dateType = FormulonDataType.Number;
|
|
66
|
-
break;
|
|
67
|
-
case 'date':
|
|
68
|
-
dateType = FormulonDataType.Date;
|
|
69
|
-
break;
|
|
70
|
-
case 'datetime':
|
|
71
|
-
dateType = FormulonDataType.Datetime;
|
|
72
|
-
break;
|
|
73
|
-
case 'boolean':
|
|
74
|
-
dateType = FormulonDataType.Checkbox;
|
|
75
|
-
break;
|
|
76
|
-
case 'select':
|
|
77
|
-
if(field.multiple){
|
|
78
|
-
dateType = FormulonDataType.Multipicklist;
|
|
79
|
-
}else{
|
|
80
|
-
dateType = FormulonDataType.Picklist;
|
|
81
|
-
}
|
|
82
|
-
break;
|
|
83
|
-
case 'lookup':
|
|
84
|
-
if(field.multiple){
|
|
85
|
-
dateType = FormulonDataType.Multipicklist;
|
|
86
|
-
}else{
|
|
87
|
-
dateType = FormulonDataType.Picklist;
|
|
88
|
-
}
|
|
89
|
-
break;
|
|
90
|
-
case 'master_detail':
|
|
91
|
-
dateType = FormulonDataType.Picklist;
|
|
92
|
-
break;
|
|
93
|
-
case 'geolocation':
|
|
94
|
-
dateType = FormulonDataType.Geolocation;
|
|
95
|
-
break;
|
|
96
|
-
case 'null':
|
|
97
|
-
dateType = FormulonDataType.Null
|
|
98
|
-
break;
|
|
99
|
-
default:
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// if(dateType == FormulonDataType.Number && (value === null || value === undefined)){
|
|
104
|
-
// if(blankValue === SteedosFormulaBlankValue.blanks){
|
|
105
|
-
// // 当值为空且配置为按空值处理时按NULL类型来处理空值
|
|
106
|
-
// // 因为Number类型在公式引擎包中当值为空时始终ISBLANK及BLANKVALUE始终被判断为非空值
|
|
107
|
-
// // 目前ISBLANK只支持字符串参数,只能用ISBLANK(TEXT(Amount))这种写法代替,但是这种写法又始终被判定为false,因为公式TEXT(null)运行结果为"NULL"
|
|
108
|
-
// // 所以对于数值类型,即不能用ISBLANK(TEXT(Amount))也不能用ISBLANK(Amount),
|
|
109
|
-
// // 而应该用Amount > 0,当Amount为空时,即使设置formula_blank_value为"blanks",其返回值也是false
|
|
110
|
-
// // 实在要判断空值,可以用TEXT(Amount) == "NULL"来判断,而不可以用ISBLANK(TEXT(Amount))或ISBLANK(Amount)
|
|
111
|
-
// return FormulonDataType.Null;
|
|
112
|
-
// }
|
|
113
|
-
// }
|
|
114
|
-
return dateType;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function getSubstitutionOptions(objectName: string, fieldName: string, dataType: string){
|
|
118
|
-
const field: any = getField(objectName, fieldName);
|
|
119
|
-
const steedosType = getFieldSteedosType(field);
|
|
120
|
-
switch (dataType) {
|
|
121
|
-
case 'number':
|
|
122
|
-
let scale = 0;
|
|
123
|
-
if(_.has(field, 'scale')){
|
|
124
|
-
scale = field.scale;
|
|
125
|
-
}else{
|
|
126
|
-
// 数值类型默认按2位小数来计算
|
|
127
|
-
scale = 2;
|
|
128
|
-
}
|
|
129
|
-
if(steedosType === "percent"){
|
|
130
|
-
// 百分比类型参数,scale配置的是百分比的小数位数,计算时需要额外增加2位小数,比如scale配置为1时,像20.2%这样的数值计算时应该按0.202是三位小数参与计算。
|
|
131
|
-
scale += 2;
|
|
132
|
-
}
|
|
133
|
-
return { scale };
|
|
134
|
-
case 'text':
|
|
135
|
-
return {length: Number.MAX_VALUE};
|
|
136
|
-
case 'multipicklist':
|
|
137
|
-
// 暂时先不支持optionsFunctions的情况,只支持写死的options
|
|
138
|
-
if(field.options){
|
|
139
|
-
/*
|
|
140
|
-
直接返回类似下面的完整内容,方便需要的时候取label显示。
|
|
141
|
-
TEXT函数在我们的公式引擎及sf中都不支持multipicklist,只支持单选的picklist,所以下面的返回值暂时没找到什么地方可以用
|
|
142
|
-
[
|
|
143
|
-
{ label: 'K1', value: 'k1' },
|
|
144
|
-
{ label: 'K2', value: 'k2' },
|
|
145
|
-
{ label: 'K3', value: 'k3' }
|
|
146
|
-
]
|
|
147
|
-
*/
|
|
148
|
-
return {values: field.options};
|
|
149
|
-
}
|
|
150
|
-
else{
|
|
151
|
-
// 实测直接返回空值不影响INCLUDES函数,所以optionsFunctions等情况下直接返回空数组影响不大
|
|
152
|
-
// 至少返回空数组,否则公式会报错
|
|
153
|
-
return {values: []};
|
|
154
|
-
}
|
|
155
|
-
default:
|
|
156
|
-
return ;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function getSubstitutionValue(dataType: string, value: any, blankValue: SteedosFormulaBlankValue){
|
|
161
|
-
switch (dataType) {
|
|
162
|
-
case FormulonDataType.Text:
|
|
163
|
-
if(value === null || value === undefined){
|
|
164
|
-
return '';
|
|
165
|
-
}
|
|
166
|
-
break;
|
|
167
|
-
case FormulonDataType.Number:
|
|
168
|
-
if(value === null || value === undefined){
|
|
169
|
-
if(blankValue === SteedosFormulaBlankValue.blanks){
|
|
170
|
-
return null;
|
|
171
|
-
}
|
|
172
|
-
else{
|
|
173
|
-
return 0;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
break;
|
|
177
|
-
case FormulonDataType.Multipicklist:
|
|
178
|
-
if(value === null || value === undefined){
|
|
179
|
-
return [];
|
|
180
|
-
}
|
|
181
|
-
break;
|
|
182
|
-
default:
|
|
183
|
-
break;
|
|
184
|
-
}
|
|
185
|
-
return value;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export function getFieldSubstitution(objectName: string, fieldName: string, value: any, blankValue: SteedosFormulaBlankValue){
|
|
189
|
-
let fieldSubstitution: any = {
|
|
190
|
-
type: 'literal',
|
|
191
|
-
value: value
|
|
192
|
-
}
|
|
193
|
-
fieldSubstitution.dataType = getSubstitutionDataType(objectName, fieldName, value);
|
|
194
|
-
fieldSubstitution.options = getSubstitutionOptions(objectName, fieldName, fieldSubstitution.dataType);
|
|
195
|
-
fieldSubstitution.value = getSubstitutionValue(fieldSubstitution.dataType, value, blankValue);
|
|
196
|
-
return fieldSubstitution;
|
|
197
|
-
}
|
package/src/formula/recompute.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { getSteedosSchema } from '../index';
|
|
2
|
-
import { SteedosFieldFormulaTypeConfig } from './type';
|
|
3
|
-
import { checkCurrentUserIdNotRequiredForFieldFormulas } from './util';
|
|
4
|
-
import { getFieldFormulaConfig, getQuotedByFieldFormulaConfigs } from './field_formula';
|
|
5
|
-
import { computeFieldFormulaValue, pickFieldFormulaVarFields, updateQuotedByObjectFieldFormulaValue } from './core';
|
|
6
|
-
import { getQuotedByFieldSummaryConfigs, recomputeFieldSummaryValues } from '../summary';
|
|
7
|
-
|
|
8
|
-
const runCurrentFieldFormulas = async function (fieldFormulaConfig: SteedosFieldFormulaTypeConfig, userSession: any) {
|
|
9
|
-
const currentUserId = userSession ? userSession.userId : undefined;
|
|
10
|
-
const { field_name: fieldName, object_name: objectName } = fieldFormulaConfig;
|
|
11
|
-
const formulaVarFields = pickFieldFormulaVarFields(fieldFormulaConfig);
|
|
12
|
-
const docs = await getSteedosSchema().getObject(objectName).find({ filters: [], fields: formulaVarFields })
|
|
13
|
-
for (const doc of docs) {
|
|
14
|
-
const value = await computeFieldFormulaValue(doc, fieldFormulaConfig, currentUserId);
|
|
15
|
-
let setDoc = {};
|
|
16
|
-
setDoc[fieldName] = value;
|
|
17
|
-
await getSteedosSchema().getObject(objectName).directUpdate(doc._id, setDoc);
|
|
18
|
-
await runQuotedFieldFormulas(doc._id, fieldFormulaConfig, userSession);
|
|
19
|
-
}
|
|
20
|
-
await runQuotedFieldSummaries(fieldFormulaConfig, userSession);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const runQuotedFieldFormulas = async function (recordId: string, fieldFormulaConfig: SteedosFieldFormulaTypeConfig, userSession: any) {
|
|
24
|
-
const formulaQuotedBys = await getQuotedByFieldFormulaConfigs(fieldFormulaConfig);
|
|
25
|
-
for (const config of formulaQuotedBys.allConfigs) {
|
|
26
|
-
await updateQuotedByObjectFieldFormulaValue(fieldFormulaConfig.object_name, recordId, config, userSession);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 找到公式字段被哪些汇总字段引用,并重新计算汇总字段值(相当于点击一次界面上的“批量重算汇总值”按钮)
|
|
32
|
-
* @param fieldFormulaConfig
|
|
33
|
-
* @param userSession
|
|
34
|
-
*/
|
|
35
|
-
const runQuotedFieldSummaries = async function (fieldFormulaConfig: SteedosFieldFormulaTypeConfig, userSession: any) {
|
|
36
|
-
const summaryQuotedBys = await getQuotedByFieldSummaryConfigs(fieldFormulaConfig);
|
|
37
|
-
for (const config of summaryQuotedBys) {
|
|
38
|
-
await recomputeFieldSummaryValues(config, userSession);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* 重算指定公式字段Id对应的公式值
|
|
44
|
-
* @param fieldId : ${objectApiName}.${fieldApiName}
|
|
45
|
-
*/
|
|
46
|
-
export const recomputeFormulaValues = async (fieldId: string, userSession: any) => {
|
|
47
|
-
let config = await getFieldFormulaConfig(fieldId);
|
|
48
|
-
if (!config) {
|
|
49
|
-
throw new Error(`recomputeFormulaValues:${fieldId} not found in field_formula configs.`);
|
|
50
|
-
}
|
|
51
|
-
return await recomputeFieldFormulaValues(config, userSession);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* 重算指定公式字段的公式值
|
|
56
|
-
* @param fieldFormulaConfig
|
|
57
|
-
*/
|
|
58
|
-
export const recomputeFieldFormulaValues = async (fieldFormulaConfig: SteedosFieldFormulaTypeConfig, userSession: any) => {
|
|
59
|
-
const currentUserId = userSession ? userSession.userId : undefined;
|
|
60
|
-
if (!currentUserId) {
|
|
61
|
-
checkCurrentUserIdNotRequiredForFieldFormulas(fieldFormulaConfig);
|
|
62
|
-
}
|
|
63
|
-
await runCurrentFieldFormulas(fieldFormulaConfig, userSession);
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { SteedosFormulaBlankValue } from './type';
|
|
2
|
-
import { FormulonDataType } from './params';
|
|
3
|
-
|
|
4
|
-
const VALUE_TYPES_NOT_SUPPORTED = ["function"];
|
|
5
|
-
|
|
6
|
-
function getSubstitutionDataType(value: any){
|
|
7
|
-
const valueType = typeof value;
|
|
8
|
-
let dateType: FormulonDataType;
|
|
9
|
-
if(VALUE_TYPES_NOT_SUPPORTED.indexOf(dateType) > -1){
|
|
10
|
-
throw new Error(`runFormula:Catch an error the param type "${valueType}" is not supported while eval formula with the params value: "${value}"`);
|
|
11
|
-
}
|
|
12
|
-
switch (valueType) {
|
|
13
|
-
case 'string':
|
|
14
|
-
dateType = FormulonDataType.Text;
|
|
15
|
-
break;
|
|
16
|
-
case 'number':
|
|
17
|
-
dateType = FormulonDataType.Number;
|
|
18
|
-
break;
|
|
19
|
-
case 'boolean':
|
|
20
|
-
dateType = FormulonDataType.Checkbox;
|
|
21
|
-
break;
|
|
22
|
-
case 'object':
|
|
23
|
-
if(value === null){
|
|
24
|
-
dateType = FormulonDataType.Null;
|
|
25
|
-
}
|
|
26
|
-
else if (value instanceof Date){
|
|
27
|
-
dateType = FormulonDataType.Datetime;
|
|
28
|
-
}
|
|
29
|
-
else{
|
|
30
|
-
throw new Error(`runFormula:Catch an error the param type "${valueType}" is not supported while eval formula with the params value: "${value}"`);
|
|
31
|
-
}
|
|
32
|
-
break;
|
|
33
|
-
case 'undefined':
|
|
34
|
-
dateType = FormulonDataType.Null;
|
|
35
|
-
break;
|
|
36
|
-
default:
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
return dateType;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function getSubstitutionOptions(dataType: string, value: any){
|
|
43
|
-
switch (dataType) {
|
|
44
|
-
case FormulonDataType.Number:
|
|
45
|
-
let scale = 0;
|
|
46
|
-
let str = value.toString();
|
|
47
|
-
let dotStr = str.toString().split(".")[1];
|
|
48
|
-
let dotCount = dotStr && dotStr.length;
|
|
49
|
-
if(dotCount > 0){
|
|
50
|
-
scale = dotCount;
|
|
51
|
-
}
|
|
52
|
-
return { scale };
|
|
53
|
-
case FormulonDataType.Text:
|
|
54
|
-
return {length: Number.MAX_VALUE};
|
|
55
|
-
default:
|
|
56
|
-
return ;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function getSubstitutionValue(dataType: string, value: any, blankValue: SteedosFormulaBlankValue){
|
|
61
|
-
switch (dataType) {
|
|
62
|
-
case FormulonDataType.Text:
|
|
63
|
-
if(value === null || value === undefined){
|
|
64
|
-
return '';
|
|
65
|
-
}
|
|
66
|
-
break;
|
|
67
|
-
case FormulonDataType.Number:
|
|
68
|
-
if(value === null || value === undefined){
|
|
69
|
-
if(blankValue === SteedosFormulaBlankValue.blanks){
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
else{
|
|
73
|
-
return 0;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
break;
|
|
77
|
-
default:
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
return value;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function getSimpleParamSubstitution(value: any, blankValue: SteedosFormulaBlankValue){
|
|
84
|
-
let fieldSubstitution: any = {
|
|
85
|
-
type: 'literal',
|
|
86
|
-
value: value
|
|
87
|
-
}
|
|
88
|
-
fieldSubstitution.dataType = getSubstitutionDataType(value);
|
|
89
|
-
fieldSubstitution.options = getSubstitutionOptions(fieldSubstitution.dataType, value);
|
|
90
|
-
fieldSubstitution.value = getSubstitutionValue(fieldSubstitution.dataType, value, blankValue);
|
|
91
|
-
return fieldSubstitution;
|
|
92
|
-
}
|
package/src/formula/type.ts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
// 公式内容中表示userSession变量的占位符
|
|
2
|
-
export const FormulaUserKey = "$user";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 记录公式字段中引用的本对象或其他对象上的字段
|
|
6
|
-
* 用于相关引用字段值变更时,能找到哪些公式字段需要级联变更
|
|
7
|
-
* is_formula指field_name是否是公式字段
|
|
8
|
-
* is_own指field_name是否引用的是本对象自身的字段(字段属于对象本身,且所对应的公式变量只有唯一一层引用,即直接引用当前对象自身上的字段)
|
|
9
|
-
*/
|
|
10
|
-
export type SteedosFieldFormulaQuoteTypeConfig = {
|
|
11
|
-
object_name: string,
|
|
12
|
-
field_name: string,
|
|
13
|
-
is_formula?: boolean
|
|
14
|
-
is_own?: boolean
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 公式中的{}括起来的单个变量中的执行路径
|
|
19
|
-
* {}中第一个reference_from肯定是指向当前对象
|
|
20
|
-
* is_formula指field_name是否是公式字段
|
|
21
|
-
*/
|
|
22
|
-
export type SteedosFormulaVarPathTypeConfig = {
|
|
23
|
-
field_name: string,
|
|
24
|
-
reference_from: string,
|
|
25
|
-
is_formula?: boolean
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 运行公式时,要注入的参数,经过计算每个SteedosFieldFormulaVarTypeConfig最终会转换为该结构作为参数注入公式中
|
|
30
|
-
* 比如contacts对象中有公式{account.website}
|
|
31
|
-
* 解析后的SteedosFieldFormulaVarTypeConfig为:
|
|
32
|
-
* {
|
|
33
|
-
* key: "account.website",
|
|
34
|
-
* paths: [
|
|
35
|
-
* {field_name: "account", reference_from:"contacts"},
|
|
36
|
-
* {field_name: "website", reference_from:"accounts"},
|
|
37
|
-
* ]
|
|
38
|
-
* }
|
|
39
|
-
* 最终转换成的SteedosFieldFormulaParamTypeConfig为:
|
|
40
|
-
* {
|
|
41
|
-
* key: "account.website",
|
|
42
|
-
* value: "www.abc.com"
|
|
43
|
-
* }
|
|
44
|
-
*/
|
|
45
|
-
export type SteedosFormulaParamTypeConfig = {
|
|
46
|
-
key: string,
|
|
47
|
-
path?: any,
|
|
48
|
-
value: any
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* 公式中的{}括起来的单个变量
|
|
53
|
-
* 比如contacts对象中有公式{account.website}
|
|
54
|
-
* 则解析为:
|
|
55
|
-
* {
|
|
56
|
-
* key: "account.website",
|
|
57
|
-
* paths: [
|
|
58
|
-
* {field_name: "account", reference_from:"contacts"},
|
|
59
|
-
* {field_name: "website", reference_from:"accounts"},
|
|
60
|
-
* ]
|
|
61
|
-
* }
|
|
62
|
-
*/
|
|
63
|
-
export type SteedosFormulaVarTypeConfig = {
|
|
64
|
-
key: string,
|
|
65
|
-
paths?: Array<SteedosFormulaVarPathTypeConfig>,
|
|
66
|
-
is_user_var?: boolean,
|
|
67
|
-
is_simple_var?: boolean //当不传入objectApiName时变量上设置该属性表示一个普通的变量,此时paths为空
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export type SteedosFieldFormulaTypeConfig = {
|
|
71
|
-
_id: string, //低代码值为${objectConfig.name}.${fieldConfig.name},零代码为数据库中的_id值
|
|
72
|
-
object_name: string,
|
|
73
|
-
field_name: string,
|
|
74
|
-
data_type: string,
|
|
75
|
-
formula_blank_value: SteedosFormulaBlankValue,
|
|
76
|
-
formula: string,
|
|
77
|
-
quotes: Array<SteedosFieldFormulaQuoteTypeConfig>,
|
|
78
|
-
vars: Array<SteedosFormulaVarTypeConfig>
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 获取对象在哪些字段公式中被引用时的返回结果
|
|
83
|
-
* ownConfigs为引用关系为当前对象上的自身引用自身(即引用关系is_own为true)
|
|
84
|
-
* otherConfigs为引用关系中排除ownConfigs后的其他引用关系(包括当前对象上is_own为false的引用关系)
|
|
85
|
-
* allConfigs = ownConfigs + otherConfigs
|
|
86
|
-
*/
|
|
87
|
-
export type SteedosQuotedByFieldFormulasTypeConfig = {
|
|
88
|
-
ownConfigs: Array<SteedosFieldFormulaTypeConfig>,
|
|
89
|
-
otherConfigs: Array<SteedosFieldFormulaTypeConfig>,
|
|
90
|
-
allConfigs: Array<SteedosFieldFormulaTypeConfig>
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* 空白字段处理,只在公式类型返回值为number和currency类型时有效,默认为zeroes
|
|
95
|
-
*/
|
|
96
|
-
export enum SteedosFormulaBlankValue {
|
|
97
|
-
zeroes = "zeroes",
|
|
98
|
-
blanks = "blanks"
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* 内核函数runFormula的额外参数
|
|
103
|
-
*/
|
|
104
|
-
export type SteedosFormulaOptions = {
|
|
105
|
-
returnType?: string,
|
|
106
|
-
blankValue?: SteedosFormulaBlankValue,
|
|
107
|
-
}
|