@steedos/standard-object-database 2.7.1-beta.3 → 2.7.1-beta.30
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/main/default/objectTranslations/object_functions.en/object_functions.en.objectTranslation.yml +47 -0
- package/main/default/objectTranslations/object_functions.zh-CN/object_functions.zh-CN.objectTranslation.yml +44 -0
- package/main/default/objectTranslations/objects.en/objects.en.objectTranslation.yml +4 -0
- package/main/default/objectTranslations/objects.zh-CN/objects.zh-CN.objectTranslation.yml +4 -0
- package/main/default/objects/datasources/fields/driver.field.yml +1 -0
- package/main/default/objects/datasources/fields/is_enable.field.yml +1 -0
- package/main/default/objects/datasources/fields/label.field.yml +2 -0
- package/main/default/objects/datasources/fields/name.field.yml +1 -0
- package/main/default/objects/object_fields/fields/auto_fill_mapping.$.from.field.yml +8 -6
- package/main/default/objects/object_fields/fields/auto_fill_mapping.$.to.field.yml +15 -0
- package/main/default/objects/object_fields/fields/auto_fill_mapping.field.yml +1 -1
- package/main/default/objects/object_fields/fields/is_name.field.yml +1 -0
- package/main/default/objects/object_fields/fields/sortable.field.yml +1 -1
- package/main/default/objects/object_fields/fields/summary_filters.field.yml +1 -1
- package/main/default/objects/object_functions/buttons/standard_new.button.js +16 -0
- package/main/default/objects/object_functions/fields/_name.field.yml +7 -0
- package/main/default/objects/object_functions/fields/description.field.yml +5 -0
- package/main/default/objects/object_functions/fields/isEnabled.field.yml +5 -0
- package/main/default/objects/object_functions/fields/is_rest.field.yml +5 -0
- package/main/default/objects/object_functions/fields/is_system.field.yml +7 -0
- package/main/default/objects/object_functions/fields/name.field.yml +8 -0
- package/main/default/objects/object_functions/fields/objectApiName.field.yml +7 -0
- package/main/default/objects/object_functions/fields/record_permissions.field.yml +4 -0
- package/main/default/objects/object_functions/fields/script.field.yml +24 -0
- package/main/default/objects/object_functions/listviews/all.listview.yml +9 -0
- package/main/default/objects/object_functions/listviews/customize.listview.yml +13 -0
- package/main/default/objects/object_functions/object_functions.object.yml +8 -0
- package/main/default/objects/object_functions/permissions/admin.permission.yml +7 -0
- package/main/default/objects/object_functions/permissions/user.permission.yml +7 -0
- package/main/default/objects/object_listviews/buttons/customize.button.js +1 -1
- package/main/default/objects/object_triggers/fields/_name.field.yml +1 -0
- package/main/default/objects/object_triggers/fields/isEnabled.field.yml +1 -0
- package/main/default/objects/object_triggers/fields/listenTo.field.yml +1 -0
- package/main/default/objects/object_triggers/fields/name.field.yml +1 -0
- package/main/default/objects/object_triggers/fields/when.field.yml +1 -0
- package/main/default/objects/object_validation_rules/fields/active.field.yml +1 -0
- package/main/default/objects/object_validation_rules/fields/description.field.yml +1 -0
- package/main/default/objects/object_validation_rules/fields/name.field.yml +2 -0
- package/main/default/objects/object_validation_rules/fields/object_name.field.yml +1 -0
- package/main/default/objects/object_webhooks/fields/event.field.yml +2 -1
- package/main/default/objects/object_webhooks/fields/execute_when.field.yml +2 -1
- package/main/default/objects/object_webhooks/fields/fields.field.yml +1 -0
- package/main/default/objects/object_webhooks/fields/name.field.yml +3 -1
- package/main/default/objects/object_webhooks/fields/object_name.field.yml +3 -1
- package/main/default/objects/object_webhooks/fields/payload_url.field.yml +3 -1
- package/main/default/objects/objects/fields/description.field.yml +1 -0
- package/main/default/objects/objects/fields/enable_form_tabs.field.yml +7 -0
- package/main/default/objects/objects/fields/in_development.field.yml +2 -0
- package/main/default/objects/objects/fields/is_customize.field.yml +1 -0
- package/main/default/objects/objects/fields/is_system.field.yml +1 -0
- package/main/default/objects/objects/listviews/customize.listview.yml +1 -1
- package/main/default/pages/design_field_layout.page.amis.json +285 -215
- package/main/default/pages/object_detail.page.amis.json +13 -0
- package/main/default/pages/object_fields_form.page.amis.json +38 -10
- package/main/default/pages/object_webhooks_form.page.amis.json +1 -1
- package/main/default/server/object_fields.object.js +4 -2
- package/main/default/server/objects.core.js +4 -0
- package/main/default/server/objects.object.js +2 -1
- package/main/default/services/object_webhooks.service.js +12 -7
- package/main/default/services/suggestions.service.js +92 -0
- package/main/default/triggers/datasources.trigger.js +9 -2
- package/main/default/triggers/object_actions.trigger.js +6 -4
- package/main/default/triggers/object_fields.trigger.js +3 -25
- package/main/default/triggers/object_functions.trigger.js +104 -0
- package/main/default/triggers/object_triggers.trigger.js +2 -2
- package/main/default/triggers/object_validation_rules.trigger.js +4 -5
- package/main/default/triggers/objects.trigger.js +20 -3
- package/package.json +6 -5
- package/package.service.js +3 -2
|
@@ -176,6 +176,19 @@
|
|
|
176
176
|
"perPage": 20
|
|
177
177
|
}
|
|
178
178
|
]
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"title": "${'objects_amis_functions' | t}",
|
|
182
|
+
"body": [
|
|
183
|
+
{
|
|
184
|
+
"type": "steedos-object-related-listview",
|
|
185
|
+
"objectApiName": "objects",
|
|
186
|
+
"recordId": "${recordId}",
|
|
187
|
+
"relatedObjectApiName": "object_functions",
|
|
188
|
+
"relatedKey": "objectApiName",
|
|
189
|
+
"perPage": 20
|
|
190
|
+
}
|
|
191
|
+
]
|
|
179
192
|
}
|
|
180
193
|
],
|
|
181
194
|
"id": "u:6a3b45d7adcf",
|
|
@@ -143,15 +143,18 @@
|
|
|
143
143
|
"amis": {
|
|
144
144
|
"onEvent": {
|
|
145
145
|
"change": {
|
|
146
|
-
"actions": [
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
"
|
|
150
|
-
"
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
146
|
+
"actions": [
|
|
147
|
+
{
|
|
148
|
+
"actionType": "setValue",
|
|
149
|
+
"args": {
|
|
150
|
+
"value": {
|
|
151
|
+
"defaultValue": null,
|
|
152
|
+
"sortable": "${ARRAYSOME(allowSort, item => item === event.data.value)}"
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
"componentId": "steedos_object_fields_form"
|
|
156
|
+
}
|
|
157
|
+
]
|
|
155
158
|
}
|
|
156
159
|
},
|
|
157
160
|
"disabledOn": "${is_system == true}",
|
|
@@ -197,8 +200,33 @@
|
|
|
197
200
|
"tabsMode": "line"
|
|
198
201
|
}],
|
|
199
202
|
"data": {
|
|
200
|
-
"context": {}
|
|
203
|
+
"context": {},
|
|
204
|
+
"allowSort": [
|
|
205
|
+
"text",
|
|
206
|
+
"select",
|
|
207
|
+
"date",
|
|
208
|
+
"datetime",
|
|
209
|
+
"time",
|
|
210
|
+
"number",
|
|
211
|
+
"currency",
|
|
212
|
+
"percent",
|
|
213
|
+
"autoumber",
|
|
214
|
+
"summary",
|
|
215
|
+
"formula"
|
|
216
|
+
]
|
|
217
|
+
},
|
|
218
|
+
"onEvent": {
|
|
219
|
+
"init": {
|
|
220
|
+
"weight": 0,
|
|
221
|
+
"actions": [
|
|
222
|
+
{
|
|
223
|
+
"actionType": "custom",
|
|
224
|
+
"script": "//初始化时给外层dialog加上类名,使过滤组件popover正常显示\n$('.steedos-object-fields-form-page').closest('.amis-dialog-widget.antd-Modal').addClass('steedos-overflow-visible-dialog');"
|
|
225
|
+
}
|
|
226
|
+
]
|
|
227
|
+
}
|
|
201
228
|
},
|
|
202
229
|
"name": "object_fields_form",
|
|
230
|
+
"className": "steedos-object-fields-form-page",
|
|
203
231
|
"id": "steedos_object_fields_service"
|
|
204
232
|
}
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"method": "get",
|
|
17
17
|
"url": "/service/api/amis-metadata-objects/objects/${object_name}/fields/options",
|
|
18
18
|
"cache": 30000,
|
|
19
|
-
"adaptor": "const visibleOnVariables = SteedosUI.getFormulaVariables(payload.data.options);\n const defaultValueVariables = [visibleOnVariables[1]];\n const variables = [];\n const varItem = {\n label: '对象字段',\n children: _.map(payload.data.options, (item)=>{\n return {\n label: item.label,\n value: item.value\n }\n })\n };\n variables.push(varItem);\n payload.data={label:
|
|
19
|
+
"adaptor": "const field = context.uiSchema.fields.condition; const visibleOnVariables = SteedosUI.getFormulaVariables(payload.data.options);\n const defaultValueVariables = [visibleOnVariables[1]];\n const variables = [];\n const varItem = {\n label: '对象字段',\n children: _.map(payload.data.options, (item)=>{\n return {\n label: item.label,\n value: item.value\n }\n })\n };\n variables.push(varItem);\n payload.data={label: field.label, type:'input-formula', name: 'condition', variables: variables, labelRemark: field.inlineHelpText, description: field.description } \n return payload;",
|
|
20
20
|
"trackExpression": "${object_name}",
|
|
21
21
|
"sendOn": "${object_name}"
|
|
22
22
|
}
|
|
@@ -299,8 +299,10 @@ function allowChangeObject(){
|
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
function checkNameField(nameField){
|
|
302
|
-
if(["text", "textarea", "autonumber", "date", "datetime", "time", "formula"].indexOf(nameField.type) < 0){
|
|
303
|
-
throw new Error("
|
|
302
|
+
if(["text", "textarea", "autonumber", "date", "datetime", "time", "formula", "lookup", "master_detail"].indexOf(nameField.type) < 0){
|
|
303
|
+
throw new Error("只有文本、长文本、自动编号、日期、日期时间、时间、公式、相关表这些类型的字段可以被设置为名称字段");
|
|
304
|
+
} else if(nameField.type == "lookup" && nameField.multiple) {
|
|
305
|
+
throw new Error("多选的相关表字段不可以被设置为名称字段");
|
|
304
306
|
}
|
|
305
307
|
}
|
|
306
308
|
|
|
@@ -349,6 +349,10 @@ function reloadObject(changeLog){
|
|
|
349
349
|
//获取到最新的对象
|
|
350
350
|
const object = register.getOriginalObjectConfig(objectName);
|
|
351
351
|
|
|
352
|
+
if (object.name) {
|
|
353
|
+
delete object.extend; // 因为objects.addConfig中会将extend赋值给name导致metadataApiName错误,故这里提前删除。
|
|
354
|
+
}
|
|
355
|
+
|
|
352
356
|
let _mf = _.max(_.values(object.fields), function (field) { return field.sort_no; });
|
|
353
357
|
if(_mf && object.name){
|
|
354
358
|
object.fields_serial_number = _mf.sort_no + 10;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @Author: baozhoutao@steedos.com
|
|
3
3
|
* @Date: 2024-04-23 14:35:03
|
|
4
4
|
* @LastEditors: baozhoutao@steedos.com
|
|
5
|
-
* @LastEditTime: 2024-
|
|
5
|
+
* @LastEditTime: 2024-05-06 11:45:46
|
|
6
6
|
* @Description:
|
|
7
7
|
*/
|
|
8
8
|
|
|
@@ -22,22 +22,28 @@ module.exports = {
|
|
|
22
22
|
},
|
|
23
23
|
events: {
|
|
24
24
|
"*.inserted": async function(ctx){
|
|
25
|
-
// TODO 校验是否是objectql的记录新增事件. 使用@objectApiName + .inserted 后,与ctx.eventName对比,看是否相同
|
|
26
25
|
const { objectApiName, id, spaceId, userId } = ctx.params;
|
|
26
|
+
if(ctx.eventName != `@${objectApiName}.inserted`){
|
|
27
|
+
return
|
|
28
|
+
}
|
|
27
29
|
if(objectApiName && id && spaceId){
|
|
28
30
|
await this.addQueue(ctx, objectApiName, "create", id, spaceId, userId)
|
|
29
31
|
}
|
|
30
32
|
},
|
|
31
33
|
"*.updated": async function(ctx){
|
|
32
|
-
// TODO 校验是否是objectql的记录新增事件. 使用@objectApiName + .updated 后,与ctx.eventName对比,看是否相同
|
|
33
34
|
const { objectApiName, id, spaceId, userId, previousDoc } = ctx.params;
|
|
35
|
+
if(ctx.eventName != `@${objectApiName}.updated`){
|
|
36
|
+
return
|
|
37
|
+
}
|
|
34
38
|
if(objectApiName && id && spaceId){
|
|
35
39
|
await this.addQueue(ctx, objectApiName, "update", id, spaceId, userId, previousDoc)
|
|
36
40
|
}
|
|
37
41
|
},
|
|
38
42
|
"*.deleted": async function(ctx){
|
|
39
|
-
// TODO 校验是否是objectql的记录新增事件. 使用@objectApiName + .deleted 后,与ctx.eventName对比,看是否相同
|
|
40
43
|
const { objectApiName, id, spaceId, userId, previousDoc } = ctx.params;
|
|
44
|
+
if(ctx.eventName != `@${objectApiName}.deleted`){
|
|
45
|
+
return
|
|
46
|
+
}
|
|
41
47
|
if(objectApiName && id){
|
|
42
48
|
await this.addQueue(ctx, objectApiName, "delete", id, spaceId, userId, previousDoc)
|
|
43
49
|
}
|
|
@@ -50,7 +56,6 @@ module.exports = {
|
|
|
50
56
|
const { url, data } = ctx.params
|
|
51
57
|
const result = await axios.post(url, data);
|
|
52
58
|
ctx.locals.job.updateProgress(100)
|
|
53
|
-
console.log('====>send', url, data.doc?.name)
|
|
54
59
|
return result.data;
|
|
55
60
|
}
|
|
56
61
|
}
|
|
@@ -71,14 +76,14 @@ module.exports = {
|
|
|
71
76
|
const userSession = await ctx.call('@steedos/service-accounts.getUserSession', {userId, spaceId})
|
|
72
77
|
if(userSession){
|
|
73
78
|
sender = {
|
|
74
|
-
|
|
79
|
+
_id: userSession.userId,
|
|
75
80
|
username: userSession.username,
|
|
76
81
|
name: userSession.name,
|
|
77
82
|
email: userSession.email
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
space = {
|
|
81
|
-
|
|
86
|
+
_id: userSession.space._id,
|
|
82
87
|
name: userSession.space.name
|
|
83
88
|
}
|
|
84
89
|
}
|
|
@@ -129,6 +129,98 @@ module.exports = {
|
|
|
129
129
|
${servicesTypes}
|
|
130
130
|
`
|
|
131
131
|
}
|
|
132
|
+
},
|
|
133
|
+
functionTSExtraLib: {
|
|
134
|
+
rest: {
|
|
135
|
+
method: "GET",
|
|
136
|
+
path: "/function.d.ts",
|
|
137
|
+
},
|
|
138
|
+
async handler(ctx) {
|
|
139
|
+
let objectsTypes = 'declare const objects: {';
|
|
140
|
+
_.each(global.objects, (v, k)=>{
|
|
141
|
+
objectsTypes = `${objectsTypes} ${k}: SteedosObjectType;`
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
objectsTypes = objectsTypes + '}'
|
|
145
|
+
|
|
146
|
+
return `
|
|
147
|
+
|
|
148
|
+
declare var global = {_: any, moment: any, validator: any, filters: any};
|
|
149
|
+
|
|
150
|
+
declare type Params = {
|
|
151
|
+
userId: SteedosIDType;
|
|
152
|
+
spaceId?: SteedosIDType;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
declare type CTXType = {
|
|
156
|
+
input: any;
|
|
157
|
+
params: Params;
|
|
158
|
+
broker: {
|
|
159
|
+
meta: any;
|
|
160
|
+
call: any;
|
|
161
|
+
mcall: any;
|
|
162
|
+
emit: any;
|
|
163
|
+
broadcast: any;
|
|
164
|
+
broadcastLocal: any;
|
|
165
|
+
namespace: string;
|
|
166
|
+
nodeID: string;
|
|
167
|
+
instanceID: string;
|
|
168
|
+
logger: any;
|
|
169
|
+
metadata: any;
|
|
170
|
+
},
|
|
171
|
+
getObject(objectName: string): SteedosObjectType;
|
|
172
|
+
getUser(userId: string, spaceId: string): Promise<SteedosUserSession>;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
declare var ctx: CTXType;
|
|
176
|
+
|
|
177
|
+
declare type SteedosQueryFilters = any;
|
|
178
|
+
declare type SteedosIDType = number | string;
|
|
179
|
+
declare type SteedosQueryOptions = {
|
|
180
|
+
fields?: Array<string> | string;
|
|
181
|
+
readonly filters?: SteedosQueryFilters;
|
|
182
|
+
readonly top?: number;
|
|
183
|
+
readonly skip?: number;
|
|
184
|
+
readonly sort?: string;
|
|
185
|
+
};
|
|
186
|
+
declare type SteedosUserSession = {
|
|
187
|
+
userId: SteedosIDType;
|
|
188
|
+
spaceId?: string;
|
|
189
|
+
name: string;
|
|
190
|
+
username?: string;
|
|
191
|
+
mobile?: string;
|
|
192
|
+
email?: string;
|
|
193
|
+
utcOffset?: number;
|
|
194
|
+
locale?: string;
|
|
195
|
+
roles?: string[];
|
|
196
|
+
space?: any;
|
|
197
|
+
spaces?: any;
|
|
198
|
+
company?: any;
|
|
199
|
+
companies?: any;
|
|
200
|
+
organization?: any;
|
|
201
|
+
organizations?: any;
|
|
202
|
+
permission_shares?: any;
|
|
203
|
+
company_id?: string;
|
|
204
|
+
company_ids?: string[];
|
|
205
|
+
is_space_admin?: boolean;
|
|
206
|
+
steedos_id?: string;
|
|
207
|
+
};
|
|
208
|
+
declare class SteedosObjectType {
|
|
209
|
+
find(query: SteedosQueryOptions, userSession?: SteedosUserSession): Promise<any>;
|
|
210
|
+
findOne(id: SteedosIDType, query: SteedosQueryOptions, userSession?: SteedosUserSession): Promise<any>;
|
|
211
|
+
insert(doc: Dictionary<any>, userSession?: SteedosUserSession): Promise<any>;
|
|
212
|
+
update(id: SteedosIDType, doc: Dictionary<any>, userSession?: SteedosUserSession): Promise<any>;
|
|
213
|
+
delete(id: SteedosIDType, userSession?: SteedosUserSession): Promise<any>;
|
|
214
|
+
directFind(query: SteedosQueryOptions, userSession?: SteedosUserSession): Promise<any>;
|
|
215
|
+
directInsert(doc: Dictionary<any>, userSession?: SteedosUserSession): Promise<any>;
|
|
216
|
+
directUpdate(id: SteedosIDType, doc: Dictionary<any>, userSession?: SteedosUserSession): Promise<any>;
|
|
217
|
+
directDelete(id: SteedosIDType, userSession?: SteedosUserSession): Promise<any>;
|
|
218
|
+
count(query: SteedosQueryOptions, userSession?: SteedosUserSession): Promise<any>;
|
|
219
|
+
_makeNewID(): Promise<any>;
|
|
220
|
+
}
|
|
221
|
+
${objectsTypes}
|
|
222
|
+
`
|
|
223
|
+
}
|
|
132
224
|
}
|
|
133
225
|
},
|
|
134
226
|
|
|
@@ -7,6 +7,7 @@ const InternalData = require('@steedos/standard-objects').internalData;
|
|
|
7
7
|
const objectql = require('@steedos/objectql');
|
|
8
8
|
const auth = require('@steedos/auth');
|
|
9
9
|
const _ = require('underscore');
|
|
10
|
+
const clone = require('clone');
|
|
10
11
|
//由于新版lookup 组件限制。需编写trigger处理在只读页面不显示已选中项的问题
|
|
11
12
|
//由于lookup组件强依赖_id 字段,所以必须返回_id
|
|
12
13
|
|
|
@@ -35,14 +36,15 @@ module.exports = {
|
|
|
35
36
|
dataList.push({_id: 'meteor', name: 'meteor', label: TAPi18n.__(`objects_field_datasource_meteor`, {}, lng), ...BASERECORD})
|
|
36
37
|
}
|
|
37
38
|
if (!_.isEmpty(dataList)) {
|
|
39
|
+
const cloneValues = clone(this.data.values, false);
|
|
38
40
|
dataList.forEach((doc) => {
|
|
39
41
|
if (!_.find(this.data.values, (value) => {
|
|
40
42
|
return value.name === doc.name
|
|
41
43
|
})) {
|
|
42
|
-
|
|
44
|
+
cloneValues.push(doc);
|
|
43
45
|
}
|
|
44
46
|
})
|
|
45
|
-
const records = objectql.getSteedosSchema().metadataDriver.find(
|
|
47
|
+
const records = objectql.getSteedosSchema().metadataDriver.find(cloneValues, this.query, spaceId);
|
|
46
48
|
if (records.length > 0) {
|
|
47
49
|
this.data.values = records;
|
|
48
50
|
} else {
|
|
@@ -75,6 +77,11 @@ module.exports = {
|
|
|
75
77
|
}
|
|
76
78
|
}
|
|
77
79
|
|
|
80
|
+
if(_.isEmpty(this.data.values)){
|
|
81
|
+
const records = await objectql.getObject('datasources').find({filters: ['name', '=', this.id]})
|
|
82
|
+
this.data.values = records.length > 0 ? records[0]: null
|
|
83
|
+
}
|
|
84
|
+
|
|
78
85
|
}
|
|
79
86
|
}
|
|
80
87
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* @Author: sunhaolin@hotoa.com
|
|
3
3
|
* @Date: 2022-05-28 11:07:57
|
|
4
|
-
* @LastEditors:
|
|
5
|
-
* @LastEditTime: 2024-
|
|
4
|
+
* @LastEditors: 孙浩林 sunhaolin@steedos.com
|
|
5
|
+
* @LastEditTime: 2024-05-11 13:57:23
|
|
6
6
|
* @Description:
|
|
7
7
|
*/
|
|
8
8
|
const InternalData = require('@steedos/standard-objects').internalData;
|
|
9
9
|
const objectql = require('@steedos/objectql');
|
|
10
10
|
const auth = require("@steedos/auth");
|
|
11
|
+
const clone = require('clone');
|
|
11
12
|
const sleep = async (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
12
13
|
module.exports = {
|
|
13
14
|
beforeInsert: async function(){
|
|
@@ -35,14 +36,15 @@ module.exports = {
|
|
|
35
36
|
if(objectName){
|
|
36
37
|
let dataList = await InternalData.getObjectActions(objectName, this.userId);
|
|
37
38
|
if (!_.isEmpty(dataList)) {
|
|
39
|
+
const cloneValues = clone(this.data.values, false);
|
|
38
40
|
dataList.forEach((doc) => {
|
|
39
41
|
if (!_.find(this.data.values, (value) => {
|
|
40
42
|
return value.name === doc.name
|
|
41
43
|
})) {
|
|
42
|
-
|
|
44
|
+
cloneValues.push(Object.assign({_id: `${objectName}.${doc.name}`}, doc));
|
|
43
45
|
}
|
|
44
46
|
})
|
|
45
|
-
const records = objectql.getSteedosSchema().metadataDriver.find(
|
|
47
|
+
const records = objectql.getSteedosSchema().metadataDriver.find(cloneValues, this.query, spaceId);
|
|
46
48
|
if (records.length > 0) {
|
|
47
49
|
this.data.values = records;
|
|
48
50
|
} else {
|
|
@@ -231,15 +231,16 @@ module.exports = {
|
|
|
231
231
|
if(objectName){
|
|
232
232
|
let fields = await InternalData.getObjectFields(objectName, this.userId, filters.name ? true : false);
|
|
233
233
|
if(fields){
|
|
234
|
+
const cloneValues = clone(this.data.values, false);
|
|
234
235
|
_.each(fields, (field)=>{
|
|
235
236
|
if(!_.find(this.data.values, (item)=>{
|
|
236
237
|
return item.object == field.object && item.name == field.name
|
|
237
238
|
})){
|
|
238
|
-
|
|
239
|
+
cloneValues.push(Object.assign({_id: `${objectName}.${field.name}`}, field))
|
|
239
240
|
}
|
|
240
241
|
})
|
|
241
242
|
// this.data.values = this.data.values.concat(fields)
|
|
242
|
-
this.data.values = objectql.getSteedosSchema().metadataDriver.find(
|
|
243
|
+
this.data.values = objectql.getSteedosSchema().metadataDriver.find(cloneValues, this.query, this.spaceId);
|
|
243
244
|
}
|
|
244
245
|
}
|
|
245
246
|
|
|
@@ -282,29 +283,6 @@ module.exports = {
|
|
|
282
283
|
}
|
|
283
284
|
|
|
284
285
|
|
|
285
|
-
},
|
|
286
|
-
beforeAggregate: async function(){
|
|
287
|
-
const { query } = this;
|
|
288
|
-
if(query.fields && _.isArray(query.fields) && !_.include(query.fields, 'object')){
|
|
289
|
-
query.fields.push('object')
|
|
290
|
-
}
|
|
291
|
-
},
|
|
292
|
-
afterAggregate: async function(){
|
|
293
|
-
let filters = InternalData.parserFilters(this.query.filters);
|
|
294
|
-
let objectName = filters.object;
|
|
295
|
-
if(!objectName && filters._id && filters._id.indexOf(".") > -1){
|
|
296
|
-
objectName = filters._id.split('.')[0];
|
|
297
|
-
}
|
|
298
|
-
if(objectName){
|
|
299
|
-
let fields = await InternalData.getObjectFields(objectName, this.userId, true);
|
|
300
|
-
if(fields){
|
|
301
|
-
_.each(fields, (field)=>{
|
|
302
|
-
this.data.values.push(Object.assign({_id: `${objectName}.${field.name}`}, field))
|
|
303
|
-
})
|
|
304
|
-
// this.data.values = this.data.values.concat(fields)
|
|
305
|
-
this.data.values = objectql.getSteedosSchema().metadataDriver.find(this.data.values, this.query, this.spaceId);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
286
|
},
|
|
309
287
|
afterCount: async function(){
|
|
310
288
|
let result = await objectql.getObject('object_fields').find(this.query, await auth.getSessionByUserId(this.userId, this.spaceId))
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: 孙浩林 sunhaolin@steedos.com
|
|
3
|
+
* @Date: 2024-05-13 14:20:37
|
|
4
|
+
* @LastEditors: 孙浩林 sunhaolin@steedos.com
|
|
5
|
+
* @LastEditTime: 2024-05-18 14:12:38
|
|
6
|
+
* @FilePath: /steedos-platform-2.3/services/standard-object-database/main/default/triggers/object_functions.trigger.js
|
|
7
|
+
* @Description:
|
|
8
|
+
*/
|
|
9
|
+
const _ = require('lodash');
|
|
10
|
+
const objectql = require('@steedos/objectql');
|
|
11
|
+
const auth = require('@steedos/auth');
|
|
12
|
+
const validator = require('validator');
|
|
13
|
+
const PERMISSIONS = {
|
|
14
|
+
allowEdit: false,
|
|
15
|
+
allowDelete: false,
|
|
16
|
+
allowRead: true,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const BASERECORD = {
|
|
20
|
+
is_system: true,
|
|
21
|
+
record_permissions: PERMISSIONS
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const APINAMEM_MULTI_MSG = '函数Api Name不能重复';
|
|
25
|
+
const METADATA_CACHER_SERVICE_NAME = 'metadata-cachers-service'
|
|
26
|
+
|
|
27
|
+
const getSourceFunctions = async () => {
|
|
28
|
+
const fDocs = await broker.call(`${METADATA_CACHER_SERVICE_NAME}.find`, { metadataName: 'object_functions' });
|
|
29
|
+
const data = _.map(_.filter(fDocs, (item)=>{
|
|
30
|
+
return !item._id || item._id == item.name
|
|
31
|
+
}), (item) => {
|
|
32
|
+
return {
|
|
33
|
+
...item,
|
|
34
|
+
_id: item.name,
|
|
35
|
+
...BASERECORD
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function checkVariableName(variableName) {
|
|
42
|
+
if (variableName.length > 50) {
|
|
43
|
+
throw new Error("名称长度不能大于50个字符");
|
|
44
|
+
}
|
|
45
|
+
var reg = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
46
|
+
if (reg.test(variableName)) {
|
|
47
|
+
var keywords = ['break', 'case', 'catch', 'continue', 'debugger', 'default', 'delete', 'do', 'else', 'finally', 'for', 'function', 'if', 'in', 'instanceof', 'new', 'return', 'switch', 'this', 'throw', 'try', 'typeof', 'var', 'void', 'while', 'with', 'true', 'false', 'null', 'undefined', 'NaN', 'Infinity'];
|
|
48
|
+
if (keywords.indexOf(variableName) === -1) {
|
|
49
|
+
return true;
|
|
50
|
+
} else {
|
|
51
|
+
throw new Error("名称不能包含关键字");
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
throw new Error("名称只能包含字母、数字,必须以字母开头");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = {
|
|
59
|
+
beforeFind: async function () {
|
|
60
|
+
delete this.query.fields;
|
|
61
|
+
},
|
|
62
|
+
afterFind: async function () {
|
|
63
|
+
let spaceId = this.spaceId;
|
|
64
|
+
let sourceData = await getSourceFunctions();
|
|
65
|
+
this.data.values = this.data.values.concat(sourceData);
|
|
66
|
+
this.data.values = objectql.getSteedosSchema().metadataDriver.find(this.data.values, this.query, spaceId);
|
|
67
|
+
},
|
|
68
|
+
afterCount: async function () {
|
|
69
|
+
let spaceId = this.spaceId;
|
|
70
|
+
this.data.values = this.data.values + objectql.getSteedosSchema().metadataDriver.count(await getSourceFunctions(), this.query, spaceId);
|
|
71
|
+
},
|
|
72
|
+
afterFindOne: async function () {
|
|
73
|
+
let spaceId = this.spaceId;
|
|
74
|
+
if (_.isEmpty(this.data.values)) {
|
|
75
|
+
const records = objectql.getSteedosSchema().metadataDriver.find(await getSourceFunctions(), { filters: ['_id', '=', this.id] }, spaceId);
|
|
76
|
+
if (records.length > 0) {
|
|
77
|
+
this.data.values = records[0]
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
beforeInsert: async function () {
|
|
82
|
+
if (validator.toBoolean(process.env.STEEDOS_TENANT_ENABLE_SAAS || 'false', true) == true) {
|
|
83
|
+
throw new Error('No permission')
|
|
84
|
+
}
|
|
85
|
+
const doc = this.doc;
|
|
86
|
+
checkVariableName(doc._name)
|
|
87
|
+
const count = await objectql.getObject(this.object_name).count({ filters: [['_name', '=', doc._name], ['objectApiName', '=', doc.objectApiName]] })
|
|
88
|
+
if (count > 0) {
|
|
89
|
+
throw new Error(APINAMEM_MULTI_MSG)
|
|
90
|
+
}
|
|
91
|
+
doc.name = `${doc.objectApiName}_${doc._name}`
|
|
92
|
+
},
|
|
93
|
+
beforeUpdate: async function () {
|
|
94
|
+
const doc = this.doc;
|
|
95
|
+
if (doc._name) {
|
|
96
|
+
checkVariableName(doc._name)
|
|
97
|
+
}
|
|
98
|
+
const count = await objectql.getObject(this.object_name).count({ filters: [['_name', '=', doc._name], ['objectApiName', '=', doc.objectApiName], ['_id', '!=', this.id]] })
|
|
99
|
+
if (count > 0) {
|
|
100
|
+
throw new Error(APINAMEM_MULTI_MSG)
|
|
101
|
+
}
|
|
102
|
+
doc.name = `${doc.objectApiName}_${doc._name}`
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* @Author: sunhaolin@hotoa.com
|
|
3
3
|
* @Date: 2021-06-03 15:11:52
|
|
4
|
-
* @LastEditors:
|
|
5
|
-
* @LastEditTime:
|
|
4
|
+
* @LastEditors: 孙浩林 sunhaolin@steedos.com
|
|
5
|
+
* @LastEditTime: 2024-05-18 14:06:18
|
|
6
6
|
* @Description:
|
|
7
7
|
*/
|
|
8
8
|
const Cache = require('@steedos/cachers');
|
|
@@ -8,26 +8,25 @@ const util = require('@steedos/standard-objects').util;
|
|
|
8
8
|
const objectql = require("@steedos/objectql");
|
|
9
9
|
const register = require('@steedos/metadata-registrar')
|
|
10
10
|
const auth = require('@steedos/auth');
|
|
11
|
+
const clone = require('clone');
|
|
11
12
|
|
|
12
13
|
module.exports = {
|
|
13
14
|
beforeFind: async function(){
|
|
14
15
|
delete this.query.fields;
|
|
15
16
|
},
|
|
16
|
-
beforeAggregate: async function(){
|
|
17
|
-
delete this.query.fields;
|
|
18
|
-
},
|
|
19
17
|
afterFind: async function(){
|
|
20
18
|
const { spaceId } = this;
|
|
21
19
|
let dataList = await register.getAllObjectValidationRules();
|
|
22
20
|
if (!_.isEmpty(dataList)) {
|
|
21
|
+
const cloneValues = clone(this.data.values, false);
|
|
23
22
|
dataList.forEach((doc) => {
|
|
24
23
|
if (!_.find(this.data.values, (value) => {
|
|
25
24
|
return value.name === doc.name
|
|
26
25
|
})) {
|
|
27
|
-
|
|
26
|
+
cloneValues.push(doc);
|
|
28
27
|
}
|
|
29
28
|
})
|
|
30
|
-
const records = objectql.getSteedosSchema().metadataDriver.find(
|
|
29
|
+
const records = objectql.getSteedosSchema().metadataDriver.find(cloneValues, this.query, spaceId);
|
|
31
30
|
if (records.length > 0) {
|
|
32
31
|
this.data.values = records;
|
|
33
32
|
} else {
|
|
@@ -2,7 +2,7 @@ const InternalData = require('@steedos/standard-objects').internalData;
|
|
|
2
2
|
const _ = require('underscore');
|
|
3
3
|
const objectql = require('@steedos/objectql');
|
|
4
4
|
const objectTree = require('../server/objects.tree.js');
|
|
5
|
-
|
|
5
|
+
const clone = require('clone');
|
|
6
6
|
const sleep = async (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
7
7
|
|
|
8
8
|
module.exports = {
|
|
@@ -18,13 +18,25 @@ module.exports = {
|
|
|
18
18
|
let userId = this.userId
|
|
19
19
|
let spaceId = this.spaceId;
|
|
20
20
|
|
|
21
|
+
let filters = InternalData.parserFilters(this.query.filters);
|
|
22
|
+
|
|
21
23
|
_.each(this.data.values, (item)=>{
|
|
22
24
|
item.is_customize = true
|
|
23
25
|
})
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
let cloneValues = clone(this.data.values, false);
|
|
28
|
+
|
|
29
|
+
if(filters.is_customize){
|
|
30
|
+
const dbObjects = await objectql.getObject('objects').directFind({space: spaceId});
|
|
31
|
+
_.each(dbObjects, (item)=>{
|
|
32
|
+
item.is_customize = true
|
|
33
|
+
})
|
|
34
|
+
cloneValues = cloneValues.concat(dbObjects);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
cloneValues = cloneValues.concat(await InternalData.getObjects(userId));
|
|
26
38
|
|
|
27
|
-
this.data.values = objectql.getSteedosSchema().metadataDriver.find(
|
|
39
|
+
this.data.values = objectql.getSteedosSchema().metadataDriver.find(cloneValues, this.query, spaceId);
|
|
28
40
|
|
|
29
41
|
_.each(this.data.values, function(value){
|
|
30
42
|
if(value){
|
|
@@ -39,6 +51,11 @@ module.exports = {
|
|
|
39
51
|
afterCount: async function(){
|
|
40
52
|
let userId = this.userId
|
|
41
53
|
let spaceId = this.spaceId;
|
|
54
|
+
let filters = InternalData.parserFilters(this.query.filters);
|
|
55
|
+
if(filters.is_customize){
|
|
56
|
+
const dbObjects = await objectql.getObject('objects').directFind({space: spaceId});
|
|
57
|
+
return this.data.values = dbObjects.length;
|
|
58
|
+
}
|
|
42
59
|
this.data.values = this.data.values + objectql.getSteedosSchema().metadataDriver.count(await InternalData.getObjects(userId), this.query, spaceId);
|
|
43
60
|
},
|
|
44
61
|
afterFindOne: async function(){
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/standard-object-database",
|
|
3
|
-
"version": "2.7.1-beta.
|
|
3
|
+
"version": "2.7.1-beta.30",
|
|
4
4
|
"main": "package.service.js",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -12,13 +12,14 @@
|
|
|
12
12
|
"description": "steedos package",
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@steedos-widgets/amis-lib": "^1.0.22",
|
|
15
|
-
"@steedos/metadata-core": "2.7.1-beta.
|
|
16
|
-
"@steedos/service-object-mixin": "2.7.1-beta.
|
|
17
|
-
"@steedos/standard-objects": "2.7.1-beta.
|
|
15
|
+
"@steedos/metadata-core": "2.7.1-beta.30",
|
|
16
|
+
"@steedos/service-object-mixin": "2.7.1-beta.30",
|
|
17
|
+
"@steedos/standard-objects": "2.7.1-beta.30",
|
|
18
18
|
"amis-formula": "~6.3.0",
|
|
19
|
+
"clone": "^2.1.2",
|
|
19
20
|
"moleculer-bullmq": "3.0.0"
|
|
20
21
|
},
|
|
21
22
|
"repository": {},
|
|
22
23
|
"license": "MIT",
|
|
23
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "232d409d0485f7d42821690909ff199050548e74"
|
|
24
25
|
}
|
package/package.service.js
CHANGED
|
@@ -166,8 +166,9 @@ module.exports = {
|
|
|
166
166
|
const dbRecord = await object.directFind({filters: ['_id','=',id]});
|
|
167
167
|
if(dbRecord.length === 0){
|
|
168
168
|
// const newId = await object._makeNewID();
|
|
169
|
-
const
|
|
170
|
-
|
|
169
|
+
const curentObject = await this.getObject(name);
|
|
170
|
+
const curentObjectConfig = await curentObject.toConfig();
|
|
171
|
+
let field_groups = curentObjectConfig.field_groups || null;
|
|
171
172
|
|
|
172
173
|
const now = new Date();
|
|
173
174
|
await object.directInsert(Object.assign({}, data, {
|