@fibery/views 20.0.2 → 21.0.0

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 (33) hide show
  1. package/lib/field-utils/avatar.js +2 -2
  2. package/lib/field-utils/date-time.js +4 -2
  3. package/lib/field-utils/icon.js +2 -2
  4. package/lib/field-utils/reference.js +2 -1
  5. package/lib/field-utils/rich-text.js +3 -2
  6. package/lib/field-utils/user-active.js +17 -17
  7. package/lib/field-utils/workflow.js +7 -10
  8. package/lib/private/board.js +20 -18
  9. package/lib/private/form.js +10 -8
  10. package/lib/private/smart-folder.js +8 -12
  11. package/lib/private/timeline.d.ts +1 -0
  12. package/lib/private/timeline.js +19 -14
  13. package/lib/private/units.js +24 -11
  14. package/lib/private/utils.js +52 -64
  15. package/lib/unit-definitions/avatar.js +9 -6
  16. package/lib/unit-definitions/comments-list.js +3 -2
  17. package/lib/unit-definitions/file-collection-count.js +3 -2
  18. package/lib/unit-definitions/file-compact-collection.js +3 -2
  19. package/lib/unit-definitions/file-compact-reference.js +2 -1
  20. package/lib/unit-definitions/file-reference.js +2 -1
  21. package/lib/unit-definitions/files-gallery.js +3 -2
  22. package/lib/unit-definitions/files-l-list-item.js +2 -1
  23. package/lib/unit-definitions/files-l-list.js +3 -2
  24. package/lib/unit-definitions/files-list-item.js +2 -1
  25. package/lib/unit-definitions/files-list.js +3 -2
  26. package/lib/unit-definitions/reference-collection.js +5 -4
  27. package/lib/unit-definitions/reference.js +3 -2
  28. package/lib/unit-utils/enums.js +2 -2
  29. package/lib/unit-utils/schema.d.ts +1 -1
  30. package/lib/unit-utils/schema.js +1 -1
  31. package/lib/units/gantt.js +1 -1
  32. package/lib/units/make-factory.js +10 -8
  33. package/package.json +7 -7
@@ -4,7 +4,7 @@ import { toSelectMapClause } from "@fibery/query-utils/src/select";
4
4
  const AVATAR_MIXIN_NAME = "avatar/avatar-mixin";
5
5
  const AVATAR_EXTENSION_FIELD = "avatar/avatars";
6
6
  const isAvatarExtensionEnabledType = (typeObject) => {
7
- return typeObject && typeObject.installedMixins.has("avatar/avatar-mixin") && isAvatarExtensionField(typeObject.fieldObjectsByName["avatar/avatars"]);
7
+ return typeObject && typeObject.installedMixins.has("avatar/avatar-mixin") && isAvatarExtensionField(typeObject.getFieldObjectByNameOrThrow("avatar/avatars"));
8
8
  };
9
9
  const isAvatarExtensionField = (fieldObject) => {
10
10
  return fieldObject.name === "avatar/avatars" && fieldObject.type === "fibery/file";
@@ -17,7 +17,7 @@ const getAvatarSelect = (fieldObject) => toSelectMapClause([
17
17
  ].filter(truthy));
18
18
  const getAvatarSelectQuery = ({ typeObject }) => {
19
19
  if (isAvatarExtensionEnabledType(typeObject)) {
20
- const fieldObject = typeObject.fieldObjectsByName[AVATAR_EXTENSION_FIELD];
20
+ const fieldObject = typeObject.getFieldObjectByNameOrThrow(AVATAR_EXTENSION_FIELD);
21
21
  const idField = fieldObject.typeObject.idField;
22
22
  const typeTitleField = typeObject.titleField;
23
23
  return {
@@ -22,8 +22,10 @@ const parseStart = ({ value, type }) => {
22
22
  throw new NotImplementedError(type);
23
23
  };
24
24
  const parseEnd = ({ value, type, minimumDelta = null }) => {
25
- if (isDateType(type)) if (isRangeType(type)) return parseDate(value).subtract(...minimumDelta || defaultDateDelta).endOf("day");
26
- else return parseDate(value).endOf("day");
25
+ if (isDateType(type)) {
26
+ if (isRangeType(type)) return parseDate(value).subtract(...minimumDelta || defaultDateDelta).endOf("day");
27
+ else return parseDate(value).endOf("day");
28
+ }
27
29
  if (isDateTimeType(type)) return parseDateTime(value).subtract(...minimumDelta || defaultDateTimeDelta).startOf("second");
28
30
  throw new NotImplementedError(type);
29
31
  };
@@ -2,14 +2,14 @@
2
2
  const ICON_MIXIN_NAME = "icon/icon-mixin";
3
3
  const ICON_EXTENSION_FIELD = "icon/icon";
4
4
  const isIconExtensionEnabledType = (typeObject) => {
5
- return typeObject.installedMixins.has("icon/icon-mixin") && isIconExtensionField(typeObject.fieldObjectsByName["icon/icon"]);
5
+ return typeObject.installedMixins.has("icon/icon-mixin") && isIconExtensionField(typeObject.getFieldObjectByNameOrThrow("icon/icon"));
6
6
  };
7
7
  const isIconExtensionField = (fieldObject) => {
8
8
  return fieldObject.name === "icon/icon" && fieldObject.type === "fibery/emoji";
9
9
  };
10
10
  const getEntityIconSelect = ({ typeObject }) => {
11
11
  if (isIconExtensionEnabledType(typeObject)) {
12
- const fieldObject = typeObject.fieldObjectsByName[ICON_EXTENSION_FIELD];
12
+ const fieldObject = typeObject.getFieldObjectByNameOrThrow(ICON_EXTENSION_FIELD);
13
13
  return { [fieldObject.name]: fieldObject.name };
14
14
  } else return {};
15
15
  };
@@ -42,7 +42,8 @@ const getReferenceFieldNormalizedSelectClause = (fieldObject, contextPath) => {
42
42
  const { typeObject } = fieldObject;
43
43
  if (typeObject.isEntityRef) {
44
44
  const pairs = fieldObject.multiRelatedFieldObjects.map((f) => {
45
- const normalizedSelect = normalizeSelect(getReferenceTypeSelectClause({ typeObject: f.holderTypeObject }, [contextPath.concat(f.holderType)]));
45
+ const select = getReferenceTypeSelectClause({ typeObject: f.holderTypeObject }, [contextPath.concat(f.holderType)]);
46
+ const normalizedSelect = normalizeSelect(select);
46
47
  return [f.holderType, {
47
48
  ...normalizedSelect,
48
49
  [isSelectForMultiFieldKey]: true
@@ -16,7 +16,7 @@ function getRichTextQuerySelect({ typeObject, unit: { expression }, includeSnipp
16
16
  ...toSelectMapClause([terminalTypeObject.idField, "Collaboration~Documents/secret"]),
17
17
  ...includeSnippet ? toSelectMapClause([terminalTypeObject.idField, "Collaboration~Documents/Snippet"]) : {}
18
18
  });
19
- return denormalizeSelect([...expression].reverse().reduce((inner, field, reversedIndex) => {
19
+ const nested = [...expression].reverse().reduce((inner, field, reversedIndex) => {
20
20
  const originalIndex = expression.length - 1 - reversedIndex;
21
21
  if (!(originalIndex === expression.length - 1)) {
22
22
  const { idField } = fieldObjects[originalIndex].typeObject;
@@ -27,7 +27,8 @@ function getRichTextQuerySelect({ typeObject, unit: { expression }, includeSnipp
27
27
  return { [field]: innerWithId };
28
28
  }
29
29
  return { [field]: inner };
30
- }, innerNormalized));
30
+ }, innerNormalized);
31
+ return denormalizeSelect(nested);
31
32
  }
32
33
  //#endregion
33
34
  export { getHasAccessToSecret, getHasAccessToSecretExpr, getRichTextQuerySelect, hasAccessToSecretKey };
@@ -1,23 +1,23 @@
1
1
  import { isUserActiveDynamicKeyPrefix, makeDynamicKey } from "../unit-utils/dynamic-keys.js";
2
- import { memoize } from "@fibery/helpers/src/_";
2
+ import { memoizeLeak, memoizeWeak } from "@fibery/helpers/src/_";
3
3
  //#region src/field-utils/user-active.ts
4
- const getIsUserActiveQueryPredicate = memoize(({ typeObject, contextPath }) => {
5
- if (typeObject.name !== "fibery/user") return null;
6
- const expression = [
7
- "=",
8
- [...contextPath, "fibery/active?"],
9
- "$true"
10
- ];
11
- return {
12
- key: makeDynamicKey(isUserActiveDynamicKeyPrefix),
13
- expression
14
- };
15
- }, ({ typeObject, contextPath }) => `${typeObject.name}_${typeObject.version}_${contextPath.join(",")}`);
4
+ const noUserActiveQueryPredicate = () => null;
5
+ const getIsUserActiveQueryPredicate = memoizeWeak((typeObject) => {
6
+ if (typeObject.name !== "fibery/user") return noUserActiveQueryPredicate;
7
+ return memoizeLeak((contextPath) => {
8
+ const expression = [
9
+ "=",
10
+ [...contextPath, "fibery/active?"],
11
+ "$true"
12
+ ];
13
+ return {
14
+ key: makeDynamicKey(isUserActiveDynamicKeyPrefix),
15
+ expression
16
+ };
17
+ }, (contextPath) => contextPath.join(","));
18
+ });
16
19
  const getIsUserActiveSelect = ({ typeObject, contextPath = [] }) => {
17
- const isUserActiveQueryPredicate = getIsUserActiveQueryPredicate({
18
- typeObject,
19
- contextPath
20
- });
20
+ const isUserActiveQueryPredicate = getIsUserActiveQueryPredicate(typeObject)(contextPath);
21
21
  return isUserActiveQueryPredicate ? { [isUserActiveQueryPredicate.key]: isUserActiveQueryPredicate.expression } : null;
22
22
  };
23
23
  //#endregion
@@ -1,5 +1,5 @@
1
1
  import { isFinalStateDynamicKeyPrefix, makeDynamicKey } from "../unit-utils/dynamic-keys.js";
2
- import { memoize } from "@fibery/helpers/src/_";
2
+ import { memoizeLeak, memoizeWeak } from "@fibery/helpers/src/_";
3
3
  //#region src/field-utils/workflow.ts
4
4
  function isWorkflowType(typeObject) {
5
5
  return typeObject.isEnum && typeObject.nameParts.namespace === "workflow";
@@ -13,9 +13,11 @@ const getWorkflowFieldObject = (typeObject) => {
13
13
  });
14
14
  return workflowFieldObject;
15
15
  };
16
- const getIsFinalStateQueryPredicate = memoize(({ typeObject, contextPath }) => {
16
+ const noFinalStateQueryPredicate = () => null;
17
+ const getIsFinalStateQueryPredicate = memoizeWeak((typeObject) => {
17
18
  const workflowFieldObject = getWorkflowFieldObject(typeObject);
18
- if (workflowFieldObject) {
19
+ if (!workflowFieldObject) return noFinalStateQueryPredicate;
20
+ return memoizeLeak((contextPath) => {
19
21
  const expression = [
20
22
  "=",
21
23
  [
@@ -29,15 +31,10 @@ const getIsFinalStateQueryPredicate = memoize(({ typeObject, contextPath }) => {
29
31
  key: makeDynamicKey(isFinalStateDynamicKeyPrefix),
30
32
  expression
31
33
  };
32
- } else return null;
33
- }, ({ typeObject, contextPath }) => {
34
- return `${typeObject.name}_${typeObject.version}_${contextPath.join(",")}`;
34
+ }, (contextPath) => contextPath.join(","));
35
35
  });
36
36
  const getIsFinalStateSelect = ({ typeObject, contextPath = [] }) => {
37
- const isFinalStateQueryPredicate = getIsFinalStateQueryPredicate({
38
- typeObject,
39
- contextPath
40
- });
37
+ const isFinalStateQueryPredicate = getIsFinalStateQueryPredicate(typeObject)(contextPath);
41
38
  return isFinalStateQueryPredicate ? { [isFinalStateQueryPredicate.key]: isFinalStateQueryPredicate.expression } : null;
42
39
  };
43
40
  function getWorkflowTypeSelect(typeObject) {
@@ -121,12 +121,14 @@ const replaceNamesWithIdsViewVisitor = (schema) => {
121
121
  visitFilter: (fromType, filter) => replaceNamesWithIdsInFilter(schema, fromType, filter),
122
122
  visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression),
123
123
  visitEnums: (enums) => entries(enums).reduce((result, [type, queryHolder]) => {
124
- if (Object.hasOwn(schema.typeObjectsByName, type)) {
125
- const typeObject = schema.typeObjectsByName[type];
126
- const fromType = get(queryHolder, ["query", "q/from"]);
127
- const axisWithVisitedQuery = visitQueryExpressionHolder(queryHolder, visitor);
128
- result[typeObject.id] = visitAxisUnits(axisWithVisitedQuery, fromType, visitor);
129
- } else result[type] = queryHolder;
124
+ const typeObject = schema.getTypeObjectByName(type);
125
+ if (!typeObject) {
126
+ result[type] = queryHolder;
127
+ return result;
128
+ }
129
+ const fromType = get(queryHolder, ["query", "q/from"]);
130
+ const axisWithVisitedQuery = visitQueryExpressionHolder(queryHolder, visitor);
131
+ result[typeObject.id] = visitAxisUnits(axisWithVisitedQuery, fromType, visitor);
130
132
  return result;
131
133
  }, {})
132
134
  };
@@ -140,12 +142,14 @@ const replaceIdsWithNamesViewVisitor = (schema) => {
140
142
  },
141
143
  visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression),
142
144
  visitEnums: (enums) => entries(enums).reduce((result, [typeId, queryHolder]) => {
143
- if (Object.hasOwn(schema.typeObjectsById, typeId)) {
144
- const typeObject = schema.typeObjectsById[typeId];
145
- const fromType = get(queryHolder, ["query", "q/from"]);
146
- const axisWithVisitedQuery = visitQueryExpressionHolder(queryHolder, visitor);
147
- result[typeObject.name] = visitAxisUnits(axisWithVisitedQuery, fromType, visitor);
148
- } else result[typeId] = queryHolder;
145
+ const typeObject = schema.getTypeObjectById(typeId);
146
+ if (!typeObject) {
147
+ result[typeId] = queryHolder;
148
+ return result;
149
+ }
150
+ const fromType = get(queryHolder, ["query", "q/from"]);
151
+ const axisWithVisitedQuery = visitQueryExpressionHolder(queryHolder, visitor);
152
+ result[typeObject.name] = visitAxisUnits(axisWithVisitedQuery, fromType, visitor);
149
153
  return result;
150
154
  }, {})
151
155
  };
@@ -158,12 +162,10 @@ const deleteExpressionWithNotFoundFieldsOrTypesViewVisitor = (schema) => {
158
162
  visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression),
159
163
  visitEnums: (enums) => {
160
164
  const enumsNew = entries(enums).reduce((result, [type, queryHolder]) => {
161
- if (Object.hasOwn(schema.typeObjectsByName, type)) {
162
- const typeObject = schema.typeObjectsByName[type];
163
- const queryHolderResult = visitQueryExpressionHolder(queryHolder, visitor);
164
- if (queryHolderResult) result[typeObject.name] = queryHolderResult;
165
- return result;
166
- }
165
+ const typeObject = schema.getTypeObjectByName(type);
166
+ if (!typeObject) return result;
167
+ const queryHolderResult = visitQueryExpressionHolder(queryHolder, visitor);
168
+ if (queryHolderResult) result[typeObject.name] = queryHolderResult;
167
169
  return result;
168
170
  }, {});
169
171
  return isEmpty(enumsNew) ? null : enumsNew;
@@ -1,13 +1,14 @@
1
1
  //#region src/private/form.ts
2
2
  const replaceNamesWithIdsInFormView = (schema, view) => {
3
3
  const typeId = view["fibery/meta"]?.typeId;
4
- const typeObject = typeId && Object.hasOwn(schema.typeObjectsByName, typeId) ? schema.typeObjectsByName[typeId] : null;
4
+ const typeObject = typeId ? schema.getTypeObjectByName(typeId) : null;
5
5
  const fields = view["fibery/meta"]?.fields;
6
6
  const fieldsInIdsTerms = fields && fields.map((field) => {
7
- if (!typeObject || !Object.hasOwn(typeObject.fieldObjectsByName, field.id)) return field;
7
+ const fieldObject = typeObject?.getFieldObjectByName(field.id);
8
+ if (!fieldObject) return field;
8
9
  return {
9
10
  ...field,
10
- id: typeObject.fieldObjectsByName[field.id].id
11
+ id: fieldObject.id
11
12
  };
12
13
  });
13
14
  return {
@@ -21,13 +22,14 @@ const replaceNamesWithIdsInFormView = (schema, view) => {
21
22
  };
22
23
  const replaceIdsWithNamesInFormView = (schema, view) => {
23
24
  const typeId = view["fibery/meta"]?.typeId;
24
- const typeObject = typeId && Object.hasOwn(schema.typeObjectsById, typeId) ? schema.typeObjectsById[typeId] : null;
25
+ const typeObject = typeId ? schema.getTypeObjectById(typeId) : null;
25
26
  const fields = view["fibery/meta"]?.fields;
26
27
  const fieldsInNameTerms = fields && fields.map((field) => {
27
- if (!typeObject || !Object.hasOwn(typeObject.fieldObjectsById, field.id)) return field;
28
+ const fieldObject = typeObject?.getFieldObjectById(field.id);
29
+ if (!fieldObject) return field;
28
30
  return {
29
31
  ...field,
30
- id: typeObject.fieldObjectsById[field.id].name
32
+ id: fieldObject.name
31
33
  };
32
34
  });
33
35
  return {
@@ -41,9 +43,9 @@ const replaceIdsWithNamesInFormView = (schema, view) => {
41
43
  };
42
44
  const deleteExpressionWithNotFoundFieldsOrTypesInFormView = (schema, view) => {
43
45
  const typeName = view["fibery/meta"]?.typeId;
44
- const typeObject = typeName && Object.hasOwn(schema.typeObjectsByName, typeName) ? schema.typeObjectsByName[typeName] : null;
46
+ const typeObject = typeName ? schema.getTypeObjectByName(typeName) : null;
45
47
  const fields = view["fibery/meta"]?.fields;
46
- const existingFields = fields && fields.filter((field) => typeObject && Object.hasOwn(typeObject.fieldObjectsByName, field.id));
48
+ const existingFields = fields && fields.filter((field) => typeObject && Boolean(typeObject.getFieldObjectByName(field.id)));
47
49
  return {
48
50
  ...view,
49
51
  "fibery/meta": {
@@ -76,21 +76,17 @@ const deleteExpressionWithNotFoundFieldsOrTypesInGroupByExpression = (schema, gr
76
76
  };
77
77
  const replaceIdsWithNamesInGroupByExpression = (schema, groupByExpression, fromType) => {
78
78
  if (!groupByExpression) return null;
79
- return Object.fromEntries(Object.entries(groupByExpression).map(([index, { expression }]) => {
80
- if (Object.hasOwn(schema.typeObjectsById, fromType)) {
81
- const typeObject = schema.typeObjectsById[fromType];
82
- return [index, { expression: replaceIdsWithNamesVisitor(typeObject).visitExpression(expression) }];
83
- } else return [index, { expression }];
84
- }));
79
+ const typeObject = schema.getTypeObjectById(fromType);
80
+ if (!typeObject) return Object.fromEntries(Object.entries(groupByExpression).map(([index, { expression }]) => [index, { expression }]));
81
+ const visitor = replaceIdsWithNamesVisitor(typeObject);
82
+ return Object.fromEntries(Object.entries(groupByExpression).map(([index, { expression }]) => [index, { expression: visitor.visitExpression(expression) }]));
85
83
  };
86
84
  const replaceNamesWithIdsInGroupByExpression = (schema, groupByExpression, fromType) => {
87
85
  if (!groupByExpression) return null;
88
- return Object.fromEntries(Object.entries(groupByExpression).map(([index, { expression }]) => {
89
- if (Object.hasOwn(schema.typeObjectsByName, fromType)) {
90
- const typeObject = schema.typeObjectsByName[fromType];
91
- return [index, { expression: replaceNamesWithIdsVisitor(typeObject).visitExpression(expression) }];
92
- } else return [index, { expression }];
93
- }));
86
+ const typeObject = schema.getTypeObjectByName(fromType);
87
+ if (!typeObject) return Object.fromEntries(Object.entries(groupByExpression).map(([index, { expression }]) => [index, { expression }]));
88
+ const visitor = replaceNamesWithIdsVisitor(typeObject);
89
+ return Object.fromEntries(Object.entries(groupByExpression).map(([index, { expression }]) => [index, { expression: visitor.visitExpression(expression) }]));
94
90
  };
95
91
  const replaceNamesWithIdsInSmartFolder = (schema, smartFolder) => visitSmartFolder(smartFolder, {
96
92
  visitQueryExpression: (query) => replaceNamesWithIdsInQueryExpression(schema, query),
@@ -18,6 +18,7 @@ type TimelineMetaItem = {
18
18
  secondaryEndExpression?: Expression | null;
19
19
  contextExpression?: Expression | null;
20
20
  units?: Unit[] | null;
21
+ laneUnits?: Unit[] | null;
21
22
  colorCoding?: {
22
23
  expression: Expression;
23
24
  [k: string]: unknown;
@@ -10,6 +10,7 @@ import set from "lodash/set.js";
10
10
  import some from "lodash/some.js";
11
11
  import has from "lodash/has.js";
12
12
  //#region src/private/timeline.ts
13
+ const visitMetaItemUnits = (fromType, units, visitor) => units ? units.filter(truthy).map((unit) => visitViewUnit(fromType, unit, visitor)).filter(isUnitExpressionValid).map((unit, idx, nextUnits) => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit, nextUnits) : unit).filter((unit) => unit !== REMOVE) : void 0;
13
14
  const visitAxisSingle = (axis, visitor) => {
14
15
  const fromType = get(axis, ["query", "q/from"]);
15
16
  const firstOrNull = (x) => Array.isArray(x) ? x[0] : null;
@@ -50,7 +51,8 @@ const visitView = (view, visitor) => immutableUpdate(view, { "fibery/meta": {
50
51
  contextExpression: { $apply: (contextExpression) => visitContextExpression(fromType, contextExpression, visitor) },
51
52
  filter: { $apply: (filter) => filter ? visitor.visitFilter(fromType, filter) : null },
52
53
  query: { $apply: (query) => query ? visitor.visitQueryExpression(query) : null },
53
- units: { $apply: (units) => units ? units.filter(truthy).map((unit) => visitViewUnit(fromType, unit, visitor)).filter(isUnitExpressionValid).map((unit, idx, units) => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit, units) : unit).filter((unit) => unit !== REMOVE) : void 0 },
54
+ units: { $apply: (units) => visitMetaItemUnits(fromType, units, visitor) },
55
+ laneUnits: { $apply: (laneUnits) => visitMetaItemUnits(fromType, laneUnits, visitor) },
54
56
  colorCoding: { $apply: (colorCodings) => {
55
57
  return colorCodings && colorCodings.map((colorCoding) => ({
56
58
  ...colorCoding,
@@ -98,10 +100,12 @@ const replaceNamesWithIdsInTimelineView = (schema, view) => {
98
100
  visitFilter: (fromType, expression) => replaceNamesWithIdsInFilter(schema, fromType, expression),
99
101
  visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression),
100
102
  visitEnums: (enums) => entries(enums).reduce((result, [type, axis]) => {
101
- if (Object.hasOwn(schema.typeObjectsByName, type)) {
102
- const typeObject = schema.typeObjectsByName[type];
103
- result[typeObject.id] = visitAxisSingle(axis, visitor);
104
- } else result[type] = axis;
103
+ const typeObject = schema.getTypeObjectByName(type);
104
+ if (!typeObject) {
105
+ result[type] = axis;
106
+ return result;
107
+ }
108
+ result[typeObject.id] = visitAxisSingle(axis, visitor);
105
109
  return result;
106
110
  }, {}),
107
111
  visitGroupByExpression: (groupBy, fromType) => replaceNamesWithIdsInGroupByExpression(schema, groupBy, fromType)
@@ -114,10 +118,12 @@ const replaceIdsWithNamesInTimelineView = (schema, view) => {
114
118
  visitFilter: (fromType, expression) => replaceIdsWithNamesInFilter(schema, fromType, expression),
115
119
  visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression),
116
120
  visitEnums: (enums) => entries(enums).reduce((result, [typeId, axis]) => {
117
- if (Object.hasOwn(schema.typeObjectsById, typeId)) {
118
- const typeObject = schema.typeObjectsById[typeId];
119
- result[typeObject.name] = visitAxisSingle(axis, visitor);
120
- } else result[typeId] = axis;
121
+ const typeObject = schema.getTypeObjectById(typeId);
122
+ if (!typeObject) {
123
+ result[typeId] = axis;
124
+ return result;
125
+ }
126
+ result[typeObject.name] = visitAxisSingle(axis, visitor);
121
127
  return result;
122
128
  }, {}),
123
129
  visitGroupByExpression: (groupBy, fromType) => replaceIdsWithNamesInGroupByExpression(schema, groupBy, fromType)
@@ -164,11 +170,10 @@ const deleteExpressionWithNotFoundFieldsOrTypesInTimelineView = (schema, view, e
164
170
  visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression),
165
171
  visitEnums: (enums) => {
166
172
  const enumsNew = entries(enums).reduce((result, [type, axis]) => {
167
- if (Object.hasOwn(schema.typeObjectsByName, type)) {
168
- const typeObject = schema.typeObjectsByName[type];
169
- const axisResult = visitAxisSingle(axis, visitor);
170
- if (axisResult) result[typeObject.name] = axisResult;
171
- }
173
+ const typeObject = schema.getTypeObjectByName(type);
174
+ if (!typeObject) return result;
175
+ const axisResult = visitAxisSingle(axis, visitor);
176
+ if (axisResult) result[typeObject.name] = axisResult;
172
177
  return result;
173
178
  }, {});
174
179
  return isEmpty(enumsNew) ? null : enumsNew;
@@ -1,7 +1,8 @@
1
+ import { AVATAR_EXTENSION_FIELD } from "../field-utils/avatar.js";
1
2
  import { REMOVE } from "./utils.js";
2
3
  import { getFieldObjectsByFieldExpression } from "@fibery/expression-utils/src/utils";
3
4
  //#region src/private/units.ts
4
- const getField = (schema, fromType, field) => Object.hasOwn(schema.typeObjectsByName, fromType) && Object.hasOwn(schema.typeObjectsByName[fromType].fieldObjectsByName, field) ? schema.typeObjectsByName[fromType].fieldObjectsByName[field] : void 0;
5
+ const getField = (schema, fromType, field) => schema.getTypeObjectByName(fromType)?.getFieldObjectByName(field);
5
6
  const getFieldType = (schema, fromType, field) => getField(schema, fromType, field)?.type;
6
7
  const getFieldMeta = (schema, fromType, field) => getField(schema, fromType, field)?.rawMeta;
7
8
  const getFieldByExpression = (schema, fromType, expression) => {
@@ -52,7 +53,7 @@ const migrateUnit = (schema, fromType, unit, units, opts = migrateUnitOptsDefaul
52
53
  type: "email"
53
54
  };
54
55
  }
55
- if (unit.type === "text" || unit.type === "email" || unit.type === "phone" || unit.type === "url") {
56
+ if ((unit.type === "text" || unit.type === "email" || unit.type === "phone" || unit.type === "url") && "expression" in unit && unit.expression) {
56
57
  const [field] = unit.expression;
57
58
  if (getFieldType(schema, fromType, field) === "fibery/text") return {
58
59
  ...unit,
@@ -60,6 +61,16 @@ const migrateUnit = (schema, fromType, unit, units, opts = migrateUnitOptsDefaul
60
61
  type: getUnitTypeForTextField(getFieldMeta(schema, fromType, field))
61
62
  };
62
63
  }
64
+ if (unit.type === "icon-button" && "expression" in unit && unit.expression) {
65
+ const [field] = unit.expression;
66
+ if (getFieldType(schema, fromType, field) === "fibery/text") {
67
+ if (getUnitTypeForTextField(getFieldMeta(schema, fromType, field)) === "text") return {
68
+ ...unit,
69
+ kind: unit.kind || "field",
70
+ type: "text"
71
+ };
72
+ }
73
+ }
63
74
  if (unit.type === "files-collection") {
64
75
  const [field] = unit.expression;
65
76
  if (getFieldType(schema, fromType, field) === "fibery/file") return {
@@ -68,14 +79,16 @@ const migrateUnit = (schema, fromType, unit, units, opts = migrateUnitOptsDefaul
68
79
  type: opts.migrateFileCollectionUnit ? "file-collection-count" : "collection-count"
69
80
  };
70
81
  }
71
- if (unit.type === "avatar" && !unit.expression) {
72
- const isAvatarExntensionEnabled = schema.typeObjectsByName[fromType]?.installedMixins.has("avatar/avatar-mixin");
73
- const hasAvatarExntensionField = getFieldType(schema, fromType, "avatar/avatars") === "fibery/file";
74
- if (isAvatarExntensionEnabled && hasAvatarExntensionField) return {
75
- ...unit,
76
- expression: ["avatar/avatars"],
77
- kind: unit.kind || "field"
78
- };
82
+ if (unit.type === "avatar") {
83
+ if (unit.kind === "db" || !unit.expression) {
84
+ const isAvatarExntensionEnabled = schema.getTypeObjectByName(fromType)?.installedMixins.has("avatar/avatar-mixin");
85
+ const hasAvatarExntensionField = getFieldType(schema, fromType, AVATAR_EXTENSION_FIELD) === "fibery/file";
86
+ if (isAvatarExntensionEnabled && hasAvatarExntensionField) return {
87
+ ...unit,
88
+ expression: unit.expression ?? ["avatar/avatars"],
89
+ kind: "field"
90
+ };
91
+ }
79
92
  }
80
93
  if (opts.migrateFileCollectionUnit && unit.type === "collection-count") {
81
94
  const [field] = unit.expression;
@@ -97,7 +110,7 @@ const fixViewUnit = (schema, fromType, unit, units, { unitDefinitions, getDefaul
97
110
  const expression = expressionFrom(unit) ?? [];
98
111
  const fieldObject = getFieldByExpression(schema, fromType, expression);
99
112
  if (fieldObject) {
100
- const typeObject = schema.typeObjectsByName[fromType];
113
+ const typeObject = schema.getTypeObjectByName(fromType);
101
114
  const parentFieldObjects = typeObject && expression.length > 1 ? getFieldObjectsByFieldExpression({
102
115
  typeObject,
103
116
  expression
@@ -30,29 +30,24 @@ const deleteExpressionWithNotFoundFieldsOrTypesInFilter = (schema, fromType, fil
30
30
  };
31
31
  const deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression = (schema, queryExpression) => {
32
32
  const { "q/from": fromExpression, "q/where": whereExpression, "q/order-by": orderByExpression } = queryExpression;
33
- if (Object.hasOwn(schema.typeObjectsByName, fromExpression)) {
34
- const typeObject = schema.typeObjectsByName[fromExpression];
35
- return pickBy({
36
- ...queryExpression,
37
- ...whereExpression ? { "q/where": deleteExpressionsWithNotFoundFieldsVisitor(typeObject).visitExpression(whereExpression) } : null,
38
- ...orderByExpression ? { "q/order-by": deleteExpressionsWithNotFoundFieldsVisitor(typeObject).visitOrderByExpression(orderByExpression) } : null
39
- });
40
- }
41
- return null;
33
+ const typeObject = schema.getTypeObjectByName(fromExpression);
34
+ if (!typeObject) return null;
35
+ const visitor = deleteExpressionsWithNotFoundFieldsVisitor(typeObject);
36
+ return pickBy({
37
+ ...queryExpression,
38
+ ...whereExpression ? { "q/where": visitor.visitExpression(whereExpression) } : null,
39
+ ...orderByExpression ? { "q/order-by": visitor.visitOrderByExpression(orderByExpression) } : null
40
+ });
42
41
  };
43
42
  const replaceNamesWithIdsInExpression = (schema, fromType, expression) => {
44
- if (Object.hasOwn(schema.typeObjectsByName, fromType)) {
45
- const typeObject = schema.typeObjectsByName[fromType];
46
- return replaceNamesWithIdsVisitor(typeObject).visitExpression(expression);
47
- }
48
- return expression;
43
+ const typeObject = schema.getTypeObjectByName(fromType);
44
+ if (!typeObject) return expression;
45
+ return replaceNamesWithIdsVisitor(typeObject).visitExpression(expression);
49
46
  };
50
47
  const replaceIdsWithNamesInExpression = (schema, fromTypeId, expression) => {
51
- if (Object.hasOwn(schema.typeObjectsById, fromTypeId)) {
52
- const typeObject = schema.typeObjectsById[fromTypeId];
53
- return replaceIdsWithNamesVisitor(typeObject).visitExpression(expression);
54
- }
55
- return expression;
48
+ const typeObject = schema.getTypeObjectById(fromTypeId);
49
+ if (!typeObject) return expression;
50
+ return replaceIdsWithNamesVisitor(typeObject).visitExpression(expression);
56
51
  };
57
52
  const visitViewUnit = (fromType, unit, visitor) => {
58
53
  if (unit.kind === "user-button") return unit;
@@ -69,16 +64,15 @@ const visitContextExpression = (fromType, contextExpression, visitor) => {
69
64
  };
70
65
  const replaceIdsWithNamesInQueryExpression = (schema, queryExpression) => {
71
66
  const { "q/from": fromExpression, "q/where": whereExpression, "q/order-by": orderByExpression } = queryExpression;
72
- if (Object.hasOwn(schema.typeObjectsById, fromExpression)) {
73
- const typeObject = schema.typeObjectsById[fromExpression];
74
- return {
75
- ...queryExpression,
76
- "q/from": typeObject.name,
77
- ...whereExpression ? { "q/where": replaceIdsWithNamesVisitor(typeObject).visitExpression(whereExpression) } : null,
78
- ...orderByExpression ? { "q/order-by": replaceIdsWithNamesVisitor(typeObject).visitOrderByExpression(orderByExpression) } : null
79
- };
80
- }
81
- return queryExpression;
67
+ const typeObject = schema.getTypeObjectById(fromExpression);
68
+ if (!typeObject) return queryExpression;
69
+ const visitor = replaceIdsWithNamesVisitor(typeObject);
70
+ return {
71
+ ...queryExpression,
72
+ "q/from": typeObject.name,
73
+ ...whereExpression ? { "q/where": visitor.visitExpression(whereExpression) } : null,
74
+ ...orderByExpression ? { "q/order-by": visitor.visitOrderByExpression(orderByExpression) } : null
75
+ };
82
76
  };
83
77
  function visitFilterGroup(filter, visitExpression, _type) {
84
78
  if (filter.kind !== "group") return null;
@@ -99,38 +93,33 @@ function visitFilterGroup(filter, visitExpression, _type) {
99
93
  };
100
94
  }
101
95
  const replaceIdsWithNamesInFilter = (schema, fromType, filter) => {
102
- if (Object.hasOwn(schema.typeObjectsById, fromType)) {
103
- const typeObject = schema.typeObjectsById[fromType];
104
- return filter ? visitFilterGroup(filter, (expression) => replaceIdsWithNamesVisitor(typeObject).visitExpression(expression), "ids") : null;
105
- }
106
- return filter;
96
+ const typeObject = schema.getTypeObjectById(fromType);
97
+ if (!typeObject) return filter;
98
+ const visitor = replaceIdsWithNamesVisitor(typeObject);
99
+ return filter ? visitFilterGroup(filter, (expression) => visitor.visitExpression(expression), "ids") : null;
107
100
  };
108
101
  const replaceNamesWithIdsInFilter = (schema, fromType, filter) => {
109
- if (Object.hasOwn(schema.typeObjectsByName, fromType)) {
110
- const typeObject = schema.typeObjectsByName[fromType];
111
- return filter ? visitFilterGroup(filter, (expression) => replaceNamesWithIdsVisitor(typeObject).visitExpression(expression), "names") : null;
112
- }
113
- return filter;
102
+ const typeObject = schema.getTypeObjectByName(fromType);
103
+ if (!typeObject) return filter;
104
+ const visitor = replaceNamesWithIdsVisitor(typeObject);
105
+ return filter ? visitFilterGroup(filter, (expression) => visitor.visitExpression(expression), "names") : null;
114
106
  };
115
107
  const replaceNamesWithIdsInQueryExpression = (schema, queryExpression) => {
116
108
  const { "q/from": fromExpression, "q/where": whereExpression, "q/order-by": orderByExpression } = queryExpression;
117
- if (Object.hasOwn(schema.typeObjectsByName, fromExpression)) {
118
- const typeObject = schema.typeObjectsByName[fromExpression];
119
- return {
120
- ...queryExpression,
121
- "q/from": typeObject.id,
122
- ...whereExpression ? { "q/where": replaceNamesWithIdsVisitor(typeObject).visitExpression(whereExpression) } : null,
123
- ...orderByExpression ? { "q/order-by": replaceNamesWithIdsVisitor(typeObject).visitOrderByExpression(orderByExpression) } : null
124
- };
125
- }
126
- return queryExpression;
109
+ const typeObject = schema.getTypeObjectByName(fromExpression);
110
+ if (!typeObject) return queryExpression;
111
+ const visitor = replaceNamesWithIdsVisitor(typeObject);
112
+ return {
113
+ ...queryExpression,
114
+ "q/from": typeObject.id,
115
+ ...whereExpression ? { "q/where": visitor.visitExpression(whereExpression) } : null,
116
+ ...orderByExpression ? { "q/order-by": visitor.visitOrderByExpression(orderByExpression) } : null
117
+ };
127
118
  };
128
119
  const deleteExpressionWithNotFoundFieldsOrTypesInExpression = (schema, fromType, expression) => {
129
- if (Object.hasOwn(schema.typeObjectsByName, fromType)) {
130
- const typeObject = schema.typeObjectsByName[fromType];
131
- return deleteExpressionsWithNotFoundFieldsVisitor(typeObject).visitExpression(expression);
132
- }
133
- return null;
120
+ const typeObject = schema.getTypeObjectByName(fromType);
121
+ if (!typeObject) return null;
122
+ return deleteExpressionsWithNotFoundFieldsVisitor(typeObject).visitExpression(expression);
134
123
  };
135
124
  const resetContextExpressionIfBroken = (schema, fromType, expression, defaultExpression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression) || defaultExpression;
136
125
  const isUnitExpressionValid = (unit) => {
@@ -142,12 +131,10 @@ const isUnitExpressionValid = (unit) => {
142
131
  };
143
132
  const getFieldObjectsById = (smartFolder, schema) => {
144
133
  return smartFolder["fibery/meta"].items.map((item) => item.query["q/from"]).reduce((acc, type) => {
145
- if (!Object.hasOwn(schema.typeObjectsById, type)) return acc;
146
- const fieldObjects = schema.typeObjectsById[type].fieldObjectsById;
147
- return {
148
- ...acc,
149
- ...fieldObjects
150
- };
134
+ const typeObject = schema.getTypeObjectById(type);
135
+ if (!typeObject) return acc;
136
+ for (const fieldObject of typeObject.fieldObjects) acc[fieldObject.id] = fieldObject;
137
+ return acc;
151
138
  }, {});
152
139
  };
153
140
  const replaceIdsWithNamesInUnitGroupKey = (unitGroupKey, fieldObjectsById) => {
@@ -169,10 +156,11 @@ const replaceNamesWithIdsInUnitGroupKey = (unitGroupKey, schema) => {
169
156
  if (!name) return keyPart;
170
157
  const [type, field] = name.split(":");
171
158
  if (!field) return keyPart;
172
- if (!Object.hasOwn(schema.typeObjectsByName, type)) return keyPart;
173
- const typeObject = schema.typeObjectsByName[type];
174
- if (!Object.hasOwn(typeObject.fieldObjectsByName, field)) return keyPart;
175
- return `${unitType}_${typeObject.fieldObjectsByName[field].id}`;
159
+ const typeObject = schema.getTypeObjectByName(type);
160
+ if (!typeObject) return keyPart;
161
+ const fieldObject = typeObject.getFieldObjectByName(field);
162
+ if (!fieldObject) return keyPart;
163
+ return `${unitType}_${fieldObject.id}`;
176
164
  }).filter(Boolean).join("|");
177
165
  };
178
166
  //#endregion
@@ -1,4 +1,4 @@
1
- import { getAvatarSelectQuery, isAvatarExtensionEnabledType, isAvatarExtensionField } from "../field-utils/avatar.js";
1
+ import { AVATAR_EXTENSION_FIELD, getAvatarSelectQuery, isAvatarExtensionEnabledType, isAvatarExtensionField } from "../field-utils/avatar.js";
2
2
  import { generateAccessCheckQueryExpression } from "../unit-utils/access.js";
3
3
  import { calculateUnitExpressionErrors, canEditFieldExpression } from "../unit-utils/common.js";
4
4
  import { getReferenceExportValue } from "../unit-utils/get-export-value.js";
@@ -19,10 +19,11 @@ const Avatar = {
19
19
  getLabel({ typeObject, unit }) {
20
20
  const { expression } = unit;
21
21
  if (expression) {
22
- if (isAvatarExtensionEnabledType(getFieldObjectByFieldExpression({
22
+ const fieldObject = getFieldObjectByFieldExpression({
23
23
  typeObject,
24
24
  expression
25
- }).typeObject)) return `Avatar of ${getFieldLabel({
25
+ });
26
+ if (isAvatarExtensionEnabledType(fieldObject.typeObject)) return `Avatar of ${getFieldLabel({
26
27
  typeObject,
27
28
  unit
28
29
  })}`;
@@ -32,7 +33,8 @@ const Avatar = {
32
33
  makeUnit(args) {
33
34
  if (!args) return {
34
35
  type,
35
- kind: "db"
36
+ kind: "field",
37
+ expression: [AVATAR_EXTENSION_FIELD]
36
38
  };
37
39
  assertIsValidExpression(args.expression);
38
40
  return {
@@ -57,7 +59,7 @@ const Avatar = {
57
59
  }),
58
60
  getAvatarSelectQuery({ typeObject: terminalFieldObject.typeObject })
59
61
  ].filter(truthy)));
60
- return denormalizeSelect([...expression].reverse().reduce((inner, field, reversedIndex) => {
62
+ const nested = [...expression].reverse().reduce((inner, field, reversedIndex) => {
61
63
  const originalIndex = expression.length - 1 - reversedIndex;
62
64
  if (!(originalIndex === expression.length - 1)) {
63
65
  const { idField } = fieldObjects[originalIndex].typeObject;
@@ -68,7 +70,8 @@ const Avatar = {
68
70
  return { [field]: innerWithId };
69
71
  }
70
72
  return { [field]: inner };
71
- }, innerSelect));
73
+ }, innerSelect);
74
+ return denormalizeSelect(nested);
72
75
  },
73
76
  calculateErrors: calculateUnitExpressionErrors,
74
77
  getExportValue: ({ typeObject, unit, object }) => {
@@ -14,10 +14,11 @@ const CommentsList = {
14
14
  getLabel: getFieldLabel,
15
15
  getQuerySelect: ({ typeObject, unit }) => {
16
16
  const { expression } = unit;
17
- return getQuerySelect(getFieldObjectByFieldExpression({
17
+ const fieldObject = getFieldObjectByFieldExpression({
18
18
  typeObject,
19
19
  expression
20
- }));
20
+ });
21
+ return getQuerySelect(fieldObject);
21
22
  },
22
23
  calculateErrors: calculateUnitExpressionErrors,
23
24
  getExportValue,
@@ -21,11 +21,12 @@ const FileCollectionCount = {
21
21
  expression
22
22
  });
23
23
  const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
24
- return denormalizeSelect(wrapNormalizedInExpression({
24
+ const collectionNormalized = {
25
25
  "q/from": null,
26
26
  "q/limit": "q/no-limit",
27
27
  "q/select": normalizeSelect(getFilesSelect(terminalFieldObject))
28
- }, fieldObjects, expression));
28
+ };
29
+ return denormalizeSelect(wrapNormalizedInExpression(collectionNormalized, fieldObjects, expression));
29
30
  },
30
31
  getExportValue,
31
32
  canExport: () => true
@@ -21,11 +21,12 @@ const FileCompactCollection = {
21
21
  expression
22
22
  });
23
23
  const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
24
- return denormalizeSelect(wrapNormalizedInExpression({
24
+ const collectionNormalized = {
25
25
  "q/from": null,
26
26
  "q/limit": "q/no-limit",
27
27
  "q/select": normalizeSelect(getFilesSelect(terminalFieldObject))
28
- }, fieldObjects, expression));
28
+ };
29
+ return denormalizeSelect(wrapNormalizedInExpression(collectionNormalized, fieldObjects, expression));
29
30
  },
30
31
  getExportValue,
31
32
  canExport: () => true
@@ -29,7 +29,8 @@ const FileCompactReference = {
29
29
  expression
30
30
  });
31
31
  const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
32
- return denormalizeSelect(wrapNormalizedInExpression(getReferenceFieldNormalizedSelectClause(terminalFieldObject, expression), fieldObjects, expression));
32
+ const innerNormalized = getReferenceFieldNormalizedSelectClause(terminalFieldObject, expression);
33
+ return denormalizeSelect(wrapNormalizedInExpression(innerNormalized, fieldObjects, expression));
33
34
  },
34
35
  calculateErrors({ typeObject, unit }) {
35
36
  return calculateUnitExpressionErrors({
@@ -21,7 +21,8 @@ const FileReference = {
21
21
  expression
22
22
  });
23
23
  const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
24
- return denormalizeSelect(wrapNormalizedInExpression(normalizeSelect(getFilesSelect(terminalFieldObject)), fieldObjects, expression));
24
+ const innerNormalized = normalizeSelect(getFilesSelect(terminalFieldObject));
25
+ return denormalizeSelect(wrapNormalizedInExpression(innerNormalized, fieldObjects, expression));
25
26
  },
26
27
  getExportValue,
27
28
  canExport: () => true
@@ -21,11 +21,12 @@ const FilesGallery = {
21
21
  expression
22
22
  });
23
23
  const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
24
- return denormalizeSelect(wrapNormalizedInExpression({
24
+ const collectionNormalized = {
25
25
  "q/from": null,
26
26
  "q/limit": "q/no-limit",
27
27
  "q/select": normalizeSelect(getFilesSelect(terminalFieldObject))
28
- }, fieldObjects, expression));
28
+ };
29
+ return denormalizeSelect(wrapNormalizedInExpression(collectionNormalized, fieldObjects, expression));
29
30
  },
30
31
  getExportValue,
31
32
  canExport: () => true
@@ -21,7 +21,8 @@ const FileLListItem = {
21
21
  expression
22
22
  });
23
23
  const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
24
- return denormalizeSelect(wrapNormalizedInExpression(normalizeSelect(getFilesSelect(terminalFieldObject)), fieldObjects, expression));
24
+ const innerNormalized = normalizeSelect(getFilesSelect(terminalFieldObject));
25
+ return denormalizeSelect(wrapNormalizedInExpression(innerNormalized, fieldObjects, expression));
25
26
  },
26
27
  getExportValue,
27
28
  canExport: () => true
@@ -21,11 +21,12 @@ const FileLList = {
21
21
  expression
22
22
  });
23
23
  const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
24
- return denormalizeSelect(wrapNormalizedInExpression({
24
+ const collectionNormalized = {
25
25
  "q/from": null,
26
26
  "q/limit": "q/no-limit",
27
27
  "q/select": normalizeSelect(getFilesSelect(terminalFieldObject))
28
- }, fieldObjects, expression));
28
+ };
29
+ return denormalizeSelect(wrapNormalizedInExpression(collectionNormalized, fieldObjects, expression));
29
30
  },
30
31
  getExportValue,
31
32
  canExport: () => true
@@ -21,7 +21,8 @@ const FileListItem = {
21
21
  expression
22
22
  });
23
23
  const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
24
- return denormalizeSelect(wrapNormalizedInExpression(normalizeSelect(getFilesSelect(terminalFieldObject)), fieldObjects, expression));
24
+ const innerNormalized = normalizeSelect(getFilesSelect(terminalFieldObject));
25
+ return denormalizeSelect(wrapNormalizedInExpression(innerNormalized, fieldObjects, expression));
25
26
  },
26
27
  getExportValue,
27
28
  canExport: () => true
@@ -21,11 +21,12 @@ const FileList = {
21
21
  expression
22
22
  });
23
23
  const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
24
- return denormalizeSelect(wrapNormalizedInExpression({
24
+ const collectionNormalized = {
25
25
  "q/from": null,
26
26
  "q/limit": "q/no-limit",
27
27
  "q/select": normalizeSelect(getFilesSelect(terminalFieldObject))
28
- }, fieldObjects, expression));
28
+ };
29
+ return denormalizeSelect(wrapNormalizedInExpression(collectionNormalized, fieldObjects, expression));
29
30
  },
30
31
  getExportValue,
31
32
  canExport: () => true
@@ -12,11 +12,12 @@ const ReferenceCollection = {
12
12
  getLabel: getFieldLabel,
13
13
  makeUnit: makeUnitMethod(type),
14
14
  getQuerySelect({ typeObject, unit: { expression } }) {
15
+ const fieldObjects = getFieldObjectsByFieldExpression({
16
+ typeObject,
17
+ expression
18
+ });
15
19
  return calculateReferenceCollectionQuery({
16
- fieldObjects: getFieldObjectsByFieldExpression({
17
- typeObject,
18
- expression
19
- }),
20
+ fieldObjects,
20
21
  expression,
21
22
  limit: REFERENCE_COLLECTION_LIMIT
22
23
  });
@@ -29,7 +29,7 @@ const Reference = {
29
29
  });
30
30
  const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
31
31
  const innerNormalized = getReferenceFieldNormalizedSelectClause(terminalFieldObject, expression);
32
- return denormalizeSelect([...expression].reverse().reduce((inner, field, reversedIndex) => {
32
+ const nested = [...expression].reverse().reduce((inner, field, reversedIndex) => {
33
33
  const originalIndex = expression.length - 1 - reversedIndex;
34
34
  if (!(originalIndex === expression.length - 1)) {
35
35
  const { idField } = fieldObjects[originalIndex].typeObject;
@@ -40,7 +40,8 @@ const Reference = {
40
40
  return { [field]: innerWithId };
41
41
  }
42
42
  return { [field]: inner };
43
- }, innerNormalized));
43
+ }, innerNormalized);
44
+ return denormalizeSelect(nested);
44
45
  },
45
46
  calculateErrors({ typeObject, unit }) {
46
47
  const errors = calculateUnitExpressionErrors({
@@ -12,8 +12,8 @@ const getWorkflowQuery = ({ typeObject }) => {
12
12
  const getEnumIconColorQuery = ({ typeObject, contextPath = [] }) => {
13
13
  if (!typeObject.isEnum) return {};
14
14
  const select = { "?accessToIcon": ["q/access?", [...contextPath, "enum/icon"]] };
15
- if (Object.hasOwn(typeObject.fieldObjectsByName, "enum/color")) select["enum/color"] = "enum/color";
16
- if (Object.hasOwn(typeObject.fieldObjectsByName, "enum/icon")) select["enum/icon"] = "enum/icon";
15
+ if (typeObject.getFieldObjectByName("enum/color")) select["enum/color"] = "enum/color";
16
+ if (typeObject.getFieldObjectByName("enum/icon")) select["enum/icon"] = "enum/icon";
17
17
  return select;
18
18
  };
19
19
  const getEnumNumberFieldQuery = (typeObject) => {
@@ -2,6 +2,6 @@ import { Schema } from "@fibery/schema";
2
2
  //#region src/unit-utils/schema.d.ts
3
3
  declare const extractTypePart: (type: string) => string;
4
4
  declare const extractTypeNamespacePart: (type: string) => string;
5
- declare const getTypeById: (schema: Schema, id: string) => import("@fibery/schema").TypeObject | undefined;
5
+ declare const getTypeById: (schema: Schema, id: string) => import("@fibery/schema").TypeObject | null;
6
6
  //#endregion
7
7
  export { extractTypeNamespacePart, extractTypePart, getTypeById };
@@ -3,7 +3,7 @@ import { parseType } from "@fibery/schema";
3
3
  const extractTypePart = (type) => parseType(type).name;
4
4
  const extractTypeNamespacePart = (type) => parseType(type).namespace;
5
5
  const getTypeById = (schema, id) => {
6
- return Object.hasOwn(schema.typeObjectsById, id) ? schema.typeObjectsById[id] : void 0;
6
+ return schema.getTypeObjectById(id);
7
7
  };
8
8
  //#endregion
9
9
  export { extractTypeNamespacePart, extractTypePart, getTypeById };
@@ -22,7 +22,7 @@ const getDefaultUnits = () => {
22
22
  };
23
23
  const getDefaultLaneUnits = (typeObject) => {
24
24
  const { Title, Avatar, Emoji, TypeBadgeAbbr } = unit_definitions_exports;
25
- return [Title && Title.makeUnit(), typeObject && isAvatarExtensionEnabledType(typeObject) && Avatar && Avatar.makeUnit() || typeObject.isEnum && Object.hasOwn(typeObject.fieldObjectsByName, "enum/icon") && Emoji && Emoji.makeUnit({ expression: ["enum/icon"] }) || TypeBadgeAbbr && TypeBadgeAbbr.makeUnit()].filter(Boolean);
25
+ return [Title && Title.makeUnit(), typeObject && isAvatarExtensionEnabledType(typeObject) && Avatar && Avatar.makeUnit() || typeObject.isEnum && Boolean(typeObject.getFieldObjectByName("enum/icon")) && Emoji && Emoji.makeUnit({ expression: ["enum/icon"] }) || TypeBadgeAbbr && TypeBadgeAbbr.makeUnit()].filter(Boolean);
26
26
  };
27
27
  //#endregion
28
28
  export { gantt_exports, getCardUnitsSelect, getDefaultLaneUnits, getDefaultUnits, getHardcodedUnitsForView, getTypeUnits, getUnitLabel, getUnitName, getUnitsForField, getUnitsForType, getUnitsForTypePerField };
@@ -180,13 +180,14 @@ const makeUnitDefinitionsFactory = (allUnitDefinitions) => {
180
180
  * @returns flat list of all units for given type
181
181
  */
182
182
  function getUnitsForType(typeObject, options = {}) {
183
- return sortBy(flatMap(typeObject.fieldObjects.filter((x) => !x.isHidden), (fieldObject) => getUnitsForField(fieldObject, options).map((unit) => ({
183
+ const collection = flatMap(typeObject.fieldObjects.filter((x) => !x.isHidden), (fieldObject) => getUnitsForField(fieldObject, options).map((unit) => ({
184
184
  unit,
185
185
  fieldObject
186
186
  }))).concat(getTypeUnits().map((unit) => ({
187
187
  unit,
188
188
  fieldObject: typeObject.titleFieldObject
189
- }))), ({ unit }) => {
189
+ })));
190
+ return sortBy(collection, ({ unit }) => {
190
191
  const index = staticUnitsTypeOrder.indexOf(unit.type);
191
192
  return index === -1 ? staticUnitsTypeOrder.length : index;
192
193
  });
@@ -214,10 +215,10 @@ const makeUnitDefinitionsFactory = (allUnitDefinitions) => {
214
215
  return [
215
216
  TypeIcon && TypeIcon.makeUnit(),
216
217
  Title && Title.makeUnit(),
217
- ...getUnitsForField(typeObject.fieldObjectsByName["fibery/creation-date"]),
218
- ...getUnitsForField(typeObject.fieldObjectsByName["fibery/container-app"]),
219
- ...getUnitsForField(typeObject.fieldObjectsByName["fibery/container-entity-id"]),
220
- ...getUnitsForField(typeObject.fieldObjectsByName["fibery/container-entity-type"])
218
+ ...getUnitsForField(typeObject.getFieldObjectByNameOrThrow("fibery/creation-date")),
219
+ ...getUnitsForField(typeObject.getFieldObjectByNameOrThrow("fibery/container-app")),
220
+ ...getUnitsForField(typeObject.getFieldObjectByNameOrThrow("fibery/container-entity-id")),
221
+ ...getUnitsForField(typeObject.getFieldObjectByNameOrThrow("fibery/container-entity-type"))
221
222
  ].filter(Boolean);
222
223
  };
223
224
  const unitDefinitionsByTypeLookup = mapValues(groupBy(allUnitDefinitions, (x) => x.type), (value) => single(value));
@@ -240,7 +241,7 @@ const makeUnitDefinitionsFactory = (allUnitDefinitions) => {
240
241
  return NotFound;
241
242
  };
242
243
  const getCardUnitsSelect = ({ schema, typeObject, units }) => {
243
- return mergeDenormalizedSelects(units.filter((unit) => {
244
+ const selects = units.filter((unit) => {
244
245
  return isUnitEnabled(unit) && unit.kind !== "user-button" && !unit.expression?.includes("documents/documents") && !unit.expression?.includes("whiteboards/whiteboards");
245
246
  }).map((unit) => {
246
247
  if (calculateUnitExpressionErrors({
@@ -254,7 +255,8 @@ const makeUnitDefinitionsFactory = (allUnitDefinitions) => {
254
255
  });
255
256
  assert(isPlainObject(select), "getQuerySelect must return object-shaped select");
256
257
  return select;
257
- }));
258
+ });
259
+ return mergeDenormalizedSelects(selects);
258
260
  };
259
261
  return {
260
262
  getTypeUnits,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fibery/views",
3
- "version": "20.0.2",
3
+ "version": "21.0.0",
4
4
  "description": "Operations on view objects",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Fibery",
@@ -33,14 +33,14 @@
33
33
  "date-fns": "2.29.2",
34
34
  "lodash": "4.17.21",
35
35
  "moment": "2.29.4",
36
- "@fibery/expression-utils": "10.0.2",
37
- "@fibery/helpers": "3.2.1",
38
- "@fibery/query-utils": "2.0.2",
39
- "@fibery/schema": "10.3.1"
36
+ "@fibery/expression-utils": "11.0.0",
37
+ "@fibery/query-utils": "3.0.0",
38
+ "@fibery/helpers": "3.3.1",
39
+ "@fibery/schema": "11.0.0"
40
40
  },
41
41
  "peerDependencies": {
42
- "@fibery/expression-utils": "^10.0.2",
43
- "@fibery/schema": "^10.3.1",
42
+ "@fibery/expression-utils": "^11.0.0",
43
+ "@fibery/schema": "^11.0.0",
44
44
  "immutability-helper": "^2.4.0",
45
45
  "lodash": "4.17.21"
46
46
  }