@steedos/objectql 2.1.55 → 2.1.59
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/lib/dynamic-load/preload_data.d.ts +3 -0
- package/lib/dynamic-load/preload_data.js +158 -1
- package/lib/dynamic-load/preload_data.js.map +1 -1
- package/lib/dynamic-load/restrictionRules.d.ts +1 -0
- package/lib/dynamic-load/restrictionRules.js +42 -0
- package/lib/dynamic-load/restrictionRules.js.map +1 -0
- package/lib/dynamic-load/shareRules.d.ts +1 -0
- package/lib/dynamic-load/shareRules.js +42 -0
- package/lib/dynamic-load/shareRules.js.map +1 -0
- package/lib/formula/core.js +22 -5
- package/lib/formula/core.js.map +1 -1
- package/lib/formula/index.d.ts +2 -0
- package/lib/formula/index.js +28 -1
- package/lib/formula/index.js.map +1 -1
- package/lib/formula/simple_params.d.ts +2 -0
- package/lib/formula/simple_params.js +91 -0
- package/lib/formula/simple_params.js.map +1 -0
- package/lib/formula/type.d.ts +3 -2
- package/lib/formula/type.js.map +1 -1
- package/lib/index.d.ts +3 -0
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -1
- package/lib/metadata-register/_base.d.ts +3 -1
- package/lib/metadata-register/_base.js +16 -5
- package/lib/metadata-register/_base.js.map +1 -1
- package/lib/metadata-register/permissionFields.d.ts +7 -0
- package/lib/metadata-register/permissionFields.js +18 -0
- package/lib/metadata-register/permissionFields.js.map +1 -0
- package/lib/metadata-register/restrictionRules.d.ts +7 -0
- package/lib/metadata-register/restrictionRules.js +18 -0
- package/lib/metadata-register/restrictionRules.js.map +1 -0
- package/lib/metadata-register/shareRules.d.ts +7 -0
- package/lib/metadata-register/shareRules.js +18 -0
- package/lib/metadata-register/shareRules.js.map +1 -0
- package/lib/types/field_permission.d.ts +4 -0
- package/lib/types/field_permission.js +50 -0
- package/lib/types/field_permission.js.map +1 -0
- package/lib/types/object.d.ts +1 -0
- package/lib/types/object.js +302 -133
- package/lib/types/object.js.map +1 -1
- package/lib/types/object_dynamic_load.js +13 -4
- package/lib/types/object_dynamic_load.js.map +1 -1
- package/lib/types/object_permission.d.ts +1 -0
- package/lib/types/object_permission.js +31 -0
- package/lib/types/object_permission.js.map +1 -1
- package/lib/types/restrictionRule.d.ts +13 -0
- package/lib/types/restrictionRule.js +75 -0
- package/lib/types/restrictionRule.js.map +1 -0
- package/lib/types/shareRule.d.ts +13 -0
- package/lib/types/shareRule.js +75 -0
- package/lib/types/shareRule.js.map +1 -0
- package/lib/util/field.js +4 -4
- package/lib/util/field.js.map +1 -1
- package/lib/util/function_expression.d.ts +2 -0
- package/lib/util/function_expression.js +66 -0
- package/lib/util/function_expression.js.map +1 -0
- package/lib/util/index.d.ts +1 -0
- package/lib/util/index.js +1 -0
- package/lib/util/index.js.map +1 -1
- package/package.json +8 -8
- package/src/dynamic-load/preload_data.ts +44 -0
- package/src/dynamic-load/restrictionRules.ts +19 -0
- package/src/dynamic-load/shareRules.ts +19 -0
- package/src/formula/core.ts +19 -2
- package/src/formula/index.ts +21 -1
- package/src/formula/simple_params.ts +92 -0
- package/src/formula/type.ts +4 -3
- package/src/index.ts +4 -1
- package/src/metadata-register/_base.ts +14 -3
- package/src/metadata-register/permissionFields.ts +13 -0
- package/src/metadata-register/restrictionRules.ts +12 -0
- package/src/metadata-register/shareRules.ts +13 -0
- package/src/types/field_permission.ts +26 -0
- package/src/types/object.ts +198 -22
- package/src/types/object_dynamic_load.ts +4 -1
- package/src/types/object_permission.ts +32 -0
- package/src/types/restrictionRule.ts +57 -0
- package/src/types/shareRule.ts +57 -0
- package/src/util/field.ts +4 -4
- package/src/util/function_expression.ts +63 -0
- package/src/util/index.ts +1 -0
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
}
|
|
@@ -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:
|
|
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:
|
|
79
|
-
fields.push({ name: 'precision', required:
|
|
80
|
-
fields.push({ name: 'scale', required:
|
|
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' });
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as _ from 'lodash'
|
|
2
|
+
|
|
3
|
+
const globalTag = '__G_L_O_B_A_L__';
|
|
4
|
+
|
|
5
|
+
const getParentPath = function (path) {
|
|
6
|
+
var pathArr;
|
|
7
|
+
if (typeof path === 'string') {
|
|
8
|
+
pathArr = path.split('.');
|
|
9
|
+
if (pathArr.length === 1) {
|
|
10
|
+
return '#';
|
|
11
|
+
}
|
|
12
|
+
pathArr.pop();
|
|
13
|
+
return pathArr.join('.');
|
|
14
|
+
}
|
|
15
|
+
return '#';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const getValueByPath = function (formData, path) {
|
|
19
|
+
if (path === '#' || !path) {
|
|
20
|
+
return formData || {};
|
|
21
|
+
} else if (typeof path === 'string') {
|
|
22
|
+
return _.get(formData, path);
|
|
23
|
+
} else {
|
|
24
|
+
console.error('path has to be a string');
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const isExpression = function (func) {
|
|
29
|
+
var pattern, reg1, reg2;
|
|
30
|
+
if (typeof func !== 'string') {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
pattern = /^{{(.+)}}$/;
|
|
34
|
+
reg1 = /^{{(function.+)}}$/;
|
|
35
|
+
reg2 = /^{{(.+=>.+)}}$/;
|
|
36
|
+
if (typeof func === 'string' && func.match(pattern) && !func.match(reg1) && !func.match(reg2)) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const parseSingleExpression = function (func, formData, dataPath, global, userSession = {}) {
|
|
43
|
+
var error, funcBody, parent, parentPath, str;
|
|
44
|
+
|
|
45
|
+
if (formData === void 0) {
|
|
46
|
+
formData = {};
|
|
47
|
+
}
|
|
48
|
+
parentPath = getParentPath(dataPath);
|
|
49
|
+
parent = getValueByPath(formData, parentPath) || {};
|
|
50
|
+
if (typeof func === 'string') {
|
|
51
|
+
funcBody = func.substring(2, func.length - 2);
|
|
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
|
+
try {
|
|
54
|
+
return Function(str)();
|
|
55
|
+
} catch (_error) {
|
|
56
|
+
error = _error;
|
|
57
|
+
console.log(error, func, dataPath);
|
|
58
|
+
return func;
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
return func;
|
|
62
|
+
}
|
|
63
|
+
};
|
package/src/util/index.ts
CHANGED
|
@@ -27,6 +27,7 @@ export * from './permission_shares'
|
|
|
27
27
|
export * from './suffix'
|
|
28
28
|
export * from './locale'
|
|
29
29
|
export * from './field'
|
|
30
|
+
export * from './function_expression'
|
|
30
31
|
|
|
31
32
|
exports.loadJSONFile = (filePath: string)=>{
|
|
32
33
|
return JSON.parse(fs.readFileSync(filePath, 'utf8').normalize('NFC'));
|