@steedos/standard-object-database 2.5.0-beta.15 → 2.5.0-beta.17

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.
@@ -6,7 +6,7 @@ hidden: true
6
6
  fields:
7
7
  _name:
8
8
  type: text
9
- label: Name
9
+ label: Api Name
10
10
  searchable: true
11
11
  index: true
12
12
  required: true
@@ -2,7 +2,7 @@
2
2
  * @Author: sunhaolin@hotoa.com
3
3
  * @Date: 2021-06-03 15:11:52
4
4
  * @LastEditors: baozhoutao@steedos.com
5
- * @LastEditTime: 2023-04-26 11:45:44
5
+ * @LastEditTime: 2023-04-27 17:41:52
6
6
  * @Description:
7
7
  */
8
8
  const Cache = require('@steedos/cachers');
@@ -20,15 +20,35 @@ const PERMISSIONS = {
20
20
  };
21
21
 
22
22
  const getSourceTriggers = async()=>{
23
- return _.map(Cache.getCacher('triggers').get('triggers'), (item)=>{
23
+ const data = _.map(_.filter(Cache.getCacher('triggers').get('triggers'), (item)=>{
24
+ return !item.metadata._id || item.metadata._id == item.metadata.name
25
+ }), (item)=>{
24
26
  return {
25
27
  ...item.metadata,
26
28
  _id: item.metadata.name,
27
29
  ...BASERECORD
28
30
  };
29
- })
31
+ });
32
+ return data;
30
33
  }
31
34
 
35
+ function checkVariableName(variableName){
36
+ if(variableName.length > 50){
37
+ throw new Error("名称长度不能大于50个字符");
38
+ }
39
+ var reg = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
40
+ if(reg.test(variableName)){
41
+ 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'];
42
+ if(keywords.indexOf(variableName) === -1){
43
+ return true;
44
+ } else {
45
+ throw new Error("名称不能包含关键字");
46
+ }
47
+ } else {
48
+ throw new Error("名称只能包含字母、数字,必须以字母开头");
49
+ }
50
+ }
51
+
32
52
  module.exports = {
33
53
  beforeFind: async function () {
34
54
  delete this.query.fields;
@@ -54,6 +74,7 @@ module.exports = {
54
74
  },
55
75
  beforeInsert: async function(){
56
76
  const doc = this.doc;
77
+ checkVariableName(doc._name)
57
78
  const count = await objectql.getObject('object_triggers').count({filters: [['_name', '=', doc._name], ['listenTo','=', doc.listenTo]]})
58
79
  if(count > 0){
59
80
  throw new Error('触发器名称不能重复')
@@ -61,6 +82,9 @@ module.exports = {
61
82
  },
62
83
  beforeUpdate: async function () {
63
84
  const doc = this.doc;
85
+ if(doc._name){
86
+ checkVariableName(doc._name)
87
+ }
64
88
  const count = await objectql.getObject('object_triggers').count({filters: [['_name', '=', doc._name], ['listenTo','=', doc.listenTo], ['_id', '!=', this.id]]})
65
89
  if(count > 0){
66
90
  throw new Error('触发器名称不能重复')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/standard-object-database",
3
- "version": "2.5.0-beta.15",
3
+ "version": "2.5.0-beta.17",
4
4
  "main": "package.service.js",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -15,5 +15,5 @@
15
15
  },
16
16
  "repository": {},
17
17
  "license": "MIT",
18
- "gitHead": "0b66b1a87086836a5c2bc45875207c29e057cff6"
18
+ "gitHead": "e91f79af27e59f8c53e5a947e3dfe5ef2e53dcda"
19
19
  }