@steedos/standard-object-database 2.7.1-beta.12 → 2.7.1-beta.13
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 +56 -0
- package/main/default/objectTranslations/object_functions.zh-CN/object_functions.zh-CN.objectTranslation.yml +53 -0
- 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/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/objects/listviews/customize.listview.yml +1 -1
- package/main/default/pages/object_detail.page.amis.json +13 -0
- package/main/default/triggers/object_functions.trigger.js +104 -0
- package/main/default/triggers/object_triggers.trigger.js +2 -2
- package/main/default/triggers/objects.trigger.js +20 -3
- package/package.json +5 -5
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
name: object_functions
|
|
2
|
+
label: Object Functions
|
|
3
|
+
description:
|
|
4
|
+
fields:
|
|
5
|
+
_name:
|
|
6
|
+
label: API Name
|
|
7
|
+
help: >-
|
|
8
|
+
Can only contain lowercase letters and numbers, must start with a letter,
|
|
9
|
+
cannot end with an underscore character or contain two consecutive
|
|
10
|
+
underscore characters
|
|
11
|
+
description:
|
|
12
|
+
is_rest:
|
|
13
|
+
label: Enable API
|
|
14
|
+
help:
|
|
15
|
+
description: allow the use of api interface access:/api/v1/:objectName/functions/:functionApiName
|
|
16
|
+
is_system:
|
|
17
|
+
label: System
|
|
18
|
+
help:
|
|
19
|
+
description:
|
|
20
|
+
isEnabled:
|
|
21
|
+
label: Enable
|
|
22
|
+
help:
|
|
23
|
+
description:
|
|
24
|
+
name:
|
|
25
|
+
label: Name
|
|
26
|
+
help:
|
|
27
|
+
description:
|
|
28
|
+
objectApiName:
|
|
29
|
+
label: Object
|
|
30
|
+
help:
|
|
31
|
+
description:
|
|
32
|
+
script:
|
|
33
|
+
label: Script
|
|
34
|
+
help:
|
|
35
|
+
description: |
|
|
36
|
+
async function run({
|
|
37
|
+
input,
|
|
38
|
+
params,
|
|
39
|
+
broker,
|
|
40
|
+
getObject,
|
|
41
|
+
getUser
|
|
42
|
+
} = ctx) {
|
|
43
|
+
// ...
|
|
44
|
+
}
|
|
45
|
+
type:
|
|
46
|
+
label: Type
|
|
47
|
+
help:
|
|
48
|
+
description:
|
|
49
|
+
options:
|
|
50
|
+
- label: "Script"
|
|
51
|
+
value: "script"
|
|
52
|
+
listviews:
|
|
53
|
+
all:
|
|
54
|
+
label: All
|
|
55
|
+
customize:
|
|
56
|
+
label: Customize
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
name: object_functions
|
|
2
|
+
label: 对象函数
|
|
3
|
+
description:
|
|
4
|
+
fields:
|
|
5
|
+
_name:
|
|
6
|
+
label: API 名称
|
|
7
|
+
help: API 名称只能包含小写字母、数字,必须以字母开头,不能以下划线字符结尾或包含两个连续的下划线字符
|
|
8
|
+
description:
|
|
9
|
+
is_rest:
|
|
10
|
+
label: 启用API
|
|
11
|
+
help:
|
|
12
|
+
description: 允许使用API接口访问:{POST} /api/v1/:objectName/functions/:functionApiName
|
|
13
|
+
is_system:
|
|
14
|
+
label: 系统
|
|
15
|
+
help:
|
|
16
|
+
description:
|
|
17
|
+
isEnabled:
|
|
18
|
+
label: 已启用
|
|
19
|
+
help:
|
|
20
|
+
description:
|
|
21
|
+
name:
|
|
22
|
+
label: 名称
|
|
23
|
+
help:
|
|
24
|
+
description:
|
|
25
|
+
objectApiName:
|
|
26
|
+
label: 所属对象
|
|
27
|
+
help:
|
|
28
|
+
description:
|
|
29
|
+
script:
|
|
30
|
+
label: 代码
|
|
31
|
+
help:
|
|
32
|
+
description: |
|
|
33
|
+
async function run({
|
|
34
|
+
input,
|
|
35
|
+
params,
|
|
36
|
+
broker,
|
|
37
|
+
getObject,
|
|
38
|
+
getUser
|
|
39
|
+
} = ctx) {
|
|
40
|
+
// ...
|
|
41
|
+
}
|
|
42
|
+
type:
|
|
43
|
+
label: 类型
|
|
44
|
+
help:
|
|
45
|
+
description:
|
|
46
|
+
options:
|
|
47
|
+
- label: "Script"
|
|
48
|
+
value: "script"
|
|
49
|
+
listviews:
|
|
50
|
+
all:
|
|
51
|
+
label: 所有
|
|
52
|
+
customize:
|
|
53
|
+
label: 自定义
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: 孙浩林 sunhaolin@steedos.com
|
|
3
|
+
* @Date: 2024-05-14 17:04:31
|
|
4
|
+
* @LastEditors: 孙浩林 sunhaolin@steedos.com
|
|
5
|
+
* @LastEditTime: 2024-05-14 17:04:36
|
|
6
|
+
* @FilePath: /steedos-platform-2.3/services/standard-object-database/main/default/objects/object_functions/buttons/standard_new.button.js
|
|
7
|
+
* @Description:
|
|
8
|
+
*/
|
|
9
|
+
module.exports = {
|
|
10
|
+
standard_newVisible: function (object_name, record_id, record_permissions, data) {
|
|
11
|
+
if(Meteor.settings.public.enable_saas){
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return Creator.baseObject.actions.standard_new.visible.apply(this, arguments);
|
|
15
|
+
},
|
|
16
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: script
|
|
2
|
+
label: Script
|
|
3
|
+
type: code
|
|
4
|
+
language: javascript
|
|
5
|
+
is_wide: true
|
|
6
|
+
required: true
|
|
7
|
+
defaultValue: |-
|
|
8
|
+
// global: {_:lodash, moment, validator, filters}
|
|
9
|
+
// objects
|
|
10
|
+
// ctx.input
|
|
11
|
+
editorDidMount: >-
|
|
12
|
+
if(window._registerCompletionItemProviderTrigger){
|
|
13
|
+
return ;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
window._registerCompletionItemProviderTrigger = true;
|
|
17
|
+
|
|
18
|
+
const result = Steedos.authRequest("/service/api/suggestions/trigger.d.ts",
|
|
19
|
+
{async: false});
|
|
20
|
+
|
|
21
|
+
monaco.languages.typescript.javascriptDefaults.addExtraLib(
|
|
22
|
+
result
|
|
23
|
+
);
|
|
24
|
+
sort_no: 150
|
|
@@ -26,6 +26,6 @@ customize:function (object_name, record_id, fields) {
|
|
|
26
26
|
},
|
|
27
27
|
customizeVisible:function(object_name, record_id, record_permissions, data){
|
|
28
28
|
var record = data && data.record;
|
|
29
|
-
return Creator.baseObject.actions.standard_new.visible() && record.is_system;
|
|
29
|
+
return Creator.baseObject.actions.standard_new.visible(object_name) && record.is_system;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -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",
|
|
@@ -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');
|
|
@@ -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.13",
|
|
4
4
|
"main": "package.service.js",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -12,14 +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.13",
|
|
16
|
+
"@steedos/service-object-mixin": "2.7.1-beta.13",
|
|
17
|
+
"@steedos/standard-objects": "2.7.1-beta.13",
|
|
18
18
|
"amis-formula": "~6.3.0",
|
|
19
19
|
"clone": "^2.1.2",
|
|
20
20
|
"moleculer-bullmq": "3.0.0"
|
|
21
21
|
},
|
|
22
22
|
"repository": {},
|
|
23
23
|
"license": "MIT",
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "4f545b49ccc0875abcfa08aef8af98e3c3418059"
|
|
25
25
|
}
|