@steedos/standard-object-database 2.7.1-beta.2 → 2.7.1-beta.20

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.
Files changed (78) hide show
  1. package/main/default/objectTranslations/object_functions.en/object_functions.en.objectTranslation.yml +60 -0
  2. package/main/default/objectTranslations/object_functions.zh-CN/object_functions.zh-CN.objectTranslation.yml +57 -0
  3. package/main/default/objectTranslations/object_webhooks.en/object_webhooks.en.objectTranslation.yml +46 -0
  4. package/main/default/objectTranslations/object_webhooks.zh-CN/object_webhooks.zh-CN.objectTranslation.yml +48 -0
  5. package/main/default/objectTranslations/objects.en/objects.en.objectTranslation.yml +4 -0
  6. package/main/default/objectTranslations/objects.zh-CN/objects.zh-CN.objectTranslation.yml +4 -0
  7. package/main/default/objects/datasources/fields/driver.field.yml +1 -0
  8. package/main/default/objects/datasources/fields/is_enable.field.yml +1 -0
  9. package/main/default/objects/datasources/fields/label.field.yml +2 -0
  10. package/main/default/objects/datasources/fields/name.field.yml +1 -0
  11. package/main/default/objects/object_fields/fields/auto_fill_mapping.$.from.field.yml +8 -6
  12. package/main/default/objects/object_fields/fields/auto_fill_mapping.$.to.field.yml +13 -0
  13. package/main/default/objects/object_fields/fields/auto_fill_mapping.field.yml +1 -1
  14. package/main/default/objects/object_fields/fields/is_name.field.yml +1 -0
  15. package/main/default/objects/object_fields/fields/sortable.field.yml +0 -1
  16. package/main/default/objects/object_fields/fields/summary_filters.field.yml +1 -1
  17. package/main/default/objects/object_functions/buttons/standard_new.button.js +16 -0
  18. package/main/default/objects/object_functions/fields/_name.field.yml +7 -0
  19. package/main/default/objects/object_functions/fields/description.field.yml +5 -0
  20. package/main/default/objects/object_functions/fields/isEnabled.field.yml +5 -0
  21. package/main/default/objects/object_functions/fields/is_rest.field.yml +5 -0
  22. package/main/default/objects/object_functions/fields/is_system.field.yml +7 -0
  23. package/main/default/objects/object_functions/fields/name.field.yml +8 -0
  24. package/main/default/objects/object_functions/fields/objectApiName.field.yml +7 -0
  25. package/main/default/objects/object_functions/fields/record_permissions.field.yml +4 -0
  26. package/main/default/objects/object_functions/fields/script.field.yml +24 -0
  27. package/main/default/objects/object_functions/listviews/all.listview.yml +9 -0
  28. package/main/default/objects/object_functions/listviews/customize.listview.yml +13 -0
  29. package/main/default/objects/object_functions/object_functions.object.yml +8 -0
  30. package/main/default/objects/object_functions/permissions/admin.permission.yml +7 -0
  31. package/main/default/objects/object_functions/permissions/user.permission.yml +7 -0
  32. package/main/default/objects/object_listviews/buttons/customize.button.js +1 -1
  33. package/main/default/objects/object_triggers/fields/_name.field.yml +1 -0
  34. package/main/default/objects/object_triggers/fields/isEnabled.field.yml +1 -0
  35. package/main/default/objects/object_triggers/fields/listenTo.field.yml +1 -0
  36. package/main/default/objects/object_triggers/fields/name.field.yml +1 -0
  37. package/main/default/objects/object_triggers/fields/when.field.yml +1 -0
  38. package/main/default/objects/object_validation_rules/fields/active.field.yml +1 -0
  39. package/main/default/objects/object_validation_rules/fields/description.field.yml +1 -0
  40. package/main/default/objects/object_validation_rules/fields/name.field.yml +2 -0
  41. package/main/default/objects/object_validation_rules/fields/object_name.field.yml +1 -0
  42. package/main/default/objects/object_webhooks/fields/active.field.yml +5 -0
  43. package/main/default/objects/object_webhooks/fields/condition.field.yml +6 -0
  44. package/main/default/objects/object_webhooks/fields/content_type.field.yml +5 -0
  45. package/main/default/objects/object_webhooks/fields/event.field.yml +16 -0
  46. package/main/default/objects/object_webhooks/fields/execute_when.field.yml +13 -0
  47. package/main/default/objects/object_webhooks/fields/fields.field.yml +28 -0
  48. package/main/default/objects/object_webhooks/fields/name.field.yml +7 -0
  49. package/main/default/objects/object_webhooks/fields/object_name.field.yml +10 -0
  50. package/main/default/objects/object_webhooks/fields/payload_url.field.yml +9 -0
  51. package/main/default/objects/object_webhooks/listviews/all.listview.yml +9 -0
  52. package/main/default/objects/object_webhooks/object_webhooks.object.yml +5 -0
  53. package/main/default/objects/object_webhooks/permissions/admin.permission.yml +7 -0
  54. package/main/default/objects/object_webhooks/permissions/user.permission.yml +7 -0
  55. package/main/default/objects/objects/fields/description.field.yml +1 -0
  56. package/main/default/objects/objects/fields/enable_form_tabs.field.yml +6 -0
  57. package/main/default/objects/objects/fields/in_development.field.yml +2 -0
  58. package/main/default/objects/objects/fields/is_customize.field.yml +1 -0
  59. package/main/default/objects/objects/fields/is_system.field.yml +1 -0
  60. package/main/default/objects/objects/listviews/customize.listview.yml +1 -1
  61. package/main/default/pages/design_field_layout.page.amis.json +285 -215
  62. package/main/default/pages/object_detail.page.amis.json +13 -0
  63. package/main/default/pages/object_fields_form.page.amis.json +38 -10
  64. package/main/default/pages/object_webhooks_form.page.amis.json +51 -0
  65. package/main/default/pages/object_webhooks_form.page.yml +12 -0
  66. package/main/default/server/object_fields.object.js +4 -2
  67. package/main/default/server/objects.object.js +2 -1
  68. package/main/default/services/object_webhooks.service.js +141 -0
  69. package/main/default/services/suggestions.service.js +92 -0
  70. package/main/default/triggers/datasources.trigger.js +9 -2
  71. package/main/default/triggers/object_actions.trigger.js +6 -4
  72. package/main/default/triggers/object_fields.trigger.js +3 -25
  73. package/main/default/triggers/object_functions.trigger.js +104 -0
  74. package/main/default/triggers/object_triggers.trigger.js +2 -2
  75. package/main/default/triggers/object_validation_rules.trigger.js +4 -5
  76. package/main/default/triggers/objects.trigger.js +20 -3
  77. package/package.json +8 -4
  78. 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
