@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.
Files changed (143) hide show
  1. package/lib/services/helpers/graphql/consts.d.ts +17 -0
  2. package/lib/services/helpers/graphql/consts.js +28 -0
  3. package/lib/services/helpers/graphql/consts.js.map +1 -0
  4. package/lib/services/helpers/graphql/getQueryFields.js +17 -2
  5. package/lib/services/helpers/graphql/getQueryFields.js.map +1 -1
  6. package/lib/services/helpers/graphql/index.d.ts +1 -1
  7. package/lib/services/helpers/graphql/index.js +31 -46
  8. package/lib/services/helpers/graphql/index.js.map +1 -1
  9. package/lib/util/index.js +7 -0
  10. package/lib/util/index.js.map +1 -1
  11. package/package.json +11 -12
  12. package/src/actions/field_updates.ts +0 -118
  13. package/src/actions/index.ts +0 -3
  14. package/src/actions/types/field_update_target.ts +0 -7
  15. package/src/actions/types/workflow_notification.ts +0 -9
  16. package/src/actions/types/workflow_rule.ts +0 -11
  17. package/src/actions/workflow_notifications.ts +0 -81
  18. package/src/actions/workflow_rule.ts +0 -136
  19. package/src/driver/driver.ts +0 -102
  20. package/src/driver/field-encrytion/index.ts +0 -8
  21. package/src/driver/field-encrytion/sharedconst.ts +0 -34
  22. package/src/driver/fieldDBType.ts +0 -14
  23. package/src/driver/format.ts +0 -36
  24. package/src/driver/index.ts +0 -20
  25. package/src/driver/metadata.ts +0 -226
  26. package/src/driver/meteorMongo.ts +0 -639
  27. package/src/driver/mongo.ts +0 -416
  28. package/src/driver/mysql.ts +0 -47
  29. package/src/driver/oracle.ts +0 -60
  30. package/src/driver/postgres.ts +0 -46
  31. package/src/driver/sqlite3.ts +0 -40
  32. package/src/driver/sqlserver.ts +0 -52
  33. package/src/dynamic-load/actions.ts +0 -146
  34. package/src/dynamic-load/approval_process.ts +0 -73
  35. package/src/dynamic-load/button.ts +0 -75
  36. package/src/dynamic-load/chart.ts +0 -22
  37. package/src/dynamic-load/client_script.ts +0 -65
  38. package/src/dynamic-load/field.ts +0 -77
  39. package/src/dynamic-load/flow_role.ts +0 -46
  40. package/src/dynamic-load/index.ts +0 -21
  41. package/src/dynamic-load/layout.ts +0 -53
  42. package/src/dynamic-load/listview.ts +0 -57
  43. package/src/dynamic-load/method.ts +0 -63
  44. package/src/dynamic-load/object_translations.ts +0 -61
  45. package/src/dynamic-load/originalObject.ts +0 -8
  46. package/src/dynamic-load/package.ts +0 -312
  47. package/src/dynamic-load/page.ts +0 -23
  48. package/src/dynamic-load/permission.ts +0 -71
  49. package/src/dynamic-load/permissionset.ts +0 -78
  50. package/src/dynamic-load/preload_data.ts +0 -104
  51. package/src/dynamic-load/profile.ts +0 -90
  52. package/src/dynamic-load/query.ts +0 -22
  53. package/src/dynamic-load/restrictionRules.ts +0 -23
  54. package/src/dynamic-load/role.ts +0 -46
  55. package/src/dynamic-load/shareRules.ts +0 -23
  56. package/src/dynamic-load/tab.ts +0 -17
  57. package/src/dynamic-load/tabs.ts +0 -13
  58. package/src/dynamic-load/translations.ts +0 -54
  59. package/src/dynamic-load/trigger.ts +0 -236
  60. package/src/dynamic-load/validation_rule.ts +0 -77
  61. package/src/dynamic-load/workflow.ts +0 -114
  62. package/src/errors/index.ts +0 -111
  63. package/src/formula/core.ts +0 -490
  64. package/src/formula/field_formula.ts +0 -107
  65. package/src/formula/index.ts +0 -81
  66. package/src/formula/params.ts +0 -197
  67. package/src/formula/recompute.ts +0 -65
  68. package/src/formula/simple_params.ts +0 -92
  69. package/src/formula/type.ts +0 -107
  70. package/src/formula/util.ts +0 -207
  71. package/src/index.ts +0 -24
  72. package/src/metadata-register/_base.ts +0 -85
  73. package/src/metadata-register/app.ts +0 -30
  74. package/src/metadata-register/chart.ts +0 -9
  75. package/src/metadata-register/index.ts +0 -123
  76. package/src/metadata-register/layout.ts +0 -38
  77. package/src/metadata-register/object.ts +0 -68
  78. package/src/metadata-register/page.ts +0 -9
  79. package/src/metadata-register/permissionFields.ts +0 -13
  80. package/src/metadata-register/permissionset.ts +0 -25
  81. package/src/metadata-register/process.ts +0 -16
  82. package/src/metadata-register/processTrigger.ts +0 -24
  83. package/src/metadata-register/profile.ts +0 -25
  84. package/src/metadata-register/query.ts +0 -9
  85. package/src/metadata-register/restrictionRules.ts +0 -12
  86. package/src/metadata-register/shareRules.ts +0 -13
  87. package/src/metadata-register/tab.ts +0 -9
  88. package/src/metadata-register/tabs.ts +0 -43
  89. package/src/services/datasourceServiceFactory.ts +0 -55
  90. package/src/services/helpers/graphql/getPrimaryFieldType.ts +0 -48
  91. package/src/services/helpers/graphql/getQueryFields.ts +0 -36
  92. package/src/services/helpers/graphql/index.ts +0 -681
  93. package/src/services/helpers/rest.ts +0 -57
  94. package/src/services/index.ts +0 -13
  95. package/src/services/objectService.ts +0 -846
  96. package/src/services/objectServiceDispatcher.ts +0 -209
  97. package/src/services/objectServiceFactory.ts +0 -29
  98. package/src/summary/core.ts +0 -263
  99. package/src/summary/field_summary.ts +0 -71
  100. package/src/summary/index.ts +0 -96
  101. package/src/summary/recompute.ts +0 -31
  102. package/src/summary/type.ts +0 -60
  103. package/src/ts-types/index.ts +0 -3
  104. package/src/ts-types/permissionset.ts +0 -8
  105. package/src/ts-types/profile.ts +0 -11
  106. package/src/ts-types/triggerActionParams.ts +0 -22
  107. package/src/typeorm/driver.ts +0 -379
  108. package/src/typeorm/index.ts +0 -3
  109. package/src/typeorm/util.ts +0 -147
  110. package/src/types/action.ts +0 -52
  111. package/src/types/app.ts +0 -280
  112. package/src/types/config.ts +0 -152
  113. package/src/types/connection.ts +0 -87
  114. package/src/types/dashboard.ts +0 -91
  115. package/src/types/datasource.ts +0 -570
  116. package/src/types/field.ts +0 -370
  117. package/src/types/field_permission.ts +0 -42
  118. package/src/types/field_types.ts +0 -1
  119. package/src/types/index.ts +0 -21
  120. package/src/types/list_view.ts +0 -56
  121. package/src/types/listeners.ts +0 -18
  122. package/src/types/object.ts +0 -2076
  123. package/src/types/object_dynamic_load.ts +0 -426
  124. package/src/types/object_events.ts +0 -43
  125. package/src/types/object_layouts.ts +0 -20
  126. package/src/types/object_permission.ts +0 -134
  127. package/src/types/query.ts +0 -28
  128. package/src/types/report.ts +0 -128
  129. package/src/types/restrictionRule.ts +0 -57
  130. package/src/types/schema.ts +0 -273
  131. package/src/types/shareRule.ts +0 -57
  132. package/src/types/trigger.ts +0 -88
  133. package/src/types/userSession.ts +0 -45
  134. package/src/types/validation_rules.ts +0 -29
  135. package/src/util/convert.ts +0 -131
  136. package/src/util/field.ts +0 -93
  137. package/src/util/function_expression.ts +0 -63
  138. package/src/util/index.ts +0 -1058
  139. package/src/util/locale.ts +0 -24
  140. package/src/util/permission_shares.ts +0 -25
  141. package/src/util/suffix.ts +0 -78
  142. package/src/util/transform.ts +0 -239
  143. package/src/validators/index.ts +0 -36
