@fibery/views 18.0.4 → 19.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.
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
- /** @type {import('jest').Config} */
3
- module.exports = {
2
+ /** @type {import('@jest/schemas').InitialOptions} */
3
+ const config = {
4
4
  testEnvironment: "node",
5
+ testEnvironmentOptions: {
6
+ customExportConditions: ["@fibery/source"],
7
+ url: "http://localhost",
8
+ },
5
9
  coveragePathIgnorePatterns: ["/node_modules/"],
6
10
  collectCoverageFrom: ["src/**/*.{js,jsx,ts,tsx}", "!src/**/*.d.ts"],
7
11
  coverageReporters: ["text", "cobertura"],
@@ -26,7 +30,5 @@ module.exports = {
26
30
  },
27
31
  ],
28
32
  },
29
- testEnvironmentOptions: {
30
- url: "http://localhost",
31
- },
32
33
  };
34
+ module.exports = config;
@@ -0,0 +1,3 @@
1
+ export = config;
2
+ /** @type {import('@jest/schemas').InitialOptions} */
3
+ declare const config: any;
@@ -1,18 +1,13 @@
1
1
  import { FieldObject } from "@fibery/schema";
2
2
  import { QueryLimit } from "@fibery/expression-utils/src/types";
3
3
  export declare const REFERENCE_COLLECTION_LIMIT = 1000;
4
- export declare const makeCollectionCountExpression: (field: string) => (string | string[])[];
4
+ export declare const makeCollectionCountExpression: (field: string | string[]) => (string | string[])[];
5
5
  export declare const getCountKey: (field: string) => string;
6
6
  export declare const getCollectionCountSelect: (field: string) => {
7
7
  [x: string]: (string | string[])[];
8
8
  };
9
- export declare const calculateReferenceCollectionQuery: ({ fieldObject, limit, }: {
10
- fieldObject: FieldObject;
9
+ export declare const calculateReferenceCollectionQuery: ({ fieldObjects, expression, limit, }: {
10
+ fieldObjects: FieldObject[];
11
+ expression: string[];
11
12
  limit: QueryLimit;
12
- }) => {
13
- [x: string]: {
14
- "q/from": string[];
15
- "q/select": any;
16
- "q/limit": QueryLimit;
17
- };
18
- };
13
+ }) => Record<string, unknown>;
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.calculateReferenceCollectionQuery = exports.getCollectionCountSelect = exports.getCountKey = exports.makeCollectionCountExpression = exports.REFERENCE_COLLECTION_LIMIT = void 0;
7
+ const last_1 = __importDefault(require("lodash/last"));
7
8
  const compact_1 = __importDefault(require("lodash/compact"));
8
9
  const select_1 = require("@fibery/query-utils/src/select");
9
10
  const dynamic_keys_1 = require("../unit-utils/dynamic-keys");
@@ -13,7 +14,10 @@ const avatar_1 = require("./avatar");
13
14
  const icon_1 = require("./icon");
14
15
  const file_1 = require("./file");
15
16
  exports.REFERENCE_COLLECTION_LIMIT = 1000;
16
- const makeCollectionCountExpression = (field) => ["q/count", [field, "fibery/id"]];
17
+ const makeCollectionCountExpression = (field) => [
18
+ "q/count",
19
+ [...(Array.isArray(field) ? field : [field]), "fibery/id"],
20
+ ];
17
21
  exports.makeCollectionCountExpression = makeCollectionCountExpression;
18
22
  const getCountKey = (field) => (0, dynamic_keys_1.makeDynamicKey)(dynamic_keys_1.collectionCountKeyPrefix, field);
19
23
  exports.getCountKey = getCountKey;
@@ -21,25 +25,43 @@ const getCollectionCountSelect = (field) => ({
21
25
  [(0, exports.getCountKey)(field)]: (0, exports.makeCollectionCountExpression)(field),
22
26
  });
23
27
  exports.getCollectionCountSelect = getCollectionCountSelect;
24
- const calculateReferenceCollectionQuery = ({ fieldObject, limit, }) => {
25
- return {
26
- [fieldObject.name]: {
27
- "q/from": [fieldObject.name],
28
- "q/select": (0, select_1.mergeDenormalizedSelects)((0, compact_1.default)([
29
- (0, select_1.toSelectMapClause)((0, compact_1.default)([
30
- fieldObject.typeObject.idField,
31
- fieldObject.typeObject.titleField,
32
- // keep public id - required to build Links
33
- fieldObject.typeObject.publicIdField,
34
- ])),
35
- (0, access_1.generateAccessCheckQueryExpression)({ typeObject: fieldObject.typeObject }),
36
- (0, avatar_1.getAvatarSelectQuery)({ typeObject: fieldObject.typeObject }),
37
- (0, icon_1.getEntityIconSelect)({ typeObject: fieldObject.typeObject }),
38
- fieldObject.type === "fibery/file" && (0, file_1.getFilesSelect)(fieldObject),
39
- (0, enums_1.getEnumIconColorQuery)({ typeObject: fieldObject.typeObject }),
28
+ const calculateReferenceCollectionQuery = ({ fieldObjects, expression, limit, }) => {
29
+ const fieldObject = (0, last_1.default)(fieldObjects);
30
+ if (!fieldObject) {
31
+ return {};
32
+ }
33
+ const collectionSubQuery = {
34
+ "q/from": expression,
35
+ "q/select": (0, select_1.mergeDenormalizedSelects)((0, compact_1.default)([
36
+ (0, select_1.toSelectMapClause)((0, compact_1.default)([
37
+ fieldObject.typeObject.idField,
38
+ fieldObject.typeObject.titleField,
39
+ // keep public id - required to build Links
40
+ fieldObject.typeObject.publicIdField,
40
41
  ])),
41
- "q/limit": limit,
42
- },
42
+ (0, access_1.generateAccessCheckQueryExpression)({ typeObject: fieldObject.typeObject }),
43
+ (0, avatar_1.getAvatarSelectQuery)({ typeObject: fieldObject.typeObject }),
44
+ (0, icon_1.getEntityIconSelect)({ typeObject: fieldObject.typeObject }),
45
+ fieldObject.type === "fibery/file" && (0, file_1.getFilesSelect)(fieldObject),
46
+ (0, enums_1.getEnumIconColorQuery)({ typeObject: fieldObject.typeObject }),
47
+ ])),
48
+ "q/limit": limit,
43
49
  };
50
+ // Wrap the collection query in intermediate reference fields (innermost to outermost).
51
+ // For each intermediate field, include its entity's id so normalizr can normalize it.
52
+ return [...expression].reverse().reduce((inner, field, reversedIndex) => {
53
+ const originalIndex = expression.length - 1 - reversedIndex;
54
+ const isTerminal = originalIndex === expression.length - 1;
55
+ if (!isTerminal) {
56
+ const pathToField = expression.slice(0, originalIndex + 1);
57
+ const { idField } = fieldObjects[originalIndex].typeObject;
58
+ // `inner` already has the next field keyed, so spread it rather than re-keying it.
59
+ const innerForField = idField
60
+ ? { [idField]: [...pathToField, idField], ...inner }
61
+ : { ...inner };
62
+ return { [field]: innerForField };
63
+ }
64
+ return { [field]: inner };
65
+ }, collectionSubQuery);
44
66
  };
45
67
  exports.calculateReferenceCollectionQuery = calculateReferenceCollectionQuery;
@@ -1,9 +1,10 @@
1
- import { FieldObject, TypeObject } from "@fibery/schema";
1
+ import { TypeObject } from "@fibery/schema";
2
+ import type { FieldExpression } from "@fibery/expression-utils/src/types";
2
3
  import { FieldUnit } from "../units/types";
3
4
  export declare const hasAccessToSecretKey: string;
4
- export declare const getHasAccessToSecretExpr: (fieldObject: FieldObject) => (string | string[])[];
5
- export declare const getHasAccessToSecret: (fieldObject: FieldObject) => {
6
- [hasAccessToSecretKey]: (string | string[])[];
5
+ export declare const getHasAccessToSecretExpr: (expression: FieldExpression) => (string | (string | import("@fibery/expression-utils/src/types").MultiFieldAccess)[])[];
6
+ export declare const getHasAccessToSecret: (expression: FieldExpression) => {
7
+ [hasAccessToSecretKey]: (string | (string | import("@fibery/expression-utils/src/types").MultiFieldAccess)[])[];
7
8
  };
8
9
  export declare function getRichTextQuerySelect({ typeObject, unit: { expression }, includeSnippet, }: {
9
10
  typeObject: TypeObject;
@@ -6,22 +6,33 @@ const select_1 = require("@fibery/query-utils/src/select");
6
6
  const utils_1 = require("@fibery/expression-utils/src/utils");
7
7
  const dynamic_keys_1 = require("../unit-utils/dynamic-keys");
8
8
  exports.hasAccessToSecretKey = (0, dynamic_keys_1.makeDynamicKey)(dynamic_keys_1.hasAccessToSecretKeyPrefix);
9
- const getHasAccessToSecretExpr = (fieldObject) => [
9
+ const getHasAccessToSecretExpr = (expression) => [
10
10
  "q/access?",
11
- [fieldObject.name, "Collaboration~Documents/secret"],
11
+ [...expression, "Collaboration~Documents/secret"],
12
12
  ];
13
13
  exports.getHasAccessToSecretExpr = getHasAccessToSecretExpr;
14
- const getHasAccessToSecret = (fieldObject) => ({
15
- [exports.hasAccessToSecretKey]: (0, exports.getHasAccessToSecretExpr)(fieldObject),
14
+ const getHasAccessToSecret = (expression) => ({
15
+ [exports.hasAccessToSecretKey]: (0, exports.getHasAccessToSecretExpr)(expression),
16
16
  });
17
17
  exports.getHasAccessToSecret = getHasAccessToSecret;
18
18
  function getRichTextQuerySelect({ typeObject, unit: { expression }, includeSnippet, }) {
19
- const fieldObject = (0, utils_1.getFieldObjectByFieldExpression)({ typeObject, expression });
20
- return (0, select_1.denormalizeSelect)({
21
- [fieldObject.name]: (0, select_1.normalizeSelect)({
22
- ...(0, exports.getHasAccessToSecret)(fieldObject),
23
- ...(0, select_1.toSelectMapClause)([typeObject.idField, "Collaboration~Documents/secret"]),
24
- ...(includeSnippet ? (0, select_1.toSelectMapClause)([typeObject.idField, "Collaboration~Documents/Snippet"]) : {}),
25
- }),
19
+ const fieldObjects = (0, utils_1.getFieldObjectsByFieldExpression)({ typeObject, expression });
20
+ const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
21
+ const { typeObject: terminalTypeObject } = terminalFieldObject;
22
+ const innerNormalized = (0, select_1.normalizeSelect)({
23
+ ...(0, exports.getHasAccessToSecret)(expression),
24
+ ...(0, select_1.toSelectMapClause)([terminalTypeObject.idField, "Collaboration~Documents/secret"]),
25
+ ...(includeSnippet ? (0, select_1.toSelectMapClause)([terminalTypeObject.idField, "Collaboration~Documents/Snippet"]) : {}),
26
26
  });
27
+ const nested = [...expression].reverse().reduce((inner, field, reversedIndex) => {
28
+ const originalIndex = expression.length - 1 - reversedIndex;
29
+ const isTerminal = originalIndex === expression.length - 1;
30
+ if (!isTerminal) {
31
+ const { idField } = fieldObjects[originalIndex].typeObject;
32
+ const innerWithId = idField ? { [idField]: idField, ...inner } : inner;
33
+ return { [field]: innerWithId };
34
+ }
35
+ return { [field]: inner };
36
+ }, innerNormalized);
37
+ return (0, select_1.denormalizeSelect)(nested);
27
38
  }
@@ -8,6 +8,18 @@ const getField = (schema, fromType, field) => Object.hasOwn(schema.typeObjectsBy
8
8
  : undefined;
9
9
  const getFieldType = (schema, fromType, field) => getField(schema, fromType, field)?.type;
10
10
  const getFieldMeta = (schema, fromType, field) => getField(schema, fromType, field)?.rawMeta;
11
+ const getFieldByExpression = (schema, fromType, expression) => {
12
+ let currentType = fromType;
13
+ let fieldObject;
14
+ for (const part of expression) {
15
+ fieldObject = getField(schema, currentType, part);
16
+ if (!fieldObject) {
17
+ return null;
18
+ }
19
+ currentType = fieldObject.type;
20
+ }
21
+ return fieldObject;
22
+ };
11
23
  const getUnitTypeForTextField = (fieldMeta) => {
12
24
  switch (fieldMeta["ui/type"]) {
13
25
  case "email":
@@ -106,16 +118,17 @@ const migrateUnit = (schema, fromType, unit, units, opts = migrateUnitOptsDefaul
106
118
  };
107
119
  const fixViewUnit = (schema, fromType, unit, units, { unitDefinitions, getDefaultUnitTypeForField, migrateFileCollectionUnit = true }) => {
108
120
  const migrated = migrateUnit(schema, fromType, unit, units, { migrateFileCollectionUnit });
109
- const field = unit.expression?.[0];
110
- const fieldObject = getField(schema, fromType, field);
121
+ const fieldObject = getFieldByExpression(schema, fromType, unit.expression ?? []);
111
122
  if (fieldObject) {
112
- const allowedUnits = unitDefinitions.getUnitsForField(fieldObject);
123
+ const allowedUnits = unitDefinitions.getUnitsForField(fieldObject, {
124
+ depth: unit.expression?.length,
125
+ });
113
126
  if (allowedUnits.some((u) => u.type === migrated.type)) {
114
127
  return migrated;
115
128
  }
116
129
  else {
117
130
  if (unit.checked) {
118
- const otherUnitsForField = units.filter((u) => u !== unit && u.expression && u.expression[0] === field);
131
+ const otherUnitsForField = units.filter((u) => u !== unit && u.expression && unit.expression && u.expression.join("/") === unit.expression.join("/"));
119
132
  const hasEnabledUnitForField = otherUnitsForField.some((u) => u.checked);
120
133
  if (hasEnabledUnitForField) {
121
134
  return utils_1.REMOVE;
@@ -24,23 +24,29 @@ exports.AvatarCollection = {
24
24
  },
25
25
  makeUnit: (0, common_1.makeUnitMethod)(type),
26
26
  getQuerySelect({ typeObject, unit: { expression } }) {
27
- const [userCollectionField] = expression;
28
- const userCollectionFieldObject = typeObject.fieldObjectsByName[userCollectionField];
29
- return {
30
- [userCollectionField]: {
31
- "q/from": [userCollectionField],
32
- "q/select": (0, select_1.mergeDenormalizedSelects)((0, compact_1.default)([
33
- (0, select_1.toSelectMapClause)([
34
- userCollectionFieldObject.typeObject.idField,
35
- userCollectionFieldObject.typeObject.titleField,
36
- ]),
37
- (0, avatar_1.getAvatarSelectQuery)({
38
- typeObject: userCollectionFieldObject.typeObject,
39
- }),
40
- ])),
41
- "q/limit": "q/no-limit",
42
- },
27
+ const fieldObjects = (0, utils_1.getFieldObjectsByFieldExpression)({ typeObject, expression });
28
+ const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
29
+ const collectionSubQuery = {
30
+ "q/from": expression,
31
+ "q/select": (0, select_1.mergeDenormalizedSelects)((0, compact_1.default)([
32
+ (0, select_1.toSelectMapClause)([terminalFieldObject.typeObject.idField, terminalFieldObject.typeObject.titleField]),
33
+ (0, avatar_1.getAvatarSelectQuery)({ typeObject: terminalFieldObject.typeObject }),
34
+ ])),
35
+ "q/limit": "q/no-limit",
43
36
  };
37
+ return [...expression].reverse().reduce((inner, field, reversedIndex) => {
38
+ const originalIndex = expression.length - 1 - reversedIndex;
39
+ const isTerminal = originalIndex === expression.length - 1;
40
+ if (!isTerminal) {
41
+ const pathToField = expression.slice(0, originalIndex + 1);
42
+ const { idField } = fieldObjects[originalIndex].typeObject;
43
+ const innerForField = idField
44
+ ? { [idField]: [...pathToField, idField], ...inner }
45
+ : { ...inner };
46
+ return { [field]: innerForField };
47
+ }
48
+ return { [field]: inner };
49
+ }, collectionSubQuery);
44
50
  },
45
51
  calculateErrors: common_1.calculateUnitExpressionErrors,
46
52
  getExportValue: get_export_value_1.getReferenceCollectionExportValue,
@@ -7,7 +7,6 @@ exports.Avatar = void 0;
7
7
  const compact_1 = __importDefault(require("lodash/compact"));
8
8
  const select_1 = require("@fibery/query-utils/src/select");
9
9
  const utils_1 = require("@fibery/expression-utils/src/utils");
10
- const array_1 = require("@fibery/helpers/utils/array");
11
10
  const avatar_1 = require("../field-utils/avatar");
12
11
  const common_1 = require("../unit-utils/common");
13
12
  const get_export_value_1 = require("../unit-utils/get-export-value");
@@ -47,17 +46,28 @@ exports.Avatar = {
47
46
  if (!expression) {
48
47
  return getSelfAvatarSelectQuery(typeObject);
49
48
  }
50
- const field = (0, array_1.single)(expression);
51
- const fieldObject = typeObject.fieldObjectsByName[field];
52
- if ((0, avatar_1.isAvatarExtensionField)(fieldObject)) {
49
+ const fieldObjects = (0, utils_1.getFieldObjectsByFieldExpression)({ typeObject, expression });
50
+ const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
51
+ if ((0, avatar_1.isAvatarExtensionField)(terminalFieldObject)) {
53
52
  return getSelfAvatarSelectQuery(typeObject);
54
53
  }
55
- return (0, select_1.denormalizeSelect)({
56
- [field]: (0, select_1.normalizeSelect)((0, select_1.mergeDenormalizedSelects)((0, compact_1.default)([
57
- (0, select_1.toSelectMapClause)([fieldObject.typeObject.idField, fieldObject.typeObject.titleField]),
58
- (0, avatar_1.getAvatarSelectQuery)({ typeObject: fieldObject.typeObject }),
59
- ]))),
60
- });
54
+ const innerSelect = (0, select_1.normalizeSelect)((0, select_1.mergeDenormalizedSelects)((0, compact_1.default)([
55
+ (0, select_1.toSelectMapClause)([terminalFieldObject.typeObject.idField, terminalFieldObject.typeObject.titleField]),
56
+ (0, avatar_1.getAvatarSelectQuery)({ typeObject: terminalFieldObject.typeObject }),
57
+ ])));
58
+ // Wrap in the full expression path (innermost to outermost).
59
+ // For intermediate reference fields, also include their entity's id so normalizr can normalize them.
60
+ const nested = [...expression].reverse().reduce((inner, field, reversedIndex) => {
61
+ const originalIndex = expression.length - 1 - reversedIndex;
62
+ const isTerminal = originalIndex === expression.length - 1;
63
+ if (!isTerminal) {
64
+ const { idField } = fieldObjects[originalIndex].typeObject;
65
+ const innerWithId = idField ? { [idField]: idField, ...inner } : inner;
66
+ return { [field]: innerWithId };
67
+ }
68
+ return { [field]: inner };
69
+ }, innerSelect);
70
+ return (0, select_1.denormalizeSelect)(nested);
61
71
  },
62
72
  calculateErrors: common_1.calculateUnitExpressionErrors,
63
73
  getExportValue: ({ typeObject, unit, object }) => {
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CollectionCount = void 0;
4
- const array_1 = require("@fibery/helpers/utils/array");
5
4
  const utils_1 = require("@fibery/expression-utils/src/utils");
6
5
  const reference_collection_1 = require("../field-utils/reference-collection");
7
6
  const common_1 = require("../unit-utils/common");
@@ -20,13 +19,12 @@ exports.CollectionCount = {
20
19
  return `${fieldObject.title} Count`;
21
20
  },
22
21
  getQuerySelect({ unit: { expression } }) {
23
- const field = (0, array_1.single)(expression);
24
- return (0, reference_collection_1.getCollectionCountSelect)(field);
22
+ const countKey = (0, reference_collection_1.getCountKey)(expression.join("/"));
23
+ return { [countKey]: (0, reference_collection_1.makeCollectionCountExpression)(expression) };
25
24
  },
26
25
  calculateErrors: common_1.calculateUnitExpressionErrors,
27
26
  getExportValue: ({ object, unit }) => {
28
- const field = (0, array_1.single)(unit.expression);
29
- return object[(0, reference_collection_1.getCountKey)(field)];
27
+ return object[(0, reference_collection_1.getCountKey)(unit.expression.join("/"))];
30
28
  },
31
29
  canExport: () => true,
32
30
  };
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FileCompactReference = void 0;
4
- const array_1 = require("@fibery/helpers/utils/array");
5
4
  const select_1 = require("@fibery/query-utils/src/select");
6
5
  const utils_1 = require("@fibery/expression-utils/src/utils");
7
6
  const reference_1 = require("../field-utils/reference");
@@ -21,9 +20,20 @@ exports.FileCompactReference = {
21
20
  return { type, kind: "field", expression: args.expression };
22
21
  },
23
22
  getQuerySelect({ typeObject, unit: { expression } }) {
24
- const field = (0, array_1.single)(expression);
25
- const fieldObject = typeObject.fieldObjectsByName[field];
26
- return (0, select_1.denormalizeSelect)({ [field]: (0, reference_1.getReferenceFieldNormalizedSelectClause)(fieldObject, [field]) });
23
+ const fieldObjects = (0, utils_1.getFieldObjectsByFieldExpression)({ typeObject, expression });
24
+ const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
25
+ 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
37
  },
28
38
  calculateErrors({ typeObject, unit }) {
29
39
  return (0, common_1.calculateUnitExpressionErrors)({ typeObject, unit });
@@ -6,6 +6,7 @@ const reference_collection_1 = require("../field-utils/reference-collection");
6
6
  const get_export_value_1 = require("../unit-utils/get-export-value");
7
7
  const get_field_label_1 = require("../unit-utils/get-field-label");
8
8
  const can_edit_field_1 = require("../unit-utils/can-edit-field");
9
+ const utils_1 = require("@fibery/expression-utils/src/utils");
9
10
  const type = "reference-collection";
10
11
  exports.ReferenceCollection = {
11
12
  type,
@@ -13,10 +14,10 @@ exports.ReferenceCollection = {
13
14
  getLabel: get_field_label_1.getFieldLabel,
14
15
  makeUnit: (0, common_1.makeUnitMethod)(type),
15
16
  getQuerySelect({ typeObject, unit: { expression } }) {
16
- const [field] = expression;
17
- const fieldObject = typeObject.fieldObjectsByName[field];
17
+ const fieldObjects = (0, utils_1.getFieldObjectsByFieldExpression)({ typeObject, expression });
18
18
  return (0, reference_collection_1.calculateReferenceCollectionQuery)({
19
- fieldObject,
19
+ fieldObjects,
20
+ expression,
20
21
  limit: reference_collection_1.REFERENCE_COLLECTION_LIMIT,
21
22
  });
22
23
  },
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Reference = void 0;
4
- const array_1 = require("@fibery/helpers/utils/array");
5
4
  const utils_1 = require("@fibery/expression-utils/src/utils");
6
5
  const get_field_label_1 = require("../unit-utils/get-field-label");
7
6
  const select_1 = require("@fibery/query-utils/src/select");
@@ -11,7 +10,7 @@ const get_export_value_1 = require("../unit-utils/get-export-value");
11
10
  const type = "reference";
12
11
  exports.Reference = {
13
12
  type,
14
- name: "Icon + Text",
13
+ name: "Name",
15
14
  getLabel: get_field_label_1.getFieldLabel,
16
15
  makeUnit: (args) => {
17
16
  if (!args) {
@@ -21,9 +20,22 @@ exports.Reference = {
21
20
  return { type, kind: "field", expression: args.expression };
22
21
  },
23
22
  getQuerySelect({ typeObject, unit: { expression } }) {
24
- const field = (0, array_1.single)(expression);
25
- const fieldObject = typeObject.fieldObjectsByName[field];
26
- return (0, select_1.denormalizeSelect)({ [field]: (0, reference_1.getReferenceFieldNormalizedSelectClause)(fieldObject, [field]) });
23
+ const fieldObjects = (0, utils_1.getFieldObjectsByFieldExpression)({ typeObject, expression });
24
+ const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
25
+ const innerNormalized = (0, reference_1.getReferenceFieldNormalizedSelectClause)(terminalFieldObject, expression);
26
+ // Wrap in the full expression path (innermost to outermost).
27
+ // For intermediate reference fields, also include their entity's id so normalizr can normalize them.
28
+ const nested = [...expression].reverse().reduce((inner, field, reversedIndex) => {
29
+ const originalIndex = expression.length - 1 - reversedIndex;
30
+ const isTerminal = originalIndex === expression.length - 1;
31
+ if (!isTerminal) {
32
+ const { idField } = fieldObjects[originalIndex].typeObject;
33
+ const innerWithId = idField ? { [idField]: idField, ...inner } : inner;
34
+ return { [field]: innerWithId };
35
+ }
36
+ return { [field]: inner };
37
+ }, innerNormalized);
38
+ return (0, select_1.denormalizeSelect)(nested);
27
39
  },
28
40
  calculateErrors({ typeObject, unit }) {
29
41
  const errors = (0, common_1.calculateUnitExpressionErrors)({ typeObject, unit });
@@ -145,7 +145,7 @@ function finalise(x, sd, rm) {
145
145
  j = sd;
146
146
  w = xd[(xdi = 0)];
147
147
  // Get the rounding digit at index j of w.
148
- rd = (w / mathpow(10, digits - j - 1)) % 10 | 0;
148
+ rd = ((w / mathpow(10, digits - j - 1)) % 10) | 0;
149
149
  }
150
150
  else {
151
151
  xdi = Math.ceil((i + 1) / LOG_BASE);
@@ -165,7 +165,7 @@ function finalise(x, sd, rm) {
165
165
  // The number of leading zeros of w is given by LOG_BASE - digits.
166
166
  j = i - LOG_BASE + digits;
167
167
  // Get the rounding digit at index j of w.
168
- rd = j < 0 ? 0 : (w / mathpow(10, digits - j - 1)) % 10 | 0;
168
+ rd = j < 0 ? 0 : ((w / mathpow(10, digits - j - 1)) % 10) | 0;
169
169
  }
170
170
  }
171
171
  // Are there any non-zero digits after the rounding digit?
@@ -182,7 +182,7 @@ function finalise(x, sd, rm) {
182
182
  isTruncated ||
183
183
  (rm == 6 &&
184
184
  // Check whether the digit to the left of the rounding digit is odd.
185
- (i > 0 ? (j > 0 ? w / mathpow(10, digits - j) : 0) : xd[xdi - 1]) % 10 & 1) ||
185
+ ((i > 0 ? (j > 0 ? w / mathpow(10, digits - j) : 0) : xd[xdi - 1]) % 10) & 1) ||
186
186
  rm == (x.s < 0 ? 8 : 7)));
187
187
  if (sd < 1 || !xd[0]) {
188
188
  xd.length = 0;
@@ -210,7 +210,7 @@ function finalise(x, sd, rm) {
210
210
  k = mathpow(10, LOG_BASE - i);
211
211
  // E.g. 56700 becomes 56000 if 7 is the rounding digit.
212
212
  // j > 0 means i > number of leading zeros of w.
213
- xd[xdi] = j > 0 ? ((w / mathpow(10, digits - j)) % mathpow(10, j) | 0) * k : 0;
213
+ xd[xdi] = j > 0 ? (((w / mathpow(10, digits - j)) % mathpow(10, j)) | 0) * k : 0;
214
214
  }
215
215
  if (roundUp) {
216
216
  for (;;) {
@@ -277,10 +277,14 @@ function parseDecimal(x, str) {
277
277
  }
278
278
  let i;
279
279
  // Determine leading zeros.
280
- for (i = 0; str.charCodeAt(i) === 48; i++) { }
280
+ for (i = 0; str.charCodeAt(i) === 48; i++) {
281
+ /* empty */
282
+ }
281
283
  let len;
282
284
  // Determine trailing zeros.
283
- for (len = str.length; str.charCodeAt(len - 1) === 48; --len) { }
285
+ for (len = str.length; str.charCodeAt(len - 1) === 48; --len) {
286
+ /* empty */
287
+ }
284
288
  str = str.slice(i, len);
285
289
  if (str) {
286
290
  len -= i;
@@ -10,7 +10,7 @@ export declare const getReferenceCollectionExportValue: ({ unit, typeObject, obj
10
10
  object: FiberyObject;
11
11
  unit: FieldUnit;
12
12
  typeObject: TypeObject;
13
- }) => FiberyObject[] | (string | undefined)[] | null;
13
+ }) => (string | undefined)[] | FiberyObject[] | null;
14
14
  export declare const getReferenceExportValue: ({ unit, typeObject, object, }: {
15
15
  object: FiberyObject;
16
16
  unit: FieldUnit;
@@ -4,7 +4,7 @@ exports.getFieldLabel = void 0;
4
4
  const utils_1 = require("@fibery/expression-utils/src/utils");
5
5
  const getFieldLabel = ({ typeObject, unit }) => {
6
6
  const { expression } = unit;
7
- const fieldObject = (0, utils_1.getFieldObjectByFieldExpression)({ typeObject, expression });
8
- return fieldObject.title;
7
+ const fieldObjects = (0, utils_1.getFieldObjectsByFieldExpression)({ typeObject, expression });
8
+ return fieldObjects.map((fieldObject) => fieldObject.title).join(" -> ");
9
9
  };
10
10
  exports.getFieldLabel = getFieldLabel;
@@ -1,22 +1,25 @@
1
1
  import { TypeObject } from "@fibery/schema";
2
2
  export declare const getTypeUnits: () => import("./types").PureUnit[], getUnitName: (unit: import("./types").Unit) => string | null, getUnitsForType: (typeObject: TypeObject, options?: {
3
+ parentExpression?: import("@fibery/expression-utils").FieldExpression;
3
4
  showHiddenFields?: boolean;
4
5
  isSharingMode?: boolean;
5
6
  }) => {
6
7
  unit: import("./types").Unit;
7
8
  fieldObject: import("@fibery/schema").FieldObject;
8
9
  }[], getUnitsForField: (fieldObject: import("@fibery/schema").FieldObject, options?: {
10
+ parentExpression?: import("@fibery/expression-utils").FieldExpression;
9
11
  showHiddenFields?: boolean;
10
12
  isSharingMode?: boolean;
11
13
  }) => import("./types").Unit[], getUnitsForTypePerField: (typeObject: TypeObject, options?: {
14
+ parentExpression?: import("@fibery/expression-utils").FieldExpression;
12
15
  showHiddenFields?: boolean;
13
16
  isSharingMode?: boolean;
14
17
  }) => {
15
18
  fieldObject: import("@fibery/schema").FieldObject;
16
19
  units: import("./types").Unit[];
17
- }[], getUnitLabel: (fieldObject: import("@fibery/schema").FieldObject, unit: import("./types").Unit) => string, getHardcodedUnitsForView: (typeObject: TypeObject) => ({
18
- expression: import("./types").UnitExpression;
20
+ }[], getUnitLabel: (typeObject: TypeObject, unit: import("./types").Unit) => string, getHardcodedUnitsForView: (typeObject: TypeObject) => ({
19
21
  type: "avatar" | "avatar-collection" | "avatar-input" | "back-references-list" | "bool" | "bool-checkbox" | "collection-count" | "color-input" | "comments-list" | "date" | "date-time" | "date-time-combobox" | "date-range" | "date-range-combobox" | "email" | "email-input" | "emoji" | "field" | "files-gallery" | "files-list" | "files-list-item" | "files-l-list" | "files-l-list-item" | "file-reference" | "file-compact-collection" | "file-compact-reference" | "file-collection-count" | "geometry-preview" | "icon-button" | "icon-input" | "id" | "json-input" | "location" | "location-input" | "number" | "number-input" | "phone" | "phone-input" | "progress-bar" | "reference" | "reference-icon" | "reference-combobox" | "reference-collection" | "reference-collection-list" | "reference-collection-view" | "reference-collection-combobox" | "rich-text-snippet" | "rich-text-document" | "single-location-preview" | "text" | "text-input" | "title" | "title-input" | "url" | "url-input" | "user-role" | "user-role-input";
22
+ expression: import("./types").UnitExpression;
20
23
  kind: "field";
21
24
  settings?: Record<string, unknown> | undefined;
22
25
  hideWhenEmpty?: boolean | undefined;
@@ -31,8 +34,8 @@ export declare const getTypeUnits: () => import("./types").PureUnit[], getUnitNa
31
34
  label: string;
32
35
  icon?: string | undefined;
33
36
  } | {
34
- expression?: import("./types").UnitExpression | undefined;
35
37
  type: "type-icon" | "type-badge" | "type-badge-abbr";
38
+ expression?: import("./types").UnitExpression | undefined;
36
39
  kind: "db";
37
40
  hideWhenEmpty?: boolean | undefined;
38
41
  })[], getCardUnitsSelect: ({ schema, typeObject, units }: {
@@ -1,25 +1,28 @@
1
1
  export declare const getTypeUnits: () => import("../types").PureUnit[], getUnitName: (unit: import("../types").Unit) => string | null, getUnitsForField: (fieldObject: import("@fibery/schema").FieldObject, options?: {
2
+ parentExpression?: import("@fibery/expression-utils").FieldExpression;
2
3
  showHiddenFields?: boolean;
3
4
  isSharingMode?: boolean;
4
5
  }) => import("../types").Unit[], getUnitsForType: (typeObject: import("@fibery/schema").TypeObject, options?: {
6
+ parentExpression?: import("@fibery/expression-utils").FieldExpression;
5
7
  showHiddenFields?: boolean;
6
8
  isSharingMode?: boolean;
7
9
  }) => {
8
10
  unit: import("../types").Unit;
9
11
  fieldObject: import("@fibery/schema").FieldObject;
10
12
  }[], getUnitsForTypePerField: (typeObject: import("@fibery/schema").TypeObject, options?: {
13
+ parentExpression?: import("@fibery/expression-utils").FieldExpression;
11
14
  showHiddenFields?: boolean;
12
15
  isSharingMode?: boolean;
13
16
  }) => {
14
17
  fieldObject: import("@fibery/schema").FieldObject;
15
18
  units: import("../types").Unit[];
16
- }[], getUnitLabel: (fieldObject: import("@fibery/schema").FieldObject, unit: import("../types").Unit) => string, getCardUnitsSelect: ({ schema, typeObject, units }: {
19
+ }[], getUnitLabel: (typeObject: import("@fibery/schema").TypeObject, unit: import("../types").Unit) => string, getCardUnitsSelect: ({ schema, typeObject, units }: {
17
20
  schema: import("@fibery/schema").Schema;
18
21
  typeObject: import("@fibery/schema").TypeObject;
19
22
  units: import("../types").Unit[];
20
23
  }) => any, getHardcodedUnitsForView: (typeObject: import("@fibery/schema").TypeObject) => ({
21
- expression: import("../types").UnitExpression;
22
24
  type: "avatar" | "avatar-collection" | "avatar-input" | "back-references-list" | "bool" | "bool-checkbox" | "collection-count" | "color-input" | "comments-list" | "date" | "date-time" | "date-time-combobox" | "date-range" | "date-range-combobox" | "email" | "email-input" | "emoji" | "field" | "files-gallery" | "files-list" | "files-list-item" | "files-l-list" | "files-l-list-item" | "file-reference" | "file-compact-collection" | "file-compact-reference" | "file-collection-count" | "geometry-preview" | "icon-button" | "icon-input" | "id" | "json-input" | "location" | "location-input" | "number" | "number-input" | "phone" | "phone-input" | "progress-bar" | "reference" | "reference-icon" | "reference-combobox" | "reference-collection" | "reference-collection-list" | "reference-collection-view" | "reference-collection-combobox" | "rich-text-snippet" | "rich-text-document" | "single-location-preview" | "text" | "text-input" | "title" | "title-input" | "url" | "url-input" | "user-role" | "user-role-input";
25
+ expression: import("../types").UnitExpression;
23
26
  kind: "field";
24
27
  settings?: Record<string, unknown> | undefined;
25
28
  hideWhenEmpty?: boolean | undefined;
@@ -34,8 +37,8 @@ export declare const getTypeUnits: () => import("../types").PureUnit[], getUnitN
34
37
  label: string;
35
38
  icon?: string | undefined;
36
39
  } | {
37
- expression?: import("../types").UnitExpression | undefined;
38
40
  type: "type-icon" | "type-badge" | "type-badge-abbr";
41
+ expression?: import("../types").UnitExpression | undefined;
39
42
  kind: "db";
40
43
  hideWhenEmpty?: boolean | undefined;
41
44
  })[];
@@ -1,14 +1,17 @@
1
1
  import { TypeObject } from "@fibery/schema";
2
2
  export declare const getTypeUnits: () => import("./types").PureUnit[], getUnitName: (unit: import("./types").Unit) => string | null, getUnitsForType: (typeObject: TypeObject, options?: {
3
+ parentExpression?: import("@fibery/expression-utils").FieldExpression;
3
4
  showHiddenFields?: boolean;
4
5
  isSharingMode?: boolean;
5
6
  }) => {
6
7
  unit: import("./types").Unit;
7
8
  fieldObject: import("@fibery/schema").FieldObject;
8
9
  }[], getUnitsForField: (fieldObject: import("@fibery/schema").FieldObject, options?: {
10
+ parentExpression?: import("@fibery/expression-utils").FieldExpression;
9
11
  showHiddenFields?: boolean;
10
12
  isSharingMode?: boolean;
11
13
  }) => import("./types").Unit[], getUnitsForTypePerField: (typeObject: TypeObject, options?: {
14
+ parentExpression?: import("@fibery/expression-utils").FieldExpression;
12
15
  showHiddenFields?: boolean;
13
16
  isSharingMode?: boolean;
14
17
  }) => {
@@ -18,9 +21,9 @@ export declare const getTypeUnits: () => import("./types").PureUnit[], getUnitNa
18
21
  schema: import("@fibery/schema").Schema;
19
22
  typeObject: TypeObject;
20
23
  units: import("./types").Unit[];
21
- }) => any, getUnitLabel: (fieldObject: import("@fibery/schema").FieldObject, unit: import("./types").Unit) => string, getHardcodedUnitsForView: (typeObject: TypeObject) => ({
22
- expression: import("./types").UnitExpression;
24
+ }) => any, getUnitLabel: (typeObject: TypeObject, unit: import("./types").Unit) => string, getHardcodedUnitsForView: (typeObject: TypeObject) => ({
23
25
  type: "avatar" | "avatar-collection" | "avatar-input" | "back-references-list" | "bool" | "bool-checkbox" | "collection-count" | "color-input" | "comments-list" | "date" | "date-time" | "date-time-combobox" | "date-range" | "date-range-combobox" | "email" | "email-input" | "emoji" | "field" | "files-gallery" | "files-list" | "files-list-item" | "files-l-list" | "files-l-list-item" | "file-reference" | "file-compact-collection" | "file-compact-reference" | "file-collection-count" | "geometry-preview" | "icon-button" | "icon-input" | "id" | "json-input" | "location" | "location-input" | "number" | "number-input" | "phone" | "phone-input" | "progress-bar" | "reference" | "reference-icon" | "reference-combobox" | "reference-collection" | "reference-collection-list" | "reference-collection-view" | "reference-collection-combobox" | "rich-text-snippet" | "rich-text-document" | "single-location-preview" | "text" | "text-input" | "title" | "title-input" | "url" | "url-input" | "user-role" | "user-role-input";
26
+ expression: import("./types").UnitExpression;
24
27
  kind: "field";
25
28
  settings?: Record<string, unknown> | undefined;
26
29
  hideWhenEmpty?: boolean | undefined;
@@ -35,8 +38,8 @@ export declare const getTypeUnits: () => import("./types").PureUnit[], getUnitNa
35
38
  label: string;
36
39
  icon?: string | undefined;
37
40
  } | {
38
- expression?: import("./types").UnitExpression | undefined;
39
41
  type: "type-icon" | "type-badge" | "type-badge-abbr";
42
+ expression?: import("./types").UnitExpression | undefined;
40
43
  kind: "db";
41
44
  hideWhenEmpty?: boolean | undefined;
42
45
  })[];
@@ -1,14 +1,17 @@
1
1
  import { TypeObject } from "@fibery/schema";
2
2
  export declare const getTypeUnits: () => import("./types").PureUnit[], getUnitName: (unit: import("./types").Unit) => string | null, getUnitsForType: (typeObject: TypeObject, options?: {
3
+ parentExpression?: import("@fibery/expression-utils").FieldExpression;
3
4
  showHiddenFields?: boolean;
4
5
  isSharingMode?: boolean;
5
6
  }) => {
6
7
  unit: import("./types").Unit;
7
8
  fieldObject: import("@fibery/schema").FieldObject;
8
9
  }[], getUnitsForField: (fieldObject: import("@fibery/schema").FieldObject, options?: {
10
+ parentExpression?: import("@fibery/expression-utils").FieldExpression;
9
11
  showHiddenFields?: boolean;
10
12
  isSharingMode?: boolean;
11
13
  }) => import("./types").Unit[], getUnitsForTypePerField: (typeObject: TypeObject, options?: {
14
+ parentExpression?: import("@fibery/expression-utils").FieldExpression;
12
15
  showHiddenFields?: boolean;
13
16
  isSharingMode?: boolean;
14
17
  }) => {
@@ -18,9 +21,9 @@ export declare const getTypeUnits: () => import("./types").PureUnit[], getUnitNa
18
21
  schema: import("@fibery/schema").Schema;
19
22
  typeObject: TypeObject;
20
23
  units: import("./types").Unit[];
21
- }) => any, getUnitLabel: (fieldObject: import("@fibery/schema").FieldObject, unit: import("./types").Unit) => string, getHardcodedUnitsForView: (typeObject: TypeObject) => ({
22
- expression: import("./types").UnitExpression;
24
+ }) => any, getUnitLabel: (typeObject: TypeObject, unit: import("./types").Unit) => string, getHardcodedUnitsForView: (typeObject: TypeObject) => ({
23
25
  type: "avatar" | "avatar-collection" | "avatar-input" | "back-references-list" | "bool" | "bool-checkbox" | "collection-count" | "color-input" | "comments-list" | "date" | "date-time" | "date-time-combobox" | "date-range" | "date-range-combobox" | "email" | "email-input" | "emoji" | "field" | "files-gallery" | "files-list" | "files-list-item" | "files-l-list" | "files-l-list-item" | "file-reference" | "file-compact-collection" | "file-compact-reference" | "file-collection-count" | "geometry-preview" | "icon-button" | "icon-input" | "id" | "json-input" | "location" | "location-input" | "number" | "number-input" | "phone" | "phone-input" | "progress-bar" | "reference" | "reference-icon" | "reference-combobox" | "reference-collection" | "reference-collection-list" | "reference-collection-view" | "reference-collection-combobox" | "rich-text-snippet" | "rich-text-document" | "single-location-preview" | "text" | "text-input" | "title" | "title-input" | "url" | "url-input" | "user-role" | "user-role-input";
26
+ expression: import("./types").UnitExpression;
24
27
  kind: "field";
25
28
  settings?: Record<string, unknown> | undefined;
26
29
  hideWhenEmpty?: boolean | undefined;
@@ -35,8 +38,8 @@ export declare const getTypeUnits: () => import("./types").PureUnit[], getUnitNa
35
38
  label: string;
36
39
  icon?: string | undefined;
37
40
  } | {
38
- expression?: import("./types").UnitExpression | undefined;
39
41
  type: "type-icon" | "type-badge" | "type-badge-abbr";
42
+ expression?: import("./types").UnitExpression | undefined;
40
43
  kind: "db";
41
44
  hideWhenEmpty?: boolean | undefined;
42
45
  })[];
@@ -1,25 +1,28 @@
1
1
  export declare const getTypeUnits: () => import("./types").PureUnit[], getUnitName: (unit: import("./types").Unit) => string | null, getUnitsForType: (typeObject: import("@fibery/schema").TypeObject, options?: {
2
+ parentExpression?: import("@fibery/expression-utils").FieldExpression;
2
3
  showHiddenFields?: boolean;
3
4
  isSharingMode?: boolean;
4
5
  }) => {
5
6
  unit: import("./types").Unit;
6
7
  fieldObject: import("@fibery/schema").FieldObject;
7
8
  }[], getUnitsForField: (fieldObject: import("@fibery/schema").FieldObject, options?: {
9
+ parentExpression?: import("@fibery/expression-utils").FieldExpression;
8
10
  showHiddenFields?: boolean;
9
11
  isSharingMode?: boolean;
10
12
  }) => import("./types").Unit[], getUnitsForTypePerField: (typeObject: import("@fibery/schema").TypeObject, options?: {
13
+ parentExpression?: import("@fibery/expression-utils").FieldExpression;
11
14
  showHiddenFields?: boolean;
12
15
  isSharingMode?: boolean;
13
16
  }) => {
14
17
  fieldObject: import("@fibery/schema").FieldObject;
15
18
  units: import("./types").Unit[];
16
- }[], getUnitLabel: (fieldObject: import("@fibery/schema").FieldObject, unit: import("./types").Unit) => string, getCardUnitsSelect: ({ schema, typeObject, units }: {
19
+ }[], getUnitLabel: (typeObject: import("@fibery/schema").TypeObject, unit: import("./types").Unit) => string, getCardUnitsSelect: ({ schema, typeObject, units }: {
17
20
  schema: import("@fibery/schema").Schema;
18
21
  typeObject: import("@fibery/schema").TypeObject;
19
22
  units: import("./types").Unit[];
20
23
  }) => any, getHardcodedUnitsForView: (typeObject: import("@fibery/schema").TypeObject) => ({
21
- expression: import("./types").UnitExpression;
22
24
  type: "avatar" | "avatar-collection" | "avatar-input" | "back-references-list" | "bool" | "bool-checkbox" | "collection-count" | "color-input" | "comments-list" | "date" | "date-time" | "date-time-combobox" | "date-range" | "date-range-combobox" | "email" | "email-input" | "emoji" | "field" | "files-gallery" | "files-list" | "files-list-item" | "files-l-list" | "files-l-list-item" | "file-reference" | "file-compact-collection" | "file-compact-reference" | "file-collection-count" | "geometry-preview" | "icon-button" | "icon-input" | "id" | "json-input" | "location" | "location-input" | "number" | "number-input" | "phone" | "phone-input" | "progress-bar" | "reference" | "reference-icon" | "reference-combobox" | "reference-collection" | "reference-collection-list" | "reference-collection-view" | "reference-collection-combobox" | "rich-text-snippet" | "rich-text-document" | "single-location-preview" | "text" | "text-input" | "title" | "title-input" | "url" | "url-input" | "user-role" | "user-role-input";
25
+ expression: import("./types").UnitExpression;
23
26
  kind: "field";
24
27
  settings?: Record<string, unknown> | undefined;
25
28
  hideWhenEmpty?: boolean | undefined;
@@ -34,8 +37,8 @@ export declare const getTypeUnits: () => import("./types").PureUnit[], getUnitNa
34
37
  label: string;
35
38
  icon?: string | undefined;
36
39
  } | {
37
- expression?: import("./types").UnitExpression | undefined;
38
40
  type: "type-icon" | "type-badge" | "type-badge-abbr";
41
+ expression?: import("./types").UnitExpression | undefined;
39
42
  kind: "db";
40
43
  hideWhenEmpty?: boolean | undefined;
41
44
  })[];
@@ -30,6 +30,8 @@ const url_1 = require("../unit-definitions/url");
30
30
  const user_button_1 = require("../unit-definitions/user-button");
31
31
  const user_role_1 = require("../unit-definitions/user-role");
32
32
  const file_collection_count_1 = require("../unit-definitions/file-collection-count");
33
+ const files_gallery_1 = require("../unit-definitions/files-gallery");
34
+ const file_reference_1 = require("@fibery/views/src/unit-definitions/file-reference");
33
35
  const allUnitDefinitions = {
34
36
  AvatarCollection: avatar_collection_1.AvatarCollection,
35
37
  Bool: bool_1.Bool,
@@ -58,6 +60,8 @@ const allUnitDefinitions = {
58
60
  IconButton: icon_button_1.IconButton,
59
61
  UserRole: user_role_1.UserRole,
60
62
  FileCollectionCount: file_collection_count_1.FileCollectionCount,
63
+ FilesGallery: files_gallery_1.FilesGallery,
64
+ FileReference: file_reference_1.FileReference,
61
65
  };
62
66
  _a = (0, make_factory_1.makeUnitDefinitionsFactory)(allUnitDefinitions), exports.getTypeUnits = _a.getTypeUnits, exports.getUnitName = _a.getUnitName, exports.getUnitsForType = _a.getUnitsForType, exports.getUnitsForField = _a.getUnitsForField, exports.getUnitsForTypePerField = _a.getUnitsForTypePerField, exports.getUnitLabel = _a.getUnitLabel, exports.getCardUnitsSelect = _a.getCardUnitsSelect, exports.getHardcodedUnitsForView = _a.getHardcodedUnitsForView;
63
67
  const getDefaultUnits = () => {
@@ -1,26 +1,29 @@
1
1
  import { TypeObject } from "@fibery/schema";
2
2
  export declare const getTypeUnits: () => import("./types").PureUnit[], getUnitName: (unit: import("./types").Unit) => string | null, getUnitsForType: (typeObject: TypeObject, options?: {
3
+ parentExpression?: import("@fibery/expression-utils").FieldExpression;
3
4
  showHiddenFields?: boolean;
4
5
  isSharingMode?: boolean;
5
6
  }) => {
6
7
  unit: import("./types").Unit;
7
8
  fieldObject: import("@fibery/schema").FieldObject;
8
9
  }[], getUnitsForField: (fieldObject: import("@fibery/schema").FieldObject, options?: {
10
+ parentExpression?: import("@fibery/expression-utils").FieldExpression;
9
11
  showHiddenFields?: boolean;
10
12
  isSharingMode?: boolean;
11
13
  }) => import("./types").Unit[], getUnitsForTypePerField: (typeObject: TypeObject, options?: {
14
+ parentExpression?: import("@fibery/expression-utils").FieldExpression;
12
15
  showHiddenFields?: boolean;
13
16
  isSharingMode?: boolean;
14
17
  }) => {
15
18
  fieldObject: import("@fibery/schema").FieldObject;
16
19
  units: import("./types").Unit[];
17
- }[], getUnitLabel: (fieldObject: import("@fibery/schema").FieldObject, unit: import("./types").Unit) => string, getCardUnitsSelect: ({ schema, typeObject, units }: {
20
+ }[], getUnitLabel: (typeObject: TypeObject, unit: import("./types").Unit) => string, getCardUnitsSelect: ({ schema, typeObject, units }: {
18
21
  schema: import("@fibery/schema").Schema;
19
22
  typeObject: TypeObject;
20
23
  units: import("./types").Unit[];
21
24
  }) => any, getHardcodedUnitsForView: (typeObject: TypeObject) => ({
22
- expression: import("./types").UnitExpression;
23
25
  type: "avatar" | "avatar-collection" | "avatar-input" | "back-references-list" | "bool" | "bool-checkbox" | "collection-count" | "color-input" | "comments-list" | "date" | "date-time" | "date-time-combobox" | "date-range" | "date-range-combobox" | "email" | "email-input" | "emoji" | "field" | "files-gallery" | "files-list" | "files-list-item" | "files-l-list" | "files-l-list-item" | "file-reference" | "file-compact-collection" | "file-compact-reference" | "file-collection-count" | "geometry-preview" | "icon-button" | "icon-input" | "id" | "json-input" | "location" | "location-input" | "number" | "number-input" | "phone" | "phone-input" | "progress-bar" | "reference" | "reference-icon" | "reference-combobox" | "reference-collection" | "reference-collection-list" | "reference-collection-view" | "reference-collection-combobox" | "rich-text-snippet" | "rich-text-document" | "single-location-preview" | "text" | "text-input" | "title" | "title-input" | "url" | "url-input" | "user-role" | "user-role-input";
26
+ expression: import("./types").UnitExpression;
24
27
  kind: "field";
25
28
  settings?: Record<string, unknown> | undefined;
26
29
  hideWhenEmpty?: boolean | undefined;
@@ -35,8 +38,8 @@ export declare const getTypeUnits: () => import("./types").PureUnit[], getUnitNa
35
38
  label: string;
36
39
  icon?: string | undefined;
37
40
  } | {
38
- expression?: import("./types").UnitExpression | undefined;
39
41
  type: "type-icon" | "type-badge" | "type-badge-abbr";
42
+ expression?: import("./types").UnitExpression | undefined;
40
43
  kind: "db";
41
44
  hideWhenEmpty?: boolean | undefined;
42
45
  })[];
@@ -1,24 +1,26 @@
1
+ import { FieldExpression } from "@fibery/expression-utils";
1
2
  import { FieldObject, Schema, TypeObject } from "@fibery/schema";
2
- import { ButtonUnit, DbUnit, FieldUnit, Unit, UnitDataDefinition } from "./types";
3
+ import { ButtonUnit, DbUnit, FieldUnit, Unit, UnitDataDefinition, UnitExpression } from "./types";
3
4
  type AnyUnitDataDefinition = UnitDataDefinition<FieldUnit> | UnitDataDefinition<DbUnit> | UnitDataDefinition<ButtonUnit>;
4
- type UnitFilterOptions = {
5
+ type UnitCreationOptions = {
6
+ parentExpression?: FieldExpression;
5
7
  showHiddenFields?: boolean;
6
8
  isSharingMode?: boolean;
7
9
  };
8
10
  export declare const makeUnitDefinitionsFactory: (allUnitDefinitions: Record<string, AnyUnitDataDefinition>) => {
9
11
  getTypeUnits: () => import("./types").PureUnit[];
10
- getUnitsForType: (typeObject: TypeObject, options?: UnitFilterOptions) => {
12
+ getUnitsForType: (typeObject: TypeObject, options?: UnitCreationOptions) => {
11
13
  unit: Unit;
12
14
  fieldObject: FieldObject;
13
15
  }[];
14
- getUnitsForTypePerField: (typeObject: TypeObject, options?: UnitFilterOptions) => {
16
+ getUnitsForTypePerField: (typeObject: TypeObject, options?: UnitCreationOptions) => {
15
17
  fieldObject: FieldObject;
16
18
  units: Unit[];
17
19
  }[];
18
- getUnitsForField: (fieldObject: FieldObject, options?: UnitFilterOptions) => Unit[];
20
+ getUnitsForField: (fieldObject: FieldObject, options?: UnitCreationOptions) => Unit[];
19
21
  getHardcodedUnitsForView: (typeObject: TypeObject) => ({
20
- expression: import("./types").UnitExpression;
21
22
  type: "avatar" | "avatar-collection" | "avatar-input" | "back-references-list" | "bool" | "bool-checkbox" | "collection-count" | "color-input" | "comments-list" | "date" | "date-time" | "date-time-combobox" | "date-range" | "date-range-combobox" | "email" | "email-input" | "emoji" | "field" | "files-gallery" | "files-list" | "files-list-item" | "files-l-list" | "files-l-list-item" | "file-reference" | "file-compact-collection" | "file-compact-reference" | "file-collection-count" | "geometry-preview" | "icon-button" | "icon-input" | "id" | "json-input" | "location" | "location-input" | "number" | "number-input" | "phone" | "phone-input" | "progress-bar" | "reference" | "reference-icon" | "reference-combobox" | "reference-collection" | "reference-collection-list" | "reference-collection-view" | "reference-collection-combobox" | "rich-text-snippet" | "rich-text-document" | "single-location-preview" | "text" | "text-input" | "title" | "title-input" | "url" | "url-input" | "user-role" | "user-role-input";
23
+ expression: UnitExpression;
22
24
  kind: "field";
23
25
  settings?: Record<string, unknown> | undefined;
24
26
  hideWhenEmpty?: boolean | undefined;
@@ -33,12 +35,12 @@ export declare const makeUnitDefinitionsFactory: (allUnitDefinitions: Record<str
33
35
  label: string;
34
36
  icon?: string | undefined;
35
37
  } | {
36
- expression?: import("./types").UnitExpression | undefined;
37
38
  type: "type-icon" | "type-badge" | "type-badge-abbr";
39
+ expression?: UnitExpression | undefined;
38
40
  kind: "db";
39
41
  hideWhenEmpty?: boolean | undefined;
40
42
  })[];
41
- getUnitLabel: (fieldObject: FieldObject, unit: Unit) => string;
43
+ getUnitLabel: (typeObject: TypeObject, unit: Unit) => string;
42
44
  getUnitName: (unit: Unit) => string | null;
43
45
  getCardUnitsSelect: ({ schema, typeObject, units }: {
44
46
  schema: Schema;
@@ -70,6 +70,9 @@ const makeUnitDefinitionsFactory = (allUnitDefinitions) => {
70
70
  if (FileReference && FileCompactReference && fieldObject.typeObject.name === "fibery/file") {
71
71
  return [FileLListItem, FileCompactReference, FileListItem, FileReference].filter(Boolean);
72
72
  }
73
+ if (FileReference && fieldObject.typeObject.name === "fibery/file") {
74
+ return [Reference, FileReference].filter(Boolean);
75
+ }
73
76
  return [
74
77
  (0, avatar_1.isAvatarExtensionEnabledType)(fieldObject.typeObject) && Avatar,
75
78
  fieldObject.name === "workflow/state" && ReferenceIcon,
@@ -78,8 +81,9 @@ const makeUnitDefinitionsFactory = (allUnitDefinitions) => {
78
81
  ];
79
82
  },
80
83
  ":field/reference-collection": (fieldObject, options) => {
84
+ const isTopLevel = (options.parentExpression?.length ?? 0) === 0;
81
85
  const common = [CollectionCount, (0, avatar_1.isAvatarExtensionEnabledType)(fieldObject.typeObject) && AvatarCollection];
82
- if ((0, relation_view_1.isRelationViewField)(fieldObject) && !options.isSharingMode) {
86
+ if ((0, relation_view_1.isRelationViewField)(fieldObject) && !options.isSharingMode && isTopLevel) {
83
87
  return [...common, ReferenceCollection, ReferenceCollectionCombobox, ReferenceCollectionView];
84
88
  }
85
89
  if ((0, back_references_1.isReferenceExtensionField)(fieldObject)) {
@@ -110,15 +114,16 @@ const makeUnitDefinitionsFactory = (allUnitDefinitions) => {
110
114
  },
111
115
  };
112
116
  const getUnitsForField = (fieldObject, options = {}) => {
113
- const makeUnit = (Unit) => Unit.makeUnit({ expression: [fieldObject.name] });
114
- const { showHiddenFields } = options;
115
- if (fieldObject.isPublicId) {
117
+ const { showHiddenFields, parentExpression = [] } = options;
118
+ const makeUnit = (Unit) => Unit.makeUnit({ expression: [...parentExpression, fieldObject.name] });
119
+ const isTopLevel = (options.parentExpression?.length ?? 0) === 0;
120
+ if (fieldObject.isPublicId && isTopLevel) {
116
121
  return [Id].filter(Boolean).map(makeUnit);
117
122
  }
118
- if (fieldObject.isTitle) {
123
+ if (fieldObject.isTitle && isTopLevel) {
119
124
  return [Title, TitleInput].filter(Boolean).map(makeUnit);
120
125
  }
121
- if ((0, avatar_1.isAvatarExtensionField)(fieldObject)) {
126
+ if ((0, avatar_1.isAvatarExtensionField)(fieldObject) && isTopLevel) {
122
127
  return [Avatar, AvatarInput].filter(Boolean).map(makeUnit);
123
128
  }
124
129
  if (fieldObject.type === "Collaboration~Documents/Document") {
@@ -188,12 +193,12 @@ const makeUnitDefinitionsFactory = (allUnitDefinitions) => {
188
193
  ].filter(Boolean);
189
194
  };
190
195
  const unitDefinitionsByTypeLookup = (0, mapValues_1.default)((0, groupBy_1.default)(allUnitDefinitions, (x) => x.type), (value) => (0, array_1.single)(value));
191
- const getUnitLabel = (fieldObject, unit) => {
196
+ const getUnitLabel = (typeObject, unit) => {
192
197
  const unitDefinition = unitDefinitionsByTypeLookup[unit.type];
193
198
  if (!unitDefinition) {
194
199
  return "";
195
200
  }
196
- return unitDefinition.getLabel({ typeObject: fieldObject.holderTypeObject, unit: unit });
201
+ return unitDefinition.getLabel({ typeObject, unit: unit });
197
202
  };
198
203
  const getUnitName = (unit) => {
199
204
  const unitDefinition = unitDefinitionsByTypeLookup[unit.type];
@@ -224,7 +229,7 @@ const makeUnitDefinitionsFactory = (allUnitDefinitions) => {
224
229
  return {};
225
230
  }
226
231
  const UnitDefinition = getUnitDataDefinition(unit);
227
- const select = UnitDefinition.getQuerySelect({ schema, typeObject, unit: unit });
232
+ const select = UnitDefinition.getQuerySelect({ schema, typeObject, unit });
228
233
  (0, trace_1.assert)((0, isPlainObject_1.default)(select), "getQuerySelect must return object-shaped select");
229
234
  return select;
230
235
  });
package/package.json CHANGED
@@ -1,46 +1,45 @@
1
1
  {
2
2
  "name": "@fibery/views",
3
- "version": "18.0.4",
3
+ "version": "19.0.0",
4
+ "private": false,
4
5
  "description": "Operations on view objects",
5
6
  "license": "UNLICENSED",
6
7
  "author": "Fibery",
7
- "main": "./lib/index.js",
8
- "types": "./lib/index.d.ts",
9
8
  "files": [
10
9
  "/lib"
11
10
  ],
12
- "private": false,
11
+ "main": "./lib/index.js",
13
12
  "exports": {
14
13
  ".": {
15
14
  "types": "./lib/index.d.ts",
15
+ "@fibery/source": "./index.ts",
16
16
  "default": "./lib/index.js"
17
17
  },
18
18
  "./src/*": {
19
19
  "types": "./lib/src/*.d.ts",
20
+ "@fibery/source": "./src/*",
20
21
  "default": "./lib/src/*.js"
21
22
  },
22
23
  "./src/unit-definitions": {
23
24
  "types": "./lib/src/unit-definitions/index.d.ts",
25
+ "@fibery/source": "./src/unit-definitions/index.ts",
24
26
  "default": "./lib/src/unit-definitions/index.js"
25
27
  },
26
28
  "./src/units/canvas": {
27
29
  "types": "./lib/src/units/canvas/index.d.ts",
30
+ "@fibery/source": "./src/units/canvas/index.ts",
28
31
  "default": "./lib/src/units/canvas/index.js"
29
32
  }
30
33
  },
31
- "fiberyDevExports": {
32
- ".": "./index.ts",
33
- "./src/*": "./src/*"
34
- },
35
34
  "dependencies": {
36
35
  "date-fns": "2.29.2",
37
36
  "lodash": "4.17.21",
38
37
  "moment": "2.29.4",
39
38
  "@fibery/context-filters": "1.1.4",
40
- "@fibery/query-utils": "1.1.4",
41
- "@fibery/expression-utils": "9.6.4",
42
- "@fibery/schema": "10.2.15",
43
- "@fibery/helpers": "2.0.0"
39
+ "@fibery/expression-utils": "9.7.0",
40
+ "@fibery/helpers": "2.0.0",
41
+ "@fibery/query-utils": "1.1.5",
42
+ "@fibery/schema": "10.2.15"
44
43
  },
45
44
  "devDependencies": {
46
45
  "@babel/core": "7.28.5",
@@ -49,21 +48,22 @@
49
48
  "immutability-helper": "2.4.0",
50
49
  "jest": "30.2.0",
51
50
  "jest-junit": "16.0.0",
52
- "typescript": "5.9.3",
53
- "@fibery/babel-preset": "7.4.2",
54
- "@fibery/eslint-config": "9.0.1"
51
+ "typescript": "6.0.0-beta",
52
+ "@fibery/babel-preset": "7.4.2"
55
53
  },
56
54
  "peerDependencies": {
57
- "@fibery/expression-utils": "^9.6.4",
55
+ "@fibery/expression-utils": "^9.7.0",
58
56
  "@fibery/schema": "^10.2.15",
59
57
  "immutability-helper": "^2.4.0",
60
58
  "lodash": "4.17.21"
61
59
  },
62
60
  "scripts": {
63
- "build": "rm -rf lib && pnpm exec tsc --project tsconfig.build.json",
61
+ "build": "rm -rf lib && tsc --project tsconfig.build.json",
64
62
  "test": "jest",
65
63
  "test:ci": "pnpm run test --reporters=default --reporters=jest-junit",
66
64
  "test:coverage": "pnpm run test --coverage --coverageDirectory=${JEST_COVERAGE_RESULT_DIR:-$(pwd)}/coverage/view --reporters=default --reporters=jest-junit",
67
- "lint": "eslint ."
68
- }
65
+ "check": "../../scripts/check.sh",
66
+ "lint": "../../scripts/lint.sh"
67
+ },
68
+ "types": "./lib/index.d.ts"
69
69
  }
@@ -1,2 +0,0 @@
1
- declare const _exports: import("jest").Config;
2
- export = _exports;