- "actionType": "setValue",
148
- "args": {
149
- "value": {
150
- "defaultValue": null
151
- }
152
- },
153
- "componentId": "steedos_object_fields_form"
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
  }
@@ -0,0 +1,51 @@
1
+ {
2
+ "type": "service",
3
+ "body": [{
4
+ "type": "steedos-object-form",
5
+ "label": "Object Webhook",
6
+ "objectApiName": "object_webhooks",
7
+ "recordId": "${recordId}",
8
+ "mode": "edit",
9
+ "layout": "horizontal",
10
+
11
+ "fieldsExtend": {
12
+ "condition": {
13
+ "amis": {
14
+ "type": "service",
15
+ "schemaApi": {
16
+ "method": "get",
17
+ "url": "/service/api/amis-metadata-objects/objects/${object_name}/fields/options",
18
+ "cache": 30000,
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
+ "trackExpression": "${object_name}",
21
+ "sendOn": "${object_name}"
22
+ }
23
+ }
24
+ },
25
+ "execute_when":{
26
+ "amis": {
27
+ "type": "radios",
28
+ "inline": false
29
+ }
30
+ },
31
+ "event": {
32
+ "amis":{
33
+ "type": "radios",
34
+ "inline": false
35
+ }
36
+ }
37
+ },
38
+ "form": {
39
+ "id": "steedos_object_webhooks_form"
40
+ },
41
+ "id": "u:e17c57cce896",
42
+ "tabsMode": "line"
43
+ }],
44
+ "data": {
45
+ "context": {},
46
+ "visibleOnVariables": "",
47
+ "defaultValueVariables": ""
48
+ },
49
+ "name": "object_webhooks_form",
50
+ "id": "steedos_object_webhooks_service"
51
+ }
@@ -0,0 +1,12 @@
1
+ name: object_webhooks_form
2
+ is_active: true
3
+ label: 对象字段表单
4
+ object_name: object_webhooks
5
+ pageAssignments:
6
+ - type: orgDefault
7
+ page: object_webhooks_form
8
+ desktop: true
9
+ mobile: true
10
+ render_engine: amis
11
+ type: form
12
+ widgets: []
@@ -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
 
@@ -315,7 +315,8 @@ let objectTriggers = {
315
315
  required: true,
316
316
  index: true,
317
317
  searchable: true,
318
- filterable: true
318
+ filterable: true,
319
+ sort_no: 10
319
320
  });
320
321
  // Creator.getCollection("object_fields").insert({
321
322
  // object: doc.name,
@@ -0,0 +1,141 @@
1
+ /*
2
+ * @Author: baozhoutao@steedos.com
3
+ * @Date: 2024-04-23 14:35:03
4
+ * @LastEditors: baozhoutao@steedos.com
5
+ * @LastEditTime: 2024-05-06 11:45:46
6
+ * @Description:
7
+ */
8
+
9
+ const BullMqMixin = require('moleculer-bullmq');
10
+ const axios = require('axios');
11
+ const { evaluate } = require("amis-formula")
12
+ const serviceObjectMixin = require('@steedos/service-object-mixin');
13
+
14
+ module.exports = {
15
+ name: "object_webhooks",
16
+ mixins: [serviceObjectMixin, BullMqMixin],
17
+ settings: {
18
+ bullmq: {
19
+ client: process.env.QUEUE_BACKEND,
20
+ worker: { concurrency: 50 }
21
+ }
22
+ },
23
+ events: {
24
+ "*.inserted": async function(ctx){
25
+ const { objectApiName, id, spaceId, userId } = ctx.params;
26
+ if(ctx.eventName != `@${objectApiName}.inserted`){
27
+ return
28
+ }
29
+ if(objectApiName && id && spaceId){
30
+ await this.addQueue(ctx, objectApiName, "create", id, spaceId, userId)
31
+ }
32
+ },
33
+ "*.updated": async function(ctx){
34
+ const { objectApiName, id, spaceId, userId, previousDoc } = ctx.params;
35
+ if(ctx.eventName != `@${objectApiName}.updated`){
36
+ return
37
+ }
38
+ if(objectApiName && id && spaceId){
39
+ await this.addQueue(ctx, objectApiName, "update", id, spaceId, userId, previousDoc)
40
+ }
41
+ },
42
+ "*.deleted": async function(ctx){
43
+ const { objectApiName, id, spaceId, userId, previousDoc } = ctx.params;
44
+ if(ctx.eventName != `@${objectApiName}.deleted`){
45
+ return
46
+ }
47
+ if(objectApiName && id){
48
+ await this.addQueue(ctx, objectApiName, "delete", id, spaceId, userId, previousDoc)
49
+ }
50
+ }
51
+ },
52
+ actions: {
53
+ send: {
54
+ queue: true,
55
+ async handler(ctx) {
56
+ const { url, data } = ctx.params
57
+ const result = await axios.post(url, data);
58
+ ctx.locals.job.updateProgress(100)
59
+ return result.data;
60
+ }
61
+ }
62
+ },
63
+ methods: {
64
+
65
+ async addQueue(ctx, objectName, actionName, recordId, spaceId, userId, previousDoc){
66
+ const hooks = await this.getObjectWebhooks(objectName, spaceId)
67
+ if(hooks.length === 0) return
68
+
69
+ let newDoc;
70
+ if(recordId && (actionName === 'update' || actionName === 'create')){
71
+ newDoc = await this.getObject(objectName).findOne(recordId)
72
+ }
73
+ let sender;
74
+ let space;
75
+ if(userId && spaceId){
76
+ const userSession = await ctx.call('@steedos/service-accounts.getUserSession', {userId, spaceId})
77
+ if(userSession){
78
+ sender = {
79
+ _id: userSession.userId,
80
+ username: userSession.username,
81
+ name: userSession.name,
82
+ email: userSession.email
83
+ }
84
+
85
+ space = {
86
+ _id: userSession.space._id,
87
+ name: userSession.space.name
88
+ }
89
+ }
90
+ }
91
+
92
+ for (const hook of hooks) {
93
+
94
+ if(hook.event != 'createAndUpdate' && hook.event != actionName){
95
+ continue;
96
+ }
97
+
98
+ if(hook.event == 'createAndUpdate' && actionName != 'create' && actionName != 'update'){
99
+ continue;
100
+ }
101
+
102
+ const { execute_when, condition } = hook;
103
+
104
+ if(hook.event == 'createAndUpdate' && actionName == 'create' && execute_when == 'trueOnChangeOnly'){
105
+ continue;
106
+ }
107
+
108
+ if(condition){
109
+
110
+ if(actionName == 'update' && execute_when === 'trueOnChangeOnly'){
111
+ const oldResult = evaluate(condition, previousDoc);
112
+ if(oldResult){
113
+ continue;
114
+ }
115
+ }
116
+
117
+ const result = evaluate(condition, newDoc);
118
+ if(!result){
119
+ continue;
120
+ }
121
+ }
122
+ let data = newDoc || previousDoc;
123
+ if(hook.fields && hook.fields.length > 0){
124
+ data = _.map(data, hook.fields)
125
+ }
126
+ await this.queue(ctx, 'object_webhooks', 'send', { url: hook.payload_url, data: {
127
+ action: actionName,
128
+ object_name: objectName,
129
+ doc: data,
130
+ sender: sender,
131
+ space: space
132
+ }, space: spaceId, user: userId }, { priority: 10 })
133
+ }
134
+ },
135
+ async getObjectWebhooks(objectName, spaceId){
136
+ const SERVICE_NAME = 'metadata-cachers-service'
137
+ const hooks = await global.broker.call(`${SERVICE_NAME}.find`, {metadataName: 'object_webhooks', filters: ['object_name', '=', objectName], spaceId});
138
+ return hooks;
139
+ }
140
+ }
141
+ }
@@ -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
- this.data.values.push(doc);
44
+ cloneValues.push(doc);
43
45
  }
44
46
  })
45
- const records = objectql.getSteedosSchema().metadataDriver.find(this.data.values, this.query, spaceId);
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: baozhoutao@steedos.com
5
- * @LastEditTime: 2024-03-20 16:00:17
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
- this.data.values.push(Object.assign({_id: `${objectName}.${doc.name}`}, doc));
44
+ cloneValues.push(Object.assign({_id: `${objectName}.${doc.name}`}, doc));
43
45
  }
44
46
  })
45
- const records = objectql.getSteedosSchema().metadataDriver.find(this.data.values, this.query, spaceId);
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
- this.data.values.push(Object.assign({_id: `${objectName}.${field.name}`}, field))
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(this.data.values, this.query, this.spaceId);
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: baozhoutao@steedos.com
5
- * @LastEditTime: 2023-05-15 09:26:19
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');