@@ -1,128 +0,0 @@
1
- import { JsonMap } from '@salesforce/ts-types';
2
- import { SteedosQueryFilters, addConfigFiles, addConfig, getConfigs, getConfig } from '.';
3
- import { SteedosDataSourceType } from '.';
4
-
5
- export const LOADED_REPORTS_CONFIGS: Array<SteedosReportTypeConfig> = [];
6
-
7
- export type SteedosReportTypeConfig = {
8
- _id: string,
9
- name: string,
10
- object_name: string,
11
- fields: Array<string>,
12
- filters: SteedosQueryFilters,
13
- description: string,
14
- mrt_file: string,
15
- graphql: string
16
- }
17
-
18
- export class SteedosReportType{
19
- private _datasource: SteedosDataSourceType;
20
- public get datasource(): SteedosDataSourceType {
21
- return this._datasource;
22
- }
23
-
24
- private __id: string;
25
- public get _id(): string {
26
- return this.__id;
27
- }
28
- public set _id(value: string) {
29
- this.__id = value;
30
- }
31
-
32
- private _name: string;
33
- public get name(): string {
34
- return this._name;
35
- }
36
- public set name(value: string) {
37
- this._name = value;
38
- }
39
-
40
- private _object_name: string;
41
- public get object_name(): string {
42
- return this._object_name;
43
- }
44
- public set object_name(value: string) {
45
- this._object_name = value;
46
- }
47
-
48
- private _fields: Array<string>;
49
- public get fields(): Array<string> {
50
- return this._fields;
51
- }
52
- public set fields(value: Array<string>) {
53
- this._fields = value;
54
- }
55
-
56
- private _filters: SteedosQueryFilters;
57
- public get filters(): SteedosQueryFilters {
58
- return this._filters;
59
- }
60
- public set filters(value: SteedosQueryFilters) {
61
- this._filters = value;
62
- }
63
-
64
- private _description: string;
65
- public get description(): string {
66
- return this._description;
67
- }
68
- public set description(value: string) {
69
- this._description = value;
70
- }
71
-
72
- private _mrt_file: string;
73
- public get mrt_file(): string {
74
- return this._mrt_file;
75
- }
76
- public set mrt_file(value: string) {
77
- this._mrt_file = value;
78
- }
79
-
80
- private _graphql: string;
81
- public get graphql(): string {
82
- return this._graphql;
83
- }
84
- public set graphql(value: string) {
85
- this._graphql = value;
86
- }
87
-
88
- constructor(config: SteedosReportTypeConfig, datasource: SteedosDataSourceType){
89
- this._datasource = datasource
90
- this._id = config._id
91
- this.name = config.name
92
- this.object_name = config.object_name
93
- this.fields = config.fields
94
- this.filters = config.filters
95
- this.description = config.description
96
- this.mrt_file = config.mrt_file
97
- this.graphql = config.graphql
98
- }
99
-
100
- toConfig(){
101
- let config:JsonMap = {}
102
- config._id = this._id
103
- config.name = this.name
104
- config.object_name = this.object_name
105
- config.fields = this.fields
106
- config.filters = this.filters
107
- config.description = this.description
108
- config.mrt_file = this.mrt_file
109
- config.graphql = this.graphql
110
- return config
111
- }
112
- }
113
-
114
- export function addReportConfigFiles(filePath: string){
115
- addConfigFiles('report', filePath);
116
- }
117
-
118
- export const addReportConfig = (appConfig: SteedosReportTypeConfig) => {
119
- addConfig('report', appConfig);
120
- }
121
-
122
- export const getReportConfigs = () => {
123
- return getConfigs('report')
124
- }
125
-
126
- export const getReportConfig = (_id: string):SteedosReportTypeConfig => {
127
- return getConfig('report', _id);
128
- }
@@ -1,57 +0,0 @@
1
- import { registerRestrictionRules } from '../metadata-register/restrictionRules';
2
- import { getSteedosSchema } from '../types'
3
- import * as _ from 'lodash'
4
- import { isExpression, parseSingleExpression } from '../util'
5
- import { formatFiltersToODataQuery } from "@steedos/filters";
6
-
7
- export type SteedosRestrictionRuleConfig = {
8
- _id: string,
9
- name: string,
10
- object_name: string,
11
- active: boolean,
12
- record_filter: string,
13
- entry_criteria: string,
14
- description: string
15
- }
16
-
17
- export class RestrictionRule {
18
- static async find(objectApiName) {
19
- const schema = getSteedosSchema();
20
- return await registerRestrictionRules.find(schema.broker, {
21
- pattern: `${objectApiName}.*`
22
- })
23
- }
24
- static async getUserObjectFilters(objectApiName, userSession: any) {
25
- const rules = await this.find(objectApiName);
26
- if (_.isEmpty(rules)) {
27
- return;
28
- }
29
- const rulesFilters = [];
30
- const globalData = { now: new Date() };
31
- _.each(rules, (rule) => {
32
- const { active, entry_criteria, record_filter } = rule.metadata;
33
- if (active) {
34
- if (_.isString(entry_criteria) && isExpression(entry_criteria.trim())) {
35
- try {
36
- const meetCriteria = parseSingleExpression(entry_criteria, {}, "#", globalData, userSession);
37
- if (_.isBoolean(meetCriteria) && meetCriteria) {
38
- if (_.isString(record_filter) && isExpression(record_filter.trim())) {
39
- try {
40
- const filters = parseSingleExpression(record_filter, {}, "#", globalData, userSession);
41
- if (filters && !_.isString(filters)) {
42
- rulesFilters.push(`(${formatFiltersToODataQuery(filters, userSession)})`)
43
- }
44
- } catch (error) {
45
- console.error(`RestrictionRule.getUserObjectFilters record_filter error`, objectApiName, record_filter, error.message);
46
- }
47
- }
48
- }
49
- } catch (error) {
50
- console.error(`RestrictionRule.getUserObjectFilters entry_criteria error`, objectApiName, entry_criteria, error.message);
51
- }
52
- }
53
- }
54
- })
55
- return rulesFilters;
56
- }
57
- }
@@ -1,273 +0,0 @@
1
- import { Dictionary } from '@salesforce/ts-types';
2
- import { SteedosDataSourceType, SteedosDataSourceTypeConfig } from ".";
3
- import { isMeteor, getSteedosConfig } from "../util";
4
- // import { isMeteor, getSteedosConfig, wrapAsync } from "../util";
5
- import _ = require("underscore");
6
- import { getFromContainer } from 'typeorm';
7
- // import { loadCoreValidators } from '../validators';
8
- // import { loadStandardBaseObjects } from './object_dynamic_load';
9
- // import { preloadDBObjectFields, preloadDBObjectButtons } from '../dynamic-load';
10
- import { MetadataRegister } from '../metadata-register';
11
- import { MetadataDriver } from '../driver/metadata';
12
-
13
-
14
- const defaultDatasourceName = 'default';
15
- const meteorDatasourceName = 'meteor';
16
-
17
- export type SteedosSchemaConfig = {
18
- datasources?: Dictionary<SteedosDataSourceTypeConfig>
19
- }
20
-
21
- export class SteedosSchema {
22
- private _datasources: Dictionary<SteedosDataSourceType> = {};
23
- private _objectsMap: Dictionary<{ datasourceName: string, filePath?: string }> = {};
24
- private _broker: any = null;
25
- private _metadataBroker: any = null;
26
- metadataRegister: MetadataRegister = null;
27
- metadataDriver = new MetadataDriver();
28
- public get metadataBroker(): any {
29
- return this._metadataBroker;
30
- }
31
- public set metadataBroker(value: any) {
32
- this._metadataBroker = value;
33
- this.metadataRegister = new MetadataRegister(this._metadataBroker);
34
- }
35
-
36
- public get broker(): any {
37
- return this._broker;
38
- }
39
- public set broker(value: any) {
40
- this._broker = value;
41
- }
42
-
43
- setObjectMap(objectName: string, options) {
44
- let objectMap = this.getObjectMap(objectName);
45
- if (objectMap) {
46
- if (objectName != 'base' && objectName != 'core' && objectMap.datasourceName != options.datasourceName) {
47
- console.log(`objectMap.datasourceName`, objectMap.datasourceName)
48
- console.log(`options.datasourceName`, options.datasourceName)
49
- throw new Error(`object name ${objectName} is unique, you can set table_name; see: https://developer.steedos.com/developer/object#%E5%AF%B9%E8%B1%A1%E5%90%8D-name`)
50
- }
51
- }
52
- this._objectsMap[objectName] = options
53
- }
54
-
55
- getObjectMap(objectName: string) {
56
- return this._objectsMap[objectName]
57
- }
58
-
59
- removeObjectMap(objectName: string) {
60
- delete this._objectsMap[objectName]
61
- }
62
-
63
- addDataSourceFromSteedosConfig() {
64
- let config: any = getSteedosConfig();
65
- if (config && config.datasources) {
66
- _.each(config.datasources, (datasource: any, datasource_name: string) => {
67
- datasource = _.extend(datasource, datasource.connection)
68
- if (datasource_name === 'default') {
69
- datasource.driver = "mongo"
70
- } else if (datasource_name === meteorDatasourceName) {
71
- if (!isMeteor()) {
72
- throw new Error('not find Meteor, can not set datasource name is meteor')
73
- }
74
- datasource.driver = "meteor-mongo"
75
- }
76
- this.addDataSource(datasource_name, datasource);
77
- })
78
- }
79
- this.addMeteorDatasource();
80
- }
81
-
82
- addMeteorDatasource(meteorDatasourceConfig?: SteedosDataSourceTypeConfig) {
83
- if (!meteorDatasourceConfig) {
84
- const steedosConfig = getSteedosConfig();
85
- meteorDatasourceConfig = steedosConfig?.datasources?.meteor;
86
- if (!meteorDatasourceConfig) {
87
- meteorDatasourceConfig = steedosConfig?.datasources?.default;
88
- }
89
- }
90
- if (meteorDatasourceConfig) {
91
- if (isMeteor() && !this.getDataSource(meteorDatasourceName)) {
92
- this.addDataSource(meteorDatasourceName, Object.assign({}, meteorDatasourceConfig, { driver: 'meteor-mongo' }));
93
- }
94
- }
95
-
96
- }
97
-
98
- constructor(config?: SteedosSchemaConfig) {
99
-
100
- // loadCoreValidators();
101
-
102
- // if (isMeteor())
103
- // loadStandardBaseObjects(); 此代码无需运行,meteor package load 已加载。
104
-
105
- if (config) {
106
- _.each(config.datasources, (datasourceConfig, datasource_name) => {
107
- this.addDataSource(datasource_name, datasourceConfig)
108
- })
109
- }
110
- this.addDataSourceFromSteedosConfig();
111
- }
112
-
113
- /**
114
- * 获取对象
115
- * @param {string} name : {datacource_name}.{object_name} ,如果没有${datacource_name}部分,则默认为default
116
- * @returns
117
- * @memberof SteedosSchema
118
- */
119
- getObject(name: string) {
120
- let datasource_name: string, object_name: string;
121
- if (!name) {
122
- throw new Error('Object name is required');
123
- }
124
- if (!name.split) {
125
- return;
126
- }
127
- let args = name.split('.')
128
- if (args.length == 1) {
129
- object_name = name
130
- let objectMap = this.getObjectMap(name);
131
- if(!objectMap){
132
- const services = require('../services');
133
- return services.getObjectDispatcher(object_name)
134
- }
135
- datasource_name = objectMap.datasourceName
136
- }
137
- if (args.length > 1) {
138
- datasource_name = args[0]
139
- object_name = _.rest(args).join('.')
140
- }
141
-
142
- let datasource = this.getDataSource(datasource_name)
143
-
144
- if (!datasource) {
145
- throw new Error(`not find datasource ${datasource_name}`);
146
- }
147
-
148
- return datasource.getObject(object_name)
149
- }
150
-
151
- getLocalObject(name: string) {
152
- let datasource_name: string, object_name: string;
153
- if (!name) {
154
- throw new Error('Object name is required');
155
- }
156
- let args = name.split('.')
157
- if (args.length == 1) {
158
- object_name = name
159
- let objectMap = this.getObjectMap(name);
160
- if (!objectMap) {
161
- throw new Error(`not find object ${name}`);
162
- }
163
- datasource_name = objectMap.datasourceName
164
- }
165
- if (args.length > 1) {
166
- datasource_name = args[0]
167
- object_name = _.rest(args).join('.')
168
- }
169
-
170
- let datasource = this.getDataSource(datasource_name)
171
-
172
- if (!datasource) {
173
- throw new Error(`not find datasource ${datasource_name}`);
174
- }
175
-
176
- return datasource.getLocalObject(object_name)
177
- }
178
-
179
- addDataSource(datasource_name: string, datasourceConfig: SteedosDataSourceTypeConfig, readd?: boolean) {
180
- if (this._datasources[datasource_name] && !readd) {
181
- throw new Error(`datasource ${datasource_name} existed`);
182
- }
183
- let datasource = new SteedosDataSourceType(datasource_name, datasourceConfig, this)
184
- this._datasources[datasource_name] = datasource
185
- return datasource;
186
- }
187
-
188
- async removeDataSource(datasource_name) {
189
- if (datasource_name != defaultDatasourceName && datasource_name != meteorDatasourceName) {
190
- let datasource = this._datasources[datasource_name];
191
- if (datasource) {
192
- delete this._datasources[datasource_name];
193
- let self = this;
194
- _.each(this._objectsMap, function (map, key) {
195
- if (map && map.datasourceName === datasource_name) {
196
- self.removeObjectMap(key);
197
- }
198
- })
199
- await datasource.close();
200
- }
201
- } else {
202
- throw new Error('Can not remove default datasource');
203
- }
204
- }
205
-
206
- /**
207
- * 转换对象的引用
208
- * 包括:app.objects 及 object 的字段有 reference_to 属性的
209
- * @private
210
- * @param {SteedosDataSourceType} datasource
211
- * @memberof SteedosSchema
212
- * TODO 处理reference_to 为function的情况
213
- */
214
- async transformReferenceOfObject(datasource: SteedosDataSourceType): Promise<void> {
215
- let objects = await datasource.getObjects();
216
- _.each(objects, (object, object_name) => {
217
- _.each(object.fields, (field, field_name) => {
218
- field.transformReferenceOfObject()
219
- })
220
- })
221
- }
222
-
223
- getDataSource(datasource_name: string = meteorDatasourceName) {
224
- return this._datasources[datasource_name]
225
- }
226
-
227
- getDataSources() {
228
- return this._datasources
229
- }
230
-
231
- async getAllObject() {
232
- let schemaObjects = [];
233
- const datasources = this.getDataSources();
234
- for (const name in datasources) {
235
- const datasource = datasources[name]
236
- const datasourceObjects = await datasource.getObjects();
237
- if (datasourceObjects && datasourceObjects.length > 0) {
238
- schemaObjects = schemaObjects.concat(datasourceObjects);
239
- }
240
- }
241
- return schemaObjects;
242
- // return await this.metadataBroker.call("objects.getAll");
243
- }
244
-
245
- async getAllRelationsInfo(){
246
- return await this.broker.call('objects.getAllRelationsInfo');
247
- }
248
- }
249
-
250
- export function getSteedosSchema(broker?: any, metadataBroker?: any): SteedosSchema {
251
- const schema = getFromContainer(SteedosSchema);
252
- if (broker) {
253
- schema.broker = broker;
254
- }
255
- if (metadataBroker || broker) {
256
- schema.metadataBroker = metadataBroker || broker;
257
- }
258
-
259
-
260
- // if(broker || metadataBroker){
261
- // loadStandardProfiles();
262
- // loadStandardPermissionsets();
263
- // }
264
-
265
- return schema;
266
- }
267
-
268
- export function getAllRelationsInfo(schema?: SteedosSchema) {
269
- return (schema ? schema : getSteedosSchema()).getAllRelationsInfo();
270
- }
271
-
272
- (function loadRun() {
273
- })();
@@ -1,57 +0,0 @@
1
- import { registerShareRules } from '../metadata-register/shareRules';
2
- import { getSteedosSchema } from '../types'
3
- import * as _ from 'lodash'
4
- import { isExpression, parseSingleExpression } from '../util'
5
- import { formatFiltersToODataQuery } from "@steedos/filters";
6
-
7
- export type SteedosShareRuleConfig = {
8
- _id: string,
9
- name: string,
10
- object_name: string,
11
- active: boolean,
12
- record_filter: string,
13
- entry_criteria: string,
14
- description: string
15
- }
16
-
17
- export class ShareRules {
18
- static async find(objectApiName) {
19
- const schema = getSteedosSchema();
20
- return await registerShareRules.find(schema.broker, {
21
- pattern: `${objectApiName}.*`
22
- })
23
- }
24
- static async getUserObjectFilters(objectApiName, userSession: any) {
25
- const rules = await this.find(objectApiName);
26
- if (_.isEmpty(rules)) {
27
- return;
28
- }
29
- const rulesFilters = [];
30
- const globalData = { now: new Date() };
31
- _.each(rules, (rule) => {
32
- const { active, entry_criteria, record_filter } = rule.metadata;
33
- if (active) {
34
- if (_.isString(entry_criteria) && isExpression(entry_criteria.trim())) {
35
- try {
36
- const meetCriteria = parseSingleExpression(entry_criteria, {}, "#", globalData, userSession);
37
- if (_.isBoolean(meetCriteria) && meetCriteria) {
38
- if (_.isString(record_filter) && isExpression(record_filter.trim())) {
39
- try {
40
- const filters = parseSingleExpression(record_filter, {}, "#", globalData, userSession);
41
- if (filters && !_.isString(filters)) {
42
- rulesFilters.push(`(${formatFiltersToODataQuery(filters, userSession)})`)
43
- }
44
- } catch (error) {
45
- console.error(`ShareRules.getUserObjectFilters record_filter error`, objectApiName, record_filter, error.message);
46
- }
47
- }
48
- }
49
- } catch (error) {
50
- console.error(`ShareRules.getUserObjectFilters entry_criteria error`, objectApiName, entry_criteria, error.message);
51
- }
52
- }
53
- }
54
- })
55
- return rulesFilters;
56
- }
57
- }
@@ -1,88 +0,0 @@
1
- import { Dictionary, JsonMap } from "@salesforce/ts-types";
2
-
3
- import _ = require('underscore')
4
- import { SteedosIDType } from "./field_types";
5
- import { SteedosQueryOptions } from ".";
6
-
7
- export type SteedosTriggerContextConfig = {
8
- id?: SteedosIDType,
9
- userId: SteedosIDType,
10
- spaceId?: SteedosIDType,
11
- doc?: JsonMap,
12
- previousDoc?: JsonMap, //仅afterUpdate, afterDelete时存在此属性
13
- query?: SteedosQueryOptions,
14
- data?: JsonMap //仅afterFind,afterCount时存在此属性
15
- objectName?: string
16
- }
17
-
18
- export type SteedosTriggerTypeConfig = {
19
- name: string,
20
- on?: string,
21
- when: string,
22
- todo: Function
23
- }
24
-
25
- const ENUM_ON = ["client","server"]
26
- const ENUM_WHEN = ['beforeFind','beforeInsert','beforeUpdate','beforeDelete','afterFind','afterCount','afterFindOne','afterInsert','afterUpdate','afterDelete', 'beforeAggregate', 'afterAggregate']
27
-
28
- export class SteedosTriggerType implements Dictionary {
29
- [key: string]: unknown;
30
- private _name: string;
31
-
32
- private _on: string;
33
-
34
- private _when: string;
35
-
36
- private _todo: Function;
37
-
38
- constructor(config: SteedosTriggerTypeConfig) {
39
- this.name = config.name
40
- this.on = config.on
41
- this.when = config.when
42
- this.todo = config.todo
43
- }
44
-
45
- toConfig(){
46
- let config = {
47
- on: this.on,
48
- when: this.when,
49
- todo: this.todo
50
- }
51
- return config;
52
- }
53
-
54
- public get name(): string {
55
- return this._name;
56
- }
57
- public set name(value: string) {
58
- if(!value)
59
- throw new Error("You must specify name for this trigger.")
60
- this._name = value;
61
- }
62
-
63
- public get on(): string {
64
- return this._on;
65
- }
66
- public set on(value: string) {
67
- if(!_.contains(ENUM_ON, value))
68
- throw new Error(`on must be a ${ENUM_ON.join(' or ')}.`)
69
- this._on = value;
70
- }
71
-
72
- public get when(): string {
73
- return this._when;
74
- }
75
-
76
- public set when(value: string) {
77
- if(!_.contains(ENUM_WHEN, value))
78
- throw new Error(`on must be a ${ENUM_WHEN.join(' or ')}.`)
79
- this._when = value;
80
- }
81
-
82
- public get todo(): Function {
83
- return this._todo;
84
- }
85
- public set todo(value: Function) {
86
- this._todo = value;
87
- }
88
- }
@@ -1,45 +0,0 @@
1
- import { SteedosIDType } from ".";
2
-
3
- export type SteedosUserSessionSpace = {
4
- _id: string,
5
- name: string
6
- }
7
-
8
- export type SteedosUserSessionCompany = {
9
- _id: string,
10
- name: string
11
- }
12
-
13
- export type SteedosUserSessionOrganization = {
14
- _id: string,
15
- name: string,
16
- fullname: string
17
- }
18
-
19
- export type SteedosUserSessionPermissionShares = {
20
- _id: string,
21
- object_name: string
22
- }
23
-
24
- export type SteedosUserSession = {
25
- userId: SteedosIDType,
26
- spaceId?: string,
27
- name: string,
28
- username?: string,
29
- mobile?: string,
30
- email?: string,
31
- utcOffset?: number,
32
- locale?: string,
33
- roles?: string[],
34
- space?: SteedosUserSessionSpace,
35
- spaces?: SteedosUserSessionSpace[],
36
- company?: SteedosUserSessionCompany,
37
- companies?: SteedosUserSessionCompany[],
38
- organization?: SteedosUserSessionOrganization,
39
- organizations?: SteedosUserSessionOrganization[],
40
- permission_shares?: SteedosUserSessionPermissionShares[],
41
- company_id?: string,
42
- company_ids?: string[],
43
- is_space_admin?: boolean,
44
- steedos_id?: string
45
- }
@@ -1,29 +0,0 @@
1
- /*
2
- * @Author: sunhaolin@hotoa.com
3
- * @Date: 2021-05-24 12:32:57
4
- * @Description:
5
- */
6
-
7
- import { computeFormula } from '../formula';
8
- import { SteedosTriggerContextConfig } from "./trigger";
9
- import { SteedosUserSession, getObject } from ".";
10
-
11
- export async function runValidationRules(method: string, context: SteedosTriggerContextConfig, objectName: string, userSession: SteedosUserSession) {
12
- if ((method === 'insert' || method === 'update') && userSession) {
13
- let spaceId = userSession.spaceId;
14
- let userId = userSession.userId + '';
15
- let doc = context.doc;
16
- let validationRules = await getObject('object_validation_rules').find({ filters: [['object_name', '=', objectName], ['active', '=', true]] });
17
- for (const vr of validationRules) {
18
- let result;
19
- try {
20
- result = await computeFormula(vr.error_condition_formula, objectName, doc, userId, spaceId);
21
- } catch (error) {
22
- throw new Error(`公式错误,请检查错误条件公式。${error.message.replace(/\:/g, ':')}`);
23
- }
24
- if (result) {
25
- throw new Error(vr.error_message);
26
- }
27
- }
28
- }
29
- }