@fibery/views 10.5.0 → 10.6.1
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/views.js +59 -48
- package/package.json +2 -2
package/lib/views.js
CHANGED
|
@@ -126,6 +126,63 @@ const isUnitExpressionValid = unit => {
|
|
|
126
126
|
}
|
|
127
127
|
return true;
|
|
128
128
|
};
|
|
129
|
+
const getFieldObjectsById = (smartFolder, schema) => {
|
|
130
|
+
const types = smartFolder["fibery/meta"].items.map(item => item.query["q/from"]);
|
|
131
|
+
return types.reduce((acc, type) => {
|
|
132
|
+
if (!(type in schema.typeObjectsById)) {
|
|
133
|
+
return acc;
|
|
134
|
+
}
|
|
135
|
+
const fieldObjects = schema.typeObjectsById[type].fieldObjectsById;
|
|
136
|
+
return {
|
|
137
|
+
...acc,
|
|
138
|
+
...fieldObjects
|
|
139
|
+
};
|
|
140
|
+
}, {});
|
|
141
|
+
};
|
|
142
|
+
const replaceIdsWithNamesInUnitGroupKey = (unitGroupKey, fieldObjectsById) => {
|
|
143
|
+
const keyParts = unitGroupKey.split("|");
|
|
144
|
+
return keyParts.map(keyPart => {
|
|
145
|
+
const [unitType, ...rest] = keyPart.split("_");
|
|
146
|
+
if (unitType === "user-button") {
|
|
147
|
+
return keyPart;
|
|
148
|
+
}
|
|
149
|
+
const fieldId = rest.join("_");
|
|
150
|
+
if (!fieldId) {
|
|
151
|
+
return keyPart;
|
|
152
|
+
}
|
|
153
|
+
const fieldObject = fieldObjectsById[fieldId];
|
|
154
|
+
if (!fieldObject) {
|
|
155
|
+
return keyPart;
|
|
156
|
+
}
|
|
157
|
+
return `${unitType}_${fieldObject.holderType}:${fieldObject.name}`;
|
|
158
|
+
}).filter(Boolean).join("|");
|
|
159
|
+
};
|
|
160
|
+
const replaceNamesWithIdsInUnitGroupKey = (unitGroupKey, schema) => {
|
|
161
|
+
const keyParts = unitGroupKey.split("|");
|
|
162
|
+
return keyParts.map(keyPart => {
|
|
163
|
+
const [unitType, ...rest] = keyPart.split("_");
|
|
164
|
+
if (unitType === "user-button") {
|
|
165
|
+
return keyPart;
|
|
166
|
+
}
|
|
167
|
+
const name = rest.join("_");
|
|
168
|
+
if (!name) {
|
|
169
|
+
return keyPart;
|
|
170
|
+
}
|
|
171
|
+
const [type, field] = name.split(":");
|
|
172
|
+
if (!field) {
|
|
173
|
+
return keyPart;
|
|
174
|
+
}
|
|
175
|
+
if (!(type in schema.typeObjectsByName)) {
|
|
176
|
+
return keyPart;
|
|
177
|
+
}
|
|
178
|
+
const typeObject = schema.typeObjectsByName[type];
|
|
179
|
+
if (!(field in typeObject.fieldObjectsByName)) {
|
|
180
|
+
return keyPart;
|
|
181
|
+
}
|
|
182
|
+
const fieldObject = typeObject.fieldObjectsByName[field];
|
|
183
|
+
return `${unitType}_${fieldObject.id}`;
|
|
184
|
+
}).filter(Boolean).join("|");
|
|
185
|
+
};
|
|
129
186
|
|
|
130
187
|
const getField = (schema, fromType, field) => Object.hasOwn(schema.typeObjectsByName, fromType) && Object.hasOwn(schema.typeObjectsByName[fromType].fieldObjectsByName, field) ? schema.typeObjectsByName[fromType].fieldObjectsByName[field] : undefined;
|
|
131
188
|
const getFieldType = (schema, fromType, field) => {
|
|
@@ -1012,59 +1069,13 @@ const replaceNamesWithIdsInSmartFolder = (schema, smartFolder) => visitSmartFold
|
|
|
1012
1069
|
visitQueryExpression: query => replaceNamesWithIdsInQueryExpression(schema, query),
|
|
1013
1070
|
visitGroupByExpression: (groupBy, fromType) => replaceNamesWithIdsInGroupByExpression(schema, groupBy, fromType, Object.keys(groupBy).map(() => 0)),
|
|
1014
1071
|
visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression),
|
|
1015
|
-
visitUnitGroupKey: unitGroupKey =>
|
|
1016
|
-
const keyParts = unitGroupKey.split("|");
|
|
1017
|
-
return keyParts.map(keyPart => {
|
|
1018
|
-
const [unitType, ...rest] = keyPart.split("_");
|
|
1019
|
-
if (unitType === "user-button") {
|
|
1020
|
-
return keyPart;
|
|
1021
|
-
}
|
|
1022
|
-
const name = rest.join("_");
|
|
1023
|
-
if (!name) {
|
|
1024
|
-
return keyPart;
|
|
1025
|
-
}
|
|
1026
|
-
const [type, field] = name.split(":");
|
|
1027
|
-
const fieldObject = schema.typeObjectsByName[type].fieldObjectsByName[field];
|
|
1028
|
-
if (!fieldObject) {
|
|
1029
|
-
return null;
|
|
1030
|
-
}
|
|
1031
|
-
return `${unitType}_${fieldObject.id}`;
|
|
1032
|
-
}).filter(Boolean).join("|");
|
|
1033
|
-
}
|
|
1072
|
+
visitUnitGroupKey: unitGroupKey => replaceNamesWithIdsInUnitGroupKey(unitGroupKey, schema)
|
|
1034
1073
|
});
|
|
1035
1074
|
const replaceIdsWithNamesInSmartFolder = (schema, smartFolder) => visitSmartFolder(smartFolder, {
|
|
1036
1075
|
visitQueryExpression: query => replaceIdsWithNamesInQueryExpression(schema, query),
|
|
1037
1076
|
visitGroupByExpression: (groupBy, fromType) => replaceIdsWithNamesInGroupByExpression(schema, groupBy, fromType, Object.keys(groupBy).map(() => 0)),
|
|
1038
1077
|
visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression),
|
|
1039
|
-
visitUnitGroupKey: unitGroupKey =>
|
|
1040
|
-
const types = smartFolder["fibery/meta"].items.map(item => item.query["q/from"]);
|
|
1041
|
-
const fieldObjectsById = types.reduce((acc, type) => {
|
|
1042
|
-
if (!(type in schema.typeObjectsById)) {
|
|
1043
|
-
return acc;
|
|
1044
|
-
}
|
|
1045
|
-
const fieldObjects = schema.typeObjectsById[type].fieldObjectsById;
|
|
1046
|
-
return {
|
|
1047
|
-
...acc,
|
|
1048
|
-
...fieldObjects
|
|
1049
|
-
};
|
|
1050
|
-
}, {});
|
|
1051
|
-
const keyParts = unitGroupKey.split("|");
|
|
1052
|
-
return keyParts.map(keyPart => {
|
|
1053
|
-
const [unitType, ...rest] = keyPart.split("_");
|
|
1054
|
-
if (unitType === "user-button") {
|
|
1055
|
-
return keyPart;
|
|
1056
|
-
}
|
|
1057
|
-
const fieldId = rest.join("_");
|
|
1058
|
-
if (!fieldId) {
|
|
1059
|
-
return keyPart;
|
|
1060
|
-
}
|
|
1061
|
-
const fieldObject = fieldObjectsById[fieldId];
|
|
1062
|
-
if (!fieldObject) {
|
|
1063
|
-
return null;
|
|
1064
|
-
}
|
|
1065
|
-
return `${unitType}_${fieldObject.holderType}:${fieldObject.name}`;
|
|
1066
|
-
}).filter(Boolean).join("|");
|
|
1067
|
-
}
|
|
1078
|
+
visitUnitGroupKey: unitGroupKey => replaceIdsWithNamesInUnitGroupKey(unitGroupKey, getFieldObjectsById(smartFolder, schema))
|
|
1068
1079
|
});
|
|
1069
1080
|
const deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder = (schema, smartFolder) => visitSmartFolder(smartFolder, {
|
|
1070
1081
|
visitQueryExpression: query => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, query),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibery/views",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.6.1",
|
|
4
4
|
"description": "Operations on view objects",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"author": "Fibery",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"lodash": "4.17.21",
|
|
20
20
|
"microbundle": "0.15.1",
|
|
21
21
|
"@fibery/babel-preset": "7.4.0",
|
|
22
|
-
"@fibery/eslint-config": "8.6.0",
|
|
23
22
|
"@fibery/expression-utils": "9.0.5",
|
|
23
|
+
"@fibery/eslint-config": "8.6.0",
|
|
24
24
|
"@fibery/schema": "10.2.1"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|