@steedos/objectql 2.1.57 → 2.1.61

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 (59) hide show
  1. package/lib/dynamic-load/preload_data.d.ts +3 -0
  2. package/lib/dynamic-load/preload_data.js +158 -1
  3. package/lib/dynamic-load/preload_data.js.map +1 -1
  4. package/lib/dynamic-load/restrictionRules.d.ts +1 -0
  5. package/lib/dynamic-load/restrictionRules.js +42 -0
  6. package/lib/dynamic-load/restrictionRules.js.map +1 -0
  7. package/lib/dynamic-load/shareRules.d.ts +1 -0
  8. package/lib/dynamic-load/shareRules.js +42 -0
  9. package/lib/dynamic-load/shareRules.js.map +1 -0
  10. package/lib/index.d.ts +3 -0
  11. package/lib/index.js +3 -0
  12. package/lib/index.js.map +1 -1
  13. package/lib/metadata-register/_base.d.ts +3 -1
  14. package/lib/metadata-register/_base.js +16 -5
  15. package/lib/metadata-register/_base.js.map +1 -1
  16. package/lib/metadata-register/permissionFields.d.ts +7 -0
  17. package/lib/metadata-register/permissionFields.js +18 -0
  18. package/lib/metadata-register/permissionFields.js.map +1 -0
  19. package/lib/metadata-register/restrictionRules.d.ts +7 -0
  20. package/lib/metadata-register/restrictionRules.js +18 -0
  21. package/lib/metadata-register/restrictionRules.js.map +1 -0
  22. package/lib/metadata-register/shareRules.d.ts +7 -0
  23. package/lib/metadata-register/shareRules.js +18 -0
  24. package/lib/metadata-register/shareRules.js.map +1 -0
  25. package/lib/types/field_permission.d.ts +4 -0
  26. package/lib/types/field_permission.js +50 -0
  27. package/lib/types/field_permission.js.map +1 -0
  28. package/lib/types/object.d.ts +0 -4
  29. package/lib/types/object.js +268 -261
  30. package/lib/types/object.js.map +1 -1
  31. package/lib/types/object_dynamic_load.js +13 -4
  32. package/lib/types/object_dynamic_load.js.map +1 -1
  33. package/lib/types/restrictionRule.d.ts +13 -0
  34. package/lib/types/restrictionRule.js +75 -0
  35. package/lib/types/restrictionRule.js.map +1 -0
  36. package/lib/types/shareRule.d.ts +13 -0
  37. package/lib/types/shareRule.js +75 -0
  38. package/lib/types/shareRule.js.map +1 -0
  39. package/lib/util/field.js +4 -4
  40. package/lib/util/field.js.map +1 -1
  41. package/lib/util/function_expression.d.ts +1 -1
  42. package/lib/util/function_expression.js +3 -2
  43. package/lib/util/function_expression.js.map +1 -1
  44. package/package.json +8 -8
  45. package/src/dynamic-load/preload_data.ts +44 -0
  46. package/src/dynamic-load/restrictionRules.ts +19 -0
  47. package/src/dynamic-load/shareRules.ts +19 -0
  48. package/src/index.ts +4 -1
  49. package/src/metadata-register/_base.ts +14 -3
  50. package/src/metadata-register/permissionFields.ts +13 -0
  51. package/src/metadata-register/restrictionRules.ts +12 -0
  52. package/src/metadata-register/shareRules.ts +13 -0
  53. package/src/types/field_permission.ts +26 -0
  54. package/src/types/object.ts +89 -68
  55. package/src/types/object_dynamic_load.ts +4 -1
  56. package/src/types/restrictionRule.ts +57 -0
  57. package/src/types/shareRule.ts +57 -0
  58. package/src/util/field.ts +4 -4
  59. package/src/util/function_expression.ts +2 -2
@@ -0,0 +1,57 @@
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
+ }
package/src/util/field.ts CHANGED
@@ -71,13 +71,13 @@ export const getFieldsByType = (doc, type: string, dataType?: string) => {
71
71
  fields.push({ name: 'formula_blank_value', required: false });
72
72
  fields.push({ name: 'summary_object', required: true });
73
73
  fields.push({ name: 'summary_type', required: true });
74
- fields.push({ name: 'summary_filters', required: true });
74
+ fields.push({ name: 'summary_filters', required: false });
75
75
  if (doc.summary_type != 'count') {
76
76
  fields.push({ name: 'summary_field', required: true });
77
77
  }
78
- fields.push({ name: 'data_type', required: true });
79
- fields.push({ name: 'precision', required: false });
80
- fields.push({ name: 'scale', required: false });
78
+ fields.push({ name: 'data_type', required: false });
79
+ fields.push({ name: 'precision', required: true });
80
+ fields.push({ name: 'scale', required: true });
81
81
  fields.push({ name: 'filters' });
82
82
  fields.push({ name: 'filters.$' });
83
83
  fields.push({ name: 'filters.$.field' });
@@ -39,7 +39,7 @@ export const isExpression = function (func) {
39
39
  return false;
40
40
  };
41
41
 
42
- export const parseSingleExpression = function (func, formData, dataPath, global) {
42
+ export const parseSingleExpression = function (func, formData, dataPath, global, userSession = {}) {
43
43
  var error, funcBody, parent, parentPath, str;
44
44
 
45
45
  if (formData === void 0) {
@@ -49,7 +49,7 @@ export const parseSingleExpression = function (func, formData, dataPath, global)
49
49
  parent = getValueByPath(formData, parentPath) || {};
50
50
  if (typeof func === 'string') {
51
51
  funcBody = func.substring(2, func.length - 2);
52
- str = '\n return ' + funcBody.replace(/\bformData\b/g, JSON.stringify(formData).replace(/\bglobal\b/g, globalTag)).replace(/\bglobal\b/g, JSON.stringify(global)).replace(new RegExp('\\b' + globalTag + '\\b', 'g'), 'global').replace(/rootValue/g, JSON.stringify(parent));
52
+ str = `\n var $user=${JSON.stringify(userSession)}; return ` + funcBody.replace(/\bformData\b/g, JSON.stringify(formData).replace(/\bglobal\b/g, globalTag)).replace(/\bglobal\b/g, JSON.stringify(global)).replace(new RegExp('\\b' + globalTag + '\\b', 'g'), 'global').replace(/rootValue/g, JSON.stringify(parent));
53
53
  try {
54
54
  return Function(str)();
55
55
  } catch (_error) {