-
Notifications
You must be signed in to change notification settings - Fork 6
/
schema.utils.js
95 lines (83 loc) · 2.09 KB
/
schema.utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
'use strict';
const { iter } = require('@metarhia/common');
const { extractDecorator } = require('metaschema');
const CATEGORY_TYPES = {
Registry: 'Global',
Dictionary: 'Global',
System: 'Global',
History: 'Global',
Local: 'Local',
Log: 'Local',
View: 'Ignore',
Memory: 'Ignore',
};
const getCategoryType = schema =>
CATEGORY_TYPES[extractDecorator(schema)] || 'Local';
const isGlobalCategory = category => getCategoryType(category) === 'Global';
const isIgnoredCategory = category => getCategoryType(category) === 'Ignore';
const isLocalCategory = category => getCategoryType(category) === 'Local';
const decoratorToRealm = {
Registry: 'Global',
Dictionary: 'Global',
System: 'System',
Log: 'Local',
Local: 'Local',
Table: 'Local',
History: 'Global',
View: 'System',
Object: 'Local',
};
const getCategoryRealm = category =>
decoratorToRealm[extractDecorator(category)];
const getCategoryFamily = category => {
const decorator = extractDecorator(category);
if (decorator === 'Object') {
return 'Local';
}
return decorator;
};
const constructActions = (actions, pub, category) => {
const common = {
Public: pub,
};
if (!pub) common.Category = category;
return iter(actions).map(([key, value]) => ({
...common,
Name: key,
Execute: value.definition.Execute,
}));
};
const extractIncludeCategoriesData = (category, record) => {
const result = [];
for (const key in category) {
const field = category[key];
if (extractDecorator(field) === 'Include') {
result.push({
category: field.category,
value: record[key],
});
}
}
return result;
};
const extractIncludeCategories = category => {
const result = [];
for (const key in category) {
const field = category[key];
if (extractDecorator(field) === 'Include') {
result.push(field.category);
}
}
return result;
};
module.exports = {
getCategoryType,
isGlobalCategory,
isIgnoredCategory,
isLocalCategory,
getCategoryRealm,
getCategoryFamily,
constructActions,
extractIncludeCategoriesData,
extractIncludeCategories,
};