@fibery/views 10.6.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 -55
- package/package.json +3 -3
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,66 +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
|
-
if (!field) {
|
|
1028
|
-
return keyPart;
|
|
1029
|
-
}
|
|
1030
|
-
if (!(type in schema.typeObjectsByName)) {
|
|
1031
|
-
return keyPart;
|
|
1032
|
-
}
|
|
1033
|
-
const typeObject = schema.typeObjectsByName[type];
|
|
1034
|
-
if (!(field in typeObject.fieldObjectsByName)) {
|
|
1035
|
-
return keyPart;
|
|
1036
|
-
}
|
|
1037
|
-
const fieldObject = typeObject.fieldObjectsByName[field];
|
|
1038
|
-
return `${unitType}_${fieldObject.id}`;
|
|
1039
|
-
}).filter(Boolean).join("|");
|
|
1040
|
-
}
|
|
1072
|
+
visitUnitGroupKey: unitGroupKey => replaceNamesWithIdsInUnitGroupKey(unitGroupKey, schema)
|
|
1041
1073
|
});
|
|
1042
1074
|
const replaceIdsWithNamesInSmartFolder = (schema, smartFolder) => visitSmartFolder(smartFolder, {
|
|
1043
1075
|
visitQueryExpression: query => replaceIdsWithNamesInQueryExpression(schema, query),
|
|
1044
1076
|
visitGroupByExpression: (groupBy, fromType) => replaceIdsWithNamesInGroupByExpression(schema, groupBy, fromType, Object.keys(groupBy).map(() => 0)),
|
|
1045
1077
|
visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression),
|
|
1046
|
-
visitUnitGroupKey: unitGroupKey =>
|
|
1047
|
-
const types = smartFolder["fibery/meta"].items.map(item => item.query["q/from"]);
|
|
1048
|
-
const fieldObjectsById = types.reduce((acc, type) => {
|
|
1049
|
-
if (!(type in schema.typeObjectsById)) {
|
|
1050
|
-
return acc;
|
|
1051
|
-
}
|
|
1052
|
-
const fieldObjects = schema.typeObjectsById[type].fieldObjectsById;
|
|
1053
|
-
return {
|
|
1054
|
-
...acc,
|
|
1055
|
-
...fieldObjects
|
|
1056
|
-
};
|
|
1057
|
-
}, {});
|
|
1058
|
-
const keyParts = unitGroupKey.split("|");
|
|
1059
|
-
return keyParts.map(keyPart => {
|
|
1060
|
-
const [unitType, ...rest] = keyPart.split("_");
|
|
1061
|
-
if (unitType === "user-button") {
|
|
1062
|
-
return keyPart;
|
|
1063
|
-
}
|
|
1064
|
-
const fieldId = rest.join("_");
|
|
1065
|
-
if (!fieldId) {
|
|
1066
|
-
return keyPart;
|
|
1067
|
-
}
|
|
1068
|
-
const fieldObject = fieldObjectsById[fieldId];
|
|
1069
|
-
if (!fieldObject) {
|
|
1070
|
-
return keyPart;
|
|
1071
|
-
}
|
|
1072
|
-
return `${unitType}_${fieldObject.holderType}:${fieldObject.name}`;
|
|
1073
|
-
}).filter(Boolean).join("|");
|
|
1074
|
-
}
|
|
1078
|
+
visitUnitGroupKey: unitGroupKey => replaceIdsWithNamesInUnitGroupKey(unitGroupKey, getFieldObjectsById(smartFolder, schema))
|
|
1075
1079
|
});
|
|
1076
1080
|
const deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder = (schema, smartFolder) => visitSmartFolder(smartFolder, {
|
|
1077
1081
|
visitQueryExpression: query => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, query),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibery/views",
|
|
3
|
-
"version": "10.6.
|
|
3
|
+
"version": "10.6.1",
|
|
4
4
|
"description": "Operations on view objects",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"author": "Fibery",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"lodash": "4.17.21",
|
|
20
20
|
"microbundle": "0.15.1",
|
|
21
21
|
"@fibery/babel-preset": "7.4.0",
|
|
22
|
+
"@fibery/expression-utils": "9.0.5",
|
|
22
23
|
"@fibery/eslint-config": "8.6.0",
|
|
23
|
-
"@fibery/schema": "10.2.1"
|
|
24
|
-
"@fibery/expression-utils": "9.0.5"
|
|
24
|
+
"@fibery/schema": "10.2.1"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@fibery/expression-utils": "^9.0.5",
|