@fibery/views 19.0.0 → 19.0.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.
Files changed (53) hide show
  1. package/lib/src/index.d.ts +28 -16
  2. package/lib/src/index.js +1 -1
  3. package/lib/src/private/board.d.ts +15 -11
  4. package/lib/src/private/board.js +8 -7
  5. package/lib/src/private/calendar.d.ts +14 -10
  6. package/lib/src/private/calendar.js +4 -3
  7. package/lib/src/private/feed.d.ts +14 -10
  8. package/lib/src/private/feed.js +4 -3
  9. package/lib/src/private/form.d.ts +25 -3
  10. package/lib/src/private/form.js +3 -3
  11. package/lib/src/private/map.d.ts +14 -10
  12. package/lib/src/private/map.js +4 -3
  13. package/lib/src/private/smart-folder.d.ts +23 -15
  14. package/lib/src/private/smart-folder.js +16 -13
  15. package/lib/src/private/timeline.d.ts +39 -10
  16. package/lib/src/private/timeline.js +8 -6
  17. package/lib/src/private/units.d.ts +10 -6
  18. package/lib/src/private/units.js +32 -24
  19. package/lib/src/private/utils.d.ts +64 -17
  20. package/lib/src/private/utils.js +26 -20
  21. package/lib/src/truthy.d.ts +1 -0
  22. package/lib/src/truthy.js +7 -0
  23. package/lib/src/unit-definitions/avatar-collection.js +2 -3
  24. package/lib/src/unit-definitions/avatar.js +3 -5
  25. package/lib/src/unit-definitions/collection-count.js +4 -2
  26. package/lib/src/unit-definitions/file-collection-count.js +9 -7
  27. package/lib/src/unit-definitions/file-compact-collection.js +9 -7
  28. package/lib/src/unit-definitions/file-compact-reference.js +2 -11
  29. package/lib/src/unit-definitions/file-reference.js +6 -4
  30. package/lib/src/unit-definitions/files-gallery.js +9 -7
  31. package/lib/src/unit-definitions/files-l-list-item.js +6 -4
  32. package/lib/src/unit-definitions/files-l-list.js +9 -7
  33. package/lib/src/unit-definitions/files-list-item.js +6 -4
  34. package/lib/src/unit-definitions/files-list.js +9 -7
  35. package/lib/src/unit-definitions/number.js +2 -4
  36. package/lib/src/unit-definitions/progress-bar.js +1 -4
  37. package/lib/src/unit-definitions/rich-text-snippet.d.ts +1 -0
  38. package/lib/src/unit-definitions/rich-text-snippet.js +6 -11
  39. package/lib/src/unit-utils/get-export-value.js +2 -1
  40. package/lib/src/unit-utils/wrap-normalized-in-expression.d.ts +3 -0
  41. package/lib/src/unit-utils/wrap-normalized-in-expression.js +14 -0
  42. package/lib/src/units/board.d.ts +4 -4
  43. package/lib/src/units/canvas/index.d.ts +4 -4
  44. package/lib/src/units/default.d.ts +4 -4
  45. package/lib/src/units/gantt.d.ts +4 -4
  46. package/lib/src/units/grid.d.ts +4 -4
  47. package/lib/src/units/list.d.ts +4 -4
  48. package/lib/src/units/make-factory.d.ts +2 -3
  49. package/lib/src/units/make-factory.js +18 -7
  50. package/lib/src/units/types.d.ts +1 -1
  51. package/package.json +18 -18
  52. package/lib/jest.config.cjs +0 -34
  53. package/lib/jest.config.d.cts +0 -3
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.enableHideWhenEmptyForCheckedEditableUnit = exports.fixViewUnit = void 0;
4
- const utils_1 = require("./utils");
4
+ const utils_1 = require("@fibery/expression-utils/src/utils");
5
+ const utils_2 = require("./utils");
5
6
  const getField = (schema, fromType, field) => Object.hasOwn(schema.typeObjectsByName, fromType) &&
6
7
  Object.hasOwn(schema.typeObjectsByName[fromType].fieldObjectsByName, field)
7
8
  ? schema.typeObjectsByName[fromType].fieldObjectsByName[field]
@@ -18,7 +19,7 @@ const getFieldByExpression = (schema, fromType, expression) => {
18
19
  }
19
20
  currentType = fieldObject.type;
20
21
  }
21
- return fieldObject;
22
+ return fieldObject ?? null;
22
23
  };
23
24
  const getUnitTypeForTextField = (fieldMeta) => {
24
25
  switch (fieldMeta["ui/type"]) {
@@ -45,24 +46,23 @@ const migrateUnitOptsDefault = {
45
46
  migrateFileCollectionUnit: true,
46
47
  };
47
48
  const migrateUnit = (schema, fromType, unit, units, opts = migrateUnitOptsDefault) => {
48
- const { type, expression } = unit;
49
49
  const kind = unit.kind || getUnitKind(unit);
50
- if (type === "date-time") {
50
+ if (unit.type === "date-time") {
51
51
  return {
52
52
  ...unit,
53
53
  kind,
54
54
  type: "date",
55
55
  };
56
56
  }
57
- if (type === "date-time-range") {
57
+ if (unit.type === "date-time-range") {
58
58
  return {
59
59
  ...unit,
60
60
  kind,
61
61
  type: "date-range",
62
62
  };
63
63
  }
64
- if (type === "text") {
65
- const [field] = expression;
64
+ if (unit.type === "text") {
65
+ const [field] = unit.expression;
66
66
  const fieldType = getFieldType(schema, fromType, field);
67
67
  if (fieldType === "fibery/email") {
68
68
  return {
@@ -72,8 +72,8 @@ const migrateUnit = (schema, fromType, unit, units, opts = migrateUnitOptsDefaul
72
72
  };
73
73
  }
74
74
  }
75
- if (["text", "email", "phone", "url"].includes(type)) {
76
- const [field] = expression;
75
+ if (unit.type === "text" || unit.type === "email" || unit.type === "phone" || unit.type === "url") {
76
+ const [field] = unit.expression;
77
77
  if (getFieldType(schema, fromType, field) === "fibery/text") {
78
78
  return {
79
79
  ...unit,
@@ -82,8 +82,8 @@ const migrateUnit = (schema, fromType, unit, units, opts = migrateUnitOptsDefaul
82
82
  };
83
83
  }
84
84
  }
85
- if (type === "files-collection") {
86
- const [field] = expression;
85
+ if (unit.type === "files-collection") {
86
+ const [field] = unit.expression;
87
87
  if (getFieldType(schema, fromType, field) === "fibery/file") {
88
88
  return {
89
89
  ...unit,
@@ -92,7 +92,7 @@ const migrateUnit = (schema, fromType, unit, units, opts = migrateUnitOptsDefaul
92
92
  };
93
93
  }
94
94
  }
95
- if (type === "avatar" && !expression) {
95
+ if (unit.type === "avatar" && !unit.expression) {
96
96
  const isAvatarExntensionEnabled = schema.typeObjectsByName[fromType]?.installedMixins.has("avatar/avatar-mixin");
97
97
  const hasAvatarExntensionField = getFieldType(schema, fromType, "avatar/avatars") === "fibery/file";
98
98
  if (isAvatarExntensionEnabled && hasAvatarExntensionField) {
@@ -103,8 +103,8 @@ const migrateUnit = (schema, fromType, unit, units, opts = migrateUnitOptsDefaul
103
103
  };
104
104
  }
105
105
  }
106
- if (opts.migrateFileCollectionUnit && type === "collection-count") {
107
- const [field] = expression;
106
+ if (opts.migrateFileCollectionUnit && unit.type === "collection-count") {
107
+ const [field] = unit.expression;
108
108
  const fieldObject = getField(schema, fromType, field);
109
109
  if (fieldObject?.type === "fibery/file" && fieldObject?.isCollection) {
110
110
  return {
@@ -116,32 +116,40 @@ const migrateUnit = (schema, fromType, unit, units, opts = migrateUnitOptsDefaul
116
116
  }
117
117
  return { ...unit, kind };
118
118
  };
119
- const fixViewUnit = (schema, fromType, unit, units, { unitDefinitions, getDefaultUnitTypeForField, migrateFileCollectionUnit = true }) => {
119
+ const expressionFrom = (unit) => unit.expression;
120
+ const fixViewUnit = (schema, fromType, unit, units, { unitDefinitions, getDefaultUnitTypeForField, migrateFileCollectionUnit = true, }) => {
120
121
  const migrated = migrateUnit(schema, fromType, unit, units, { migrateFileCollectionUnit });
121
- const fieldObject = getFieldByExpression(schema, fromType, unit.expression ?? []);
122
+ const expression = expressionFrom(unit) ?? [];
123
+ const fieldObject = getFieldByExpression(schema, fromType, expression);
122
124
  if (fieldObject) {
123
- const allowedUnits = unitDefinitions.getUnitsForField(fieldObject, {
124
- depth: unit.expression?.length,
125
- });
125
+ const typeObject = schema.typeObjectsByName[fromType];
126
+ const parentFieldObjects = typeObject && expression.length > 1
127
+ ? (0, utils_1.getFieldObjectsByFieldExpression)({ typeObject, expression }).slice(0, -1)
128
+ : [];
129
+ const allowedUnits = unitDefinitions.getUnitsForField(fieldObject, { parentFieldObjects });
126
130
  if (allowedUnits.some((u) => u.type === migrated.type)) {
127
131
  return migrated;
128
132
  }
129
133
  else {
130
134
  if (unit.checked) {
131
- const otherUnitsForField = units.filter((u) => u !== unit && u.expression && unit.expression && u.expression.join("/") === unit.expression.join("/"));
135
+ const otherUnitsForField = units.filter((u) => {
136
+ const uExpression = expressionFrom(u);
137
+ return u !== unit && uExpression && expressionFrom(unit) && uExpression.join("/") === expression.join("/");
138
+ });
132
139
  const hasEnabledUnitForField = otherUnitsForField.some((u) => u.checked);
133
140
  if (hasEnabledUnitForField) {
134
- return utils_1.REMOVE;
141
+ return utils_2.REMOVE;
135
142
  }
136
143
  const defaultUnitType = getDefaultUnitTypeForField(fieldObject, allowedUnits);
137
- const defaultUnit = (defaultUnitType && otherUnitsForField.find((u) => u.type === defaultUnitType)) || otherUnitsForField[0];
144
+ const defaultUnit = (defaultUnitType && otherUnitsForField.find((u) => u.type === defaultUnitType)) ||
145
+ otherUnitsForField[0];
138
146
  if (defaultUnit) {
139
147
  defaultUnit.checked = true;
140
- return utils_1.REMOVE;
148
+ return utils_2.REMOVE;
141
149
  }
142
150
  }
143
151
  else {
144
- return utils_1.REMOVE;
152
+ return utils_2.REMOVE;
145
153
  }
146
154
  }
147
155
  }
@@ -1,17 +1,64 @@
1
- export const REMOVE: unique symbol;
2
- export function deleteExpressionWithNotFoundFieldsOrTypesInFilter(schema: any, fromType: any, filter: any): any;
3
- export function deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema: any, queryExpression: any): Partial<any> | null;
4
- export function replaceNamesWithIdsInExpression(schema: any, fromType: any, expression: any): any;
5
- export function replaceIdsWithNamesInExpression(schema: any, fromTypeId: any, expression: any): any;
6
- export function visitViewUnit(fromType: any, unit: any, visitor: any): any;
7
- export function visitContextExpression(fromType: any, contextExpression: any, visitor: any): any;
8
- export function replaceIdsWithNamesInQueryExpression(schema: any, queryExpression: any): any;
9
- export function replaceIdsWithNamesInFilter(schema: any, fromType: any, filter: any): any;
10
- export function replaceNamesWithIdsInFilter(schema: any, fromType: any, filter: any): any;
11
- export function replaceNamesWithIdsInQueryExpression(schema: any, queryExpression: any): any;
12
- export function deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema: any, fromType: any, expression: any): any;
13
- export function resetContextExpressionIfBroken(schema: any, fromType: any, expression: any, defaultExpression: any): any;
14
- export function isUnitExpressionValid(unit: any): boolean;
15
- export function getFieldObjectsById(smartFolder: any, schema: any): any;
16
- export function replaceIdsWithNamesInUnitGroupKey(unitGroupKey: any, fieldObjectsById: any): any;
17
- export function replaceNamesWithIdsInUnitGroupKey(unitGroupKey: any, schema: any): any;
1
+ import type { Expression, Query } from "@fibery/expression-utils/src/types";
2
+ import type { FieldObject, Schema } from "@fibery/schema";
3
+ import { Unit } from "@fibery/views/src/units/types";
4
+ export declare const REMOVE: unique symbol;
5
+ export declare const skipRemove: (unit: Unit | typeof REMOVE) => unit is Unit;
6
+ export type ViewVisitor = {
7
+ visitExpression: (fromType: string, expression: Expression) => Expression | null;
8
+ visitFilter: (fromType: string, filter: ViewFilter | null) => ViewFilter | null;
9
+ visitQueryExpression: (query: Query) => Query | null;
10
+ visitViewUnit?: (fromType: string, unit: Unit, units: Unit[]) => Unit | typeof REMOVE;
11
+ visitContextExpression?: (fromType: string, expression: Expression) => Expression;
12
+ visitGroupByExpression?: (groupBy: Record<string, unknown>, fromType: string, removedItems?: number[]) => Record<string, unknown> | null;
13
+ visitEnums?: (enums: Record<string, unknown>) => Record<string, unknown> | null;
14
+ visitUnitGroupKey?: (key: string) => string;
15
+ };
16
+ export type UnitDefinitions = {
17
+ getUnitsForField: (fieldObject: FieldObject, options?: {
18
+ parentFieldObjects?: FieldObject[];
19
+ }) => Unit[];
20
+ };
21
+ export type ViewRecord = Record<string, unknown>;
22
+ type ViewFilterLeaf = {
23
+ kind: string;
24
+ value: {
25
+ expression: Expression | null;
26
+ [k: string]: unknown;
27
+ };
28
+ };
29
+ type ViewFilterGroup = {
30
+ kind: "group";
31
+ value: ViewFilter[];
32
+ };
33
+ export type ViewFilter = ViewFilterLeaf | ViewFilterGroup;
34
+ export declare const deleteExpressionWithNotFoundFieldsOrTypesInFilter: (schema: Schema, fromType: string, filter: ViewFilter) => ViewFilter | null;
35
+ export declare const deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression: (schema: Schema, queryExpression: Query) => Query | null;
36
+ export declare const replaceNamesWithIdsInExpression: (schema: Schema, fromType: string, expression: Expression) => any;
37
+ export declare const replaceIdsWithNamesInExpression: (schema: Schema, fromTypeId: string, expression: Expression) => any;
38
+ export declare const visitViewUnit: (fromType: string, unit: Unit, visitor: Pick<ViewVisitor, "visitExpression">) => Unit;
39
+ export declare const visitContextExpression: (fromType: string, contextExpression: Expression | null | undefined, visitor: Pick<ViewVisitor, "visitExpression" | "visitContextExpression">) => string | Expression[] | null | undefined;
40
+ export declare const replaceIdsWithNamesInQueryExpression: (schema: Schema, queryExpression: Query) => {
41
+ "q/order-by"?: any;
42
+ "q/where"?: any;
43
+ "q/from": string;
44
+ "q/select"?: Expression | import("@fibery/expression-utils/src/types").Select;
45
+ "q/offset"?: number;
46
+ "q/limit"?: import("@fibery/expression-utils/src/types").QueryLimit;
47
+ };
48
+ export declare const replaceIdsWithNamesInFilter: (schema: Schema, fromType: string, filter: ViewFilter | null) => ViewFilter | null;
49
+ export declare const replaceNamesWithIdsInFilter: (schema: Schema, fromType: string, filter: ViewFilter | null) => ViewFilter | null;
50
+ export declare const replaceNamesWithIdsInQueryExpression: (schema: Schema, queryExpression: Query) => {
51
+ "q/order-by"?: any;
52
+ "q/where"?: any;
53
+ "q/from": string;
54
+ "q/select"?: Expression | import("@fibery/expression-utils/src/types").Select;
55
+ "q/offset"?: number;
56
+ "q/limit"?: import("@fibery/expression-utils/src/types").QueryLimit;
57
+ };
58
+ export declare const deleteExpressionWithNotFoundFieldsOrTypesInExpression: (schema: Schema, fromType: string, expression: Expression) => any;
59
+ export declare const resetContextExpressionIfBroken: (schema: Schema, fromType: string, expression: Expression, defaultExpression: Expression) => any;
60
+ export declare const isUnitExpressionValid: (unit: Record<string, unknown>) => boolean;
61
+ export declare const getFieldObjectsById: (smartFolder: Record<string, unknown>, schema: Schema) => Record<string, FieldObject>;
62
+ export declare const replaceIdsWithNamesInUnitGroupKey: (unitGroupKey: string, fieldObjectsById: Record<string, FieldObject>) => string;
63
+ export declare const replaceNamesWithIdsInUnitGroupKey: (unitGroupKey: string, schema: Schema) => string;
64
+ export {};
@@ -3,12 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.replaceNamesWithIdsInUnitGroupKey = exports.replaceIdsWithNamesInUnitGroupKey = exports.getFieldObjectsById = exports.isUnitExpressionValid = exports.resetContextExpressionIfBroken = exports.deleteExpressionWithNotFoundFieldsOrTypesInExpression = exports.replaceNamesWithIdsInQueryExpression = exports.replaceNamesWithIdsInFilter = exports.replaceIdsWithNamesInFilter = exports.replaceIdsWithNamesInQueryExpression = exports.visitContextExpression = exports.visitViewUnit = exports.replaceIdsWithNamesInExpression = exports.replaceNamesWithIdsInExpression = exports.deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression = exports.deleteExpressionWithNotFoundFieldsOrTypesInFilter = exports.REMOVE = void 0;
6
+ exports.replaceNamesWithIdsInUnitGroupKey = exports.replaceIdsWithNamesInUnitGroupKey = exports.getFieldObjectsById = exports.isUnitExpressionValid = exports.resetContextExpressionIfBroken = exports.deleteExpressionWithNotFoundFieldsOrTypesInExpression = exports.replaceNamesWithIdsInQueryExpression = exports.replaceNamesWithIdsInFilter = exports.replaceIdsWithNamesInFilter = exports.replaceIdsWithNamesInQueryExpression = exports.visitContextExpression = exports.visitViewUnit = exports.replaceIdsWithNamesInExpression = exports.replaceNamesWithIdsInExpression = exports.deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression = exports.deleteExpressionWithNotFoundFieldsOrTypesInFilter = exports.skipRemove = exports.REMOVE = void 0;
7
7
  const visitors_1 = require("@fibery/expression-utils/src/visitors");
8
8
  const pickBy_1 = __importDefault(require("lodash/pickBy"));
9
+ const truthy_1 = require("../truthy");
9
10
  // Return this symbol from a visitor callback to remove the node from the
10
11
  // output. Not supported in all places, add support as needed.
11
12
  exports.REMOVE = Symbol("remove");
13
+ const skipRemove = (unit) => unit !== exports.REMOVE;
14
+ exports.skipRemove = skipRemove;
12
15
  function visitDeleteExpressionInFilterGroup(filter, visitExpression) {
13
16
  if (filter.kind !== "group") {
14
17
  return null;
@@ -18,19 +21,20 @@ function visitDeleteExpressionInFilterGroup(filter, visitExpression) {
18
21
  if (nestedFilter.kind === "group") {
19
22
  return visitFilterGroup(nestedFilter, visitExpression);
20
23
  }
21
- const expression = nestedFilter.value.expression ? visitExpression(nestedFilter.value.expression) : null;
24
+ const leaf = nestedFilter;
25
+ const expression = leaf.value.expression ? visitExpression(leaf.value.expression) : null;
22
26
  if (!expression) {
23
27
  return null;
24
28
  }
25
29
  return {
26
- ...nestedFilter,
30
+ ...leaf,
27
31
  value: {
28
- ...nestedFilter.value,
32
+ ...leaf.value,
29
33
  expression: expression,
30
34
  },
31
35
  };
32
36
  })
33
- .filter(Boolean);
37
+ .filter(truthy_1.truthy);
34
38
  if (value.length === 0) {
35
39
  return null;
36
40
  }
@@ -81,16 +85,15 @@ const replaceIdsWithNamesInExpression = (schema, fromTypeId, expression) => {
81
85
  };
82
86
  exports.replaceIdsWithNamesInExpression = replaceIdsWithNamesInExpression;
83
87
  const visitViewUnit = (fromType, unit, visitor) => {
88
+ if (unit.kind === "user-button") {
89
+ return unit;
90
+ }
84
91
  const { expression } = unit;
85
- if (expression) {
86
- return {
87
- ...unit,
88
- ...{
89
- expression: visitor.visitExpression(fromType, expression),
90
- },
91
- };
92
+ if (!expression) {
93
+ return unit;
92
94
  }
93
- return unit;
95
+ // visitExpression preserves string[] shape; null results are filtered by isUnitExpressionValid downstream
96
+ return { ...unit, expression: visitor.visitExpression(fromType, expression) };
94
97
  };
95
98
  exports.visitViewUnit = visitViewUnit;
96
99
  const visitContextExpression = (fromType, contextExpression, visitor) => {
@@ -122,21 +125,23 @@ const replaceIdsWithNamesInQueryExpression = (schema, queryExpression) => {
122
125
  return queryExpression;
123
126
  };
124
127
  exports.replaceIdsWithNamesInQueryExpression = replaceIdsWithNamesInQueryExpression;
125
- function visitFilterGroup(filter, visitExpression, type) {
128
+ function visitFilterGroup(filter, visitExpression, _type) {
126
129
  if (filter.kind !== "group") {
127
130
  return null;
128
131
  }
132
+ const group = filter;
129
133
  return {
130
- ...filter,
131
- value: filter.value.map((nestedFilter) => {
134
+ ...group,
135
+ value: group.value.map((nestedFilter) => {
132
136
  if (nestedFilter.kind === "group") {
133
137
  return visitFilterGroup(nestedFilter, visitExpression);
134
138
  }
139
+ const leaf = nestedFilter;
135
140
  return {
136
- ...nestedFilter,
141
+ ...leaf,
137
142
  value: {
138
- ...nestedFilter.value,
139
- expression: nestedFilter.value.expression ? visitExpression(nestedFilter.value.expression) : null,
143
+ ...leaf.value,
144
+ expression: leaf.value.expression ? visitExpression(leaf.value.expression) : null,
140
145
  },
141
146
  };
142
147
  }),
@@ -203,7 +208,8 @@ const isUnitExpressionValid = (unit) => {
203
208
  };
204
209
  exports.isUnitExpressionValid = isUnitExpressionValid;
205
210
  const getFieldObjectsById = (smartFolder, schema) => {
206
- const types = smartFolder["fibery/meta"].items.map((item) => item.query["q/from"]);
211
+ const meta = smartFolder["fibery/meta"];
212
+ const types = meta.items.map((item) => item.query["q/from"]);
207
213
  return types.reduce((acc, type) => {
208
214
  if (!Object.hasOwn(schema.typeObjectsById, type)) {
209
215
  return acc;
@@ -0,0 +1 @@
1
+ export declare const truthy: <T>(x: T | null | undefined | false) => x is T;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.truthy = void 0;
4
+ const truthy = (x) => {
5
+ return Boolean(x);
6
+ };
7
+ exports.truthy = truthy;
@@ -10,6 +10,7 @@ const select_1 = require("@fibery/query-utils/src/select");
10
10
  const get_export_value_1 = require("../unit-utils/get-export-value");
11
11
  const avatar_1 = require("../field-utils/avatar");
12
12
  const common_1 = require("../unit-utils/common");
13
+ const get_field_label_1 = require("../unit-utils/get-field-label");
13
14
  const type = "avatar-collection";
14
15
  exports.AvatarCollection = {
15
16
  type,
@@ -18,9 +19,7 @@ exports.AvatarCollection = {
18
19
  return (0, common_1.canEditFieldExpression)(typeObject, expression);
19
20
  },
20
21
  getLabel({ typeObject, unit }) {
21
- const { expression } = unit;
22
- const fieldObject = (0, utils_1.getFieldObjectByFieldExpression)({ typeObject, expression });
23
- return `Avatar of ${fieldObject.title}`;
22
+ return `Avatar of ${(0, get_field_label_1.getFieldLabel)({ typeObject, unit })}`;
24
23
  },
25
24
  makeUnit: (0, common_1.makeUnitMethod)(type),
26
25
  getQuerySelect({ typeObject, unit: { expression } }) {
@@ -10,6 +10,7 @@ const utils_1 = require("@fibery/expression-utils/src/utils");
10
10
  const avatar_1 = require("../field-utils/avatar");
11
11
  const common_1 = require("../unit-utils/common");
12
12
  const get_export_value_1 = require("../unit-utils/get-export-value");
13
+ const get_field_label_1 = require("../unit-utils/get-field-label");
13
14
  const type = "avatar";
14
15
  const getSelfAvatarSelectQuery = (typeObject) => (0, avatar_1.getAvatarSelectQuery)({ typeObject }) || {};
15
16
  exports.Avatar = {
@@ -24,12 +25,9 @@ exports.Avatar = {
24
25
  getLabel({ typeObject, unit }) {
25
26
  const { expression } = unit;
26
27
  if (expression) {
27
- const fieldObject = (0, utils_1.getFieldObjectByFieldExpression)({
28
- typeObject,
29
- expression,
30
- });
28
+ const fieldObject = (0, utils_1.getFieldObjectByFieldExpression)({ typeObject, expression });
31
29
  if ((0, avatar_1.isAvatarExtensionEnabledType)(fieldObject.typeObject)) {
32
- return `Avatar of ${fieldObject.title}`;
30
+ return `Avatar of ${(0, get_field_label_1.getFieldLabel)({ typeObject, unit })}`;
33
31
  }
34
32
  }
35
33
  return "Avatar";
@@ -4,6 +4,7 @@ exports.CollectionCount = void 0;
4
4
  const utils_1 = require("@fibery/expression-utils/src/utils");
5
5
  const reference_collection_1 = require("../field-utils/reference-collection");
6
6
  const common_1 = require("../unit-utils/common");
7
+ const get_field_label_1 = require("../unit-utils/get-field-label");
7
8
  const type = "collection-count";
8
9
  exports.CollectionCount = {
9
10
  type,
@@ -13,10 +14,11 @@ exports.CollectionCount = {
13
14
  getLabel({ typeObject, unit }) {
14
15
  const { expression } = unit;
15
16
  const fieldObject = (0, utils_1.getFieldObjectByFieldExpression)({ typeObject, expression });
17
+ const label = (0, get_field_label_1.getFieldLabel)({ typeObject, unit });
16
18
  if (fieldObject.name === "comments/comments") {
17
- return fieldObject.title;
19
+ return label;
18
20
  }
19
- return `${fieldObject.title} Count`;
21
+ return `${label} Count`;
20
22
  },
21
23
  getQuerySelect({ unit: { expression } }) {
22
24
  const countKey = (0, reference_collection_1.getCountKey)(expression.join("/"));
@@ -2,11 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FileCollectionCount = void 0;
4
4
  const utils_1 = require("@fibery/expression-utils/src/utils");
5
+ const select_1 = require("@fibery/query-utils/src/select");
5
6
  const file_1 = require("../field-utils/file");
6
7
  const common_1 = require("../unit-utils/common");
7
8
  const can_edit_field_1 = require("../unit-utils/can-edit-field");
8
9
  const get_field_label_1 = require("../unit-utils/get-field-label");
9
10
  const get_export_value_1 = require("../unit-utils/get-export-value");
11
+ const wrap_normalized_in_expression_1 = require("../unit-utils/wrap-normalized-in-expression");
10
12
  const type = "file-collection-count";
11
13
  exports.FileCollectionCount = {
12
14
  type,
@@ -16,14 +18,14 @@ exports.FileCollectionCount = {
16
18
  calculateErrors: common_1.calculateUnitExpressionErrors,
17
19
  makeUnit: (0, common_1.makeUnitMethod)(type),
18
20
  getQuerySelect({ typeObject, unit: { expression } }) {
19
- const fieldObject = (0, utils_1.getFieldObjectByFieldExpression)({ typeObject, expression });
20
- return {
21
- [fieldObject.name]: {
22
- "q/from": [fieldObject.name],
23
- "q/limit": "q/no-limit",
24
- "q/select": (0, file_1.getFilesSelect)(fieldObject),
25
- },
21
+ const fieldObjects = (0, utils_1.getFieldObjectsByFieldExpression)({ typeObject, expression });
22
+ const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
23
+ const collectionNormalized = {
24
+ "q/from": null,
25
+ "q/limit": "q/no-limit",
26
+ "q/select": (0, select_1.normalizeSelect)((0, file_1.getFilesSelect)(terminalFieldObject)),
26
27
  };
28
+ return (0, select_1.denormalizeSelect)((0, wrap_normalized_in_expression_1.wrapNormalizedInExpression)(collectionNormalized, fieldObjects, expression));
27
29
  },
28
30
  getExportValue: get_export_value_1.getExportValue,
29
31
  canExport: () => true,
@@ -2,11 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FileCompactCollection = void 0;
4
4
  const utils_1 = require("@fibery/expression-utils/src/utils");
5
+ const select_1 = require("@fibery/query-utils/src/select");
5
6
  const file_1 = require("../field-utils/file");
6
7
  const common_1 = require("../unit-utils/common");
7
8
  const get_field_label_1 = require("../unit-utils/get-field-label");
8
9
  const get_export_value_1 = require("../unit-utils/get-export-value");
9
10
  const can_edit_field_1 = require("../unit-utils/can-edit-field");
11
+ const wrap_normalized_in_expression_1 = require("../unit-utils/wrap-normalized-in-expression");
10
12
  const type = "file-compact-collection";
11
13
  exports.FileCompactCollection = {
12
14
  type,
@@ -16,14 +18,14 @@ exports.FileCompactCollection = {
16
18
  calculateErrors: common_1.calculateUnitExpressionErrors,
17
19
  makeUnit: (0, common_1.makeUnitMethod)(type),
18
20
  getQuerySelect({ typeObject, unit: { expression } }) {
19
- const fieldObject = (0, utils_1.getFieldObjectByFieldExpression)({ typeObject, expression });
20
- return {
21
- [fieldObject.name]: {
22
- "q/from": [fieldObject.name],
23
- "q/limit": "q/no-limit",
24
- "q/select": (0, file_1.getFilesSelect)(fieldObject),
25
- },
21
+ const fieldObjects = (0, utils_1.getFieldObjectsByFieldExpression)({ typeObject, expression });
22
+ const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
23
+ const collectionNormalized = {
24
+ "q/from": null,
25
+ "q/limit": "q/no-limit",
26
+ "q/select": (0, select_1.normalizeSelect)((0, file_1.getFilesSelect)(terminalFieldObject)),
26
27
  };
28
+ return (0, select_1.denormalizeSelect)((0, wrap_normalized_in_expression_1.wrapNormalizedInExpression)(collectionNormalized, fieldObjects, expression));
27
29
  },
28
30
  getExportValue: get_export_value_1.getExportValue,
29
31
  canExport: () => true,
@@ -7,6 +7,7 @@ const reference_1 = require("../field-utils/reference");
7
7
  const common_1 = require("../unit-utils/common");
8
8
  const get_export_value_1 = require("../unit-utils/get-export-value");
9
9
  const get_field_label_1 = require("../unit-utils/get-field-label");
10
+ const wrap_normalized_in_expression_1 = require("../unit-utils/wrap-normalized-in-expression");
10
11
  const type = "file-compact-reference";
11
12
  exports.FileCompactReference = {
12
13
  type,
@@ -23,17 +24,7 @@ exports.FileCompactReference = {
23
24
  const fieldObjects = (0, utils_1.getFieldObjectsByFieldExpression)({ typeObject, expression });
24
25
  const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
25
26
  const innerNormalized = (0, reference_1.getReferenceFieldNormalizedSelectClause)(terminalFieldObject, expression);
26
- const nested = [...expression].reverse().reduce((inner, field, reversedIndex) => {
27
- const originalIndex = expression.length - 1 - reversedIndex;
28
- const isTerminal = originalIndex === expression.length - 1;
29
- if (!isTerminal) {
30
- const { idField } = fieldObjects[originalIndex].typeObject;
31
- const innerWithId = idField ? { [idField]: idField, ...inner } : inner;
32
- return { [field]: innerWithId };
33
- }
34
- return { [field]: inner };
35
- }, innerNormalized);
36
- return (0, select_1.denormalizeSelect)(nested);
27
+ return (0, select_1.denormalizeSelect)((0, wrap_normalized_in_expression_1.wrapNormalizedInExpression)(innerNormalized, fieldObjects, expression));
37
28
  },
38
29
  calculateErrors({ typeObject, unit }) {
39
30
  return (0, common_1.calculateUnitExpressionErrors)({ typeObject, unit });
@@ -2,11 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FileReference = void 0;
4
4
  const utils_1 = require("@fibery/expression-utils/src/utils");
5
+ const select_1 = require("@fibery/query-utils/src/select");
5
6
  const file_1 = require("../field-utils/file");
6
7
  const common_1 = require("../unit-utils/common");
7
8
  const get_field_label_1 = require("../unit-utils/get-field-label");
8
9
  const get_export_value_1 = require("../unit-utils/get-export-value");
9
10
  const can_edit_field_1 = require("../unit-utils/can-edit-field");
11
+ const wrap_normalized_in_expression_1 = require("../unit-utils/wrap-normalized-in-expression");
10
12
  const type = "file-reference";
11
13
  exports.FileReference = {
12
14
  type,
@@ -16,10 +18,10 @@ exports.FileReference = {
16
18
  calculateErrors: common_1.calculateUnitExpressionErrors,
17
19
  makeUnit: (0, common_1.makeUnitMethod)(type),
18
20
  getQuerySelect({ typeObject, unit: { expression } }) {
19
- const fieldObject = (0, utils_1.getFieldObjectByFieldExpression)({ typeObject, expression });
20
- return {
21
- [fieldObject.name]: (0, file_1.getFilesSelect)(fieldObject),
22
- };
21
+ const fieldObjects = (0, utils_1.getFieldObjectsByFieldExpression)({ typeObject, expression });
22
+ const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
23
+ const innerNormalized = (0, select_1.normalizeSelect)((0, file_1.getFilesSelect)(terminalFieldObject));
24
+ return (0, select_1.denormalizeSelect)((0, wrap_normalized_in_expression_1.wrapNormalizedInExpression)(innerNormalized, fieldObjects, expression));
23
25
  },
24
26
  getExportValue: get_export_value_1.getExportValue,
25
27
  canExport: () => true,
@@ -2,11 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FilesGallery = void 0;
4
4
  const utils_1 = require("@fibery/expression-utils/src/utils");
5
+ const select_1 = require("@fibery/query-utils/src/select");
5
6
  const file_1 = require("../field-utils/file");
6
7
  const common_1 = require("../unit-utils/common");
7
8
  const can_edit_field_1 = require("../unit-utils/can-edit-field");
8
9
  const get_field_label_1 = require("../unit-utils/get-field-label");
9
10
  const get_export_value_1 = require("../unit-utils/get-export-value");
11
+ const wrap_normalized_in_expression_1 = require("../unit-utils/wrap-normalized-in-expression");
10
12
  const type = "files-gallery";
11
13
  exports.FilesGallery = {
12
14
  type,
@@ -16,14 +18,14 @@ exports.FilesGallery = {
16
18
  calculateErrors: common_1.calculateUnitExpressionErrors,
17
19
  makeUnit: (0, common_1.makeUnitMethod)(type),
18
20
  getQuerySelect({ typeObject, unit: { expression } }) {
19
- const fieldObject = (0, utils_1.getFieldObjectByFieldExpression)({ typeObject, expression });
20
- return {
21
- [fieldObject.name]: {
22
- "q/from": [fieldObject.name],
23
- "q/limit": "q/no-limit",
24
- "q/select": (0, file_1.getFilesSelect)(fieldObject),
25
- },
21
+ const fieldObjects = (0, utils_1.getFieldObjectsByFieldExpression)({ typeObject, expression });
22
+ const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
23
+ const collectionNormalized = {
24
+ "q/from": null,
25
+ "q/limit": "q/no-limit",
26
+ "q/select": (0, select_1.normalizeSelect)((0, file_1.getFilesSelect)(terminalFieldObject)),
26
27
  };
28
+ return (0, select_1.denormalizeSelect)((0, wrap_normalized_in_expression_1.wrapNormalizedInExpression)(collectionNormalized, fieldObjects, expression));
27
29
  },
28
30
  getExportValue: get_export_value_1.getExportValue,
29
31
  canExport: () => true,
@@ -2,11 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FileLListItem = void 0;
4
4
  const utils_1 = require("@fibery/expression-utils/src/utils");
5
+ const select_1 = require("@fibery/query-utils/src/select");
5
6
  const file_1 = require("../field-utils/file");
6
7
  const common_1 = require("../unit-utils/common");
7
8
  const can_edit_field_1 = require("../unit-utils/can-edit-field");
8
9
  const get_field_label_1 = require("../unit-utils/get-field-label");
9
10
  const get_export_value_1 = require("../unit-utils/get-export-value");
11
+ const wrap_normalized_in_expression_1 = require("../unit-utils/wrap-normalized-in-expression");
10
12
  const type = "files-l-list-item";
11
13
  exports.FileLListItem = {
12
14
  type,
@@ -16,10 +18,10 @@ exports.FileLListItem = {
16
18
  calculateErrors: common_1.calculateUnitExpressionErrors,
17
19
  makeUnit: (0, common_1.makeUnitMethod)(type),
18
20
  getQuerySelect({ typeObject, unit: { expression } }) {
19
- const fieldObject = (0, utils_1.getFieldObjectByFieldExpression)({ typeObject, expression });
20
- return {
21
- [fieldObject.name]: (0, file_1.getFilesSelect)(fieldObject),
22
- };
21
+ const fieldObjects = (0, utils_1.getFieldObjectsByFieldExpression)({ typeObject, expression });
22
+ const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
23
+ const innerNormalized = (0, select_1.normalizeSelect)((0, file_1.getFilesSelect)(terminalFieldObject));
24
+ return (0, select_1.denormalizeSelect)((0, wrap_normalized_in_expression_1.wrapNormalizedInExpression)(innerNormalized, fieldObjects, expression));
23
25
  },
24
26
  getExportValue: get_export_value_1.getExportValue,
25
27
  canExport: () => true,