Skip to content

Commit

Permalink
Presentation: Add assertions for correct classmap 3.0 (iTwin#2359)
Browse files Browse the repository at this point in the history
* Add assertions for correct class map

* Update `SelectClassInfo.pathFromInputToSelectClass` type definition to match reality
  • Loading branch information
grigasp authored Sep 28, 2021
1 parent 0af28ed commit fbb670d
Show file tree
Hide file tree
Showing 15 changed files with 260 additions and 152 deletions.
24 changes: 21 additions & 3 deletions common/api/presentation-common.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1905,6 +1905,9 @@ export interface ParentCategoryIdentifier {
type: "DefaultParent";
}

// @public
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;

// @public
export type PartialHierarchyModification = NodeInsertionInfo | NodeDeletionInfo | NodeUpdateInfo;

Expand Down Expand Up @@ -2349,6 +2352,22 @@ export interface RelatedClassInfoJSON<TClassInfoJSON = ClassInfoJSON> {
targetClassInfo: TClassInfoJSON;
}

// @public
export type RelatedClassInfoWithOptionalRelationship = PartialBy<RelatedClassInfo, "relationshipInfo" | "isForwardRelationship" | "isPolymorphicRelationship">;

// @public (undocumented)
export namespace RelatedClassInfoWithOptionalRelationship {
export function fromCompressedJSON(json: RelatedClassInfoWithOptionalRelationshipJSON<string>, classesMap: {
[id: string]: CompressedClassInfoJSON;
}): RelatedClassInfoWithOptionalRelationship;
export function toCompressedJSON(classInfo: RelatedClassInfoWithOptionalRelationship, classesMap: {
[id: string]: CompressedClassInfoJSON;
}): RelatedClassInfoWithOptionalRelationshipJSON<string>;
}

// @public (undocumented)
export type RelatedClassInfoWithOptionalRelationshipJSON<TClassInfoJSON = ClassInfoJSON> = PartialBy<RelatedClassInfoJSON<TClassInfoJSON>, "relationshipInfo" | "isForwardRelationship" | "isPolymorphicRelationship">;

// @public
export type RelatedInstanceNodesSpecification = DEPRECATED_RelatedInstanceNodesSpecification | RelatedInstanceNodesSpecificationNew;

Expand Down Expand Up @@ -2641,7 +2660,7 @@ export interface SchemasSpecification {
export interface SelectClassInfo {
isSelectPolymorphic: boolean;
navigationPropertyClasses?: RelatedClassInfo[];
pathFromInputToSelectClass?: RelationshipPath;
pathFromInputToSelectClass?: RelatedClassInfoWithOptionalRelationship[];
relatedInstancePaths?: RelationshipPath[];
relatedPropertyPaths?: RelationshipPath[];
selectClassInfo: ClassInfo;
Expand All @@ -2652,7 +2671,6 @@ export namespace SelectClassInfo {
export function fromCompressedJSON(json: SelectClassInfoJSON<string>, classesMap: {
[id: string]: CompressedClassInfoJSON;
}): SelectClassInfo;
export function fromJSON(json: SelectClassInfoJSON): SelectClassInfo;
// @internal
export function listFromCompressedJSON(json: SelectClassInfoJSON<Id64String>[], classesMap: {
[id: string]: CompressedClassInfoJSON;
Expand All @@ -2669,7 +2687,7 @@ export interface SelectClassInfoJSON<TClassInfoJSON = ClassInfoJSON> {
// (undocumented)
navigationPropertyClasses?: RelatedClassInfoJSON<TClassInfoJSON>[];
// (undocumented)
pathFromInputToSelectClass?: RelationshipPathJSON<TClassInfoJSON>;
pathFromInputToSelectClass?: RelatedClassInfoWithOptionalRelationshipJSON<TClassInfoJSON>[];
// (undocumented)
relatedInstancePaths?: RelationshipPathJSON<TClassInfoJSON>[];
// (undocumented)
Expand Down
4 changes: 4 additions & 0 deletions common/api/summary/presentation-common.exports.csv
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ public;Paged
public;PagedResponse
public;PageOptions
public;ParentCategoryIdentifier
public;PartialBy
public;PartialHierarchyModification = NodeInsertionInfo | NodeDeletionInfo | NodeUpdateInfo
public;PartialHierarchyModification
public;PartialHierarchyModificationJSON = NodeInsertionInfoJSON | NodeDeletionInfoJSON | NodeUpdateInfoJSON
Expand Down Expand Up @@ -312,6 +313,9 @@ public;RegisteredRuleset
public;RelatedClassInfo
public;RelatedClassInfo
public;RelatedClassInfoJSON
public;RelatedClassInfoWithOptionalRelationship = PartialBy
public;RelatedClassInfoWithOptionalRelationship
public;RelatedClassInfoWithOptionalRelationshipJSON
public;RelatedInstanceNodesSpecification = DEPRECATED_RelatedInstanceNodesSpecification | RelatedInstanceNodesSpecificationNew
public;RelatedInstanceNodesSpecificationNew
public;RelatedInstanceSpecification = DEPRECATED_RelatedInstanceSpecification | RelatedInstanceSpecificationNew
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@bentley/presentation-backend",
"comment": "",
"type": "none"
}
],
"packageName": "@bentley/presentation-backend"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@bentley/presentation-common",
"comment": "",
"type": "none"
}
],
"packageName": "@bentley/presentation-common"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@bentley/presentation-common",
"comment": "Update `SelectClassInfo.pathFromInputToSelectClass` type definition to match reality - the relationship may not always be set.",
"type": "none"
}
],
"packageName": "@bentley/presentation-common"
}
85 changes: 43 additions & 42 deletions presentation/backend/src/test/PresentationManager.test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -964,11 +964,14 @@ Object {
},
],
"classesMap": Object {
"0": Object {},
"0x1": Object {
"label": "Source",
"name": "source:class",
},
"0x1054a000001245d": Object {
"label": "Rustic Metal Fish Automotive Cuban Peso Peso Convertible",
"name": "Barbados",
},
"0x2": Object {
"label": "Target",
"name": "target:class",
Expand All @@ -977,7 +980,14 @@ Object {
"label": "Relationship",
"name": "relationship:class",
},
"[object Object]": Object {},
"0xab690000009ba9": Object {
"label": "back-end",
"name": "auxiliary",
},
"0xea7d000000f2b6": Object {
"label": "Assurance turquoise navigating",
"name": "Berkshire",
},
},
"connectionId": "d61dcbd0-3355-426a-9ebf-3eadccd4b8be",
"contentFlags": 0,
Expand All @@ -999,25 +1009,21 @@ Object {
"properties": Array [
Object {
"property": Object {
"classInfo": Object {
"id": "0xb0b60000001f53",
"label": "withdrawal",
"name": "utilize",
},
"classInfo": "0x1",
"enumerationInfo": Object {
"choices": Array [
Object {
"label": "SQL markets",
"value": "655821da-f1ef-4589-ad49-bacbaea86483",
"label": "Games withdrawal",
"value": "27ad4616-5582-41da-b1ef-5896d49bacba",
},
Object {
"label": "tangible platforms navigating",
"value": "bc243b63-ea44-46b6-bcee-422bd1fbdfff",
"label": "payment morph Congo",
"value": "b4e62d6b-c243-4b63-aa44-6b6bcee422bd",
},
],
"isStrict": true,
"isStrict": false,
},
"name": "Granite",
"name": "Practical",
"type": "string",
},
},
Expand All @@ -1032,23 +1038,19 @@ Object {
"category": "test-category",
"editor": undefined,
"isReadonly": true,
"label": "Directives multi-byte Keys",
"label": "bus Strategist Facilitator",
"name": "Complex array of structs property field",
"priority": 4698,
"priority": 26470,
"properties": Array [
Object {
"property": Object {
"classInfo": Object {
"id": "0x675f0000014e92",
"label": "stable transmitter",
"name": "Kids",
},
"classInfo": "0x1",
"kindOfQuantity": Object {
"label": "web services",
"name": "Personal Loan Account",
"persistenceUnit": "Home Loan Account",
"label": "Accounts backing up",
"name": "Avon",
"persistenceUnit": "Senior",
},
"name": "Integration",
"name": "Tennessee",
"type": "double",
},
},
Expand All @@ -1058,16 +1060,16 @@ Object {
"memberType": Object {
"members": Array [
Object {
"label": "Fields open-source Tennessee",
"name": "efficient",
"label": "multi-byte",
"name": "CFA Franc BCEAO",
"type": Object {
"typeName": "string",
"valueFormat": "Primitive",
},
},
Object {
"label": "Accounts backing up",
"name": "Avon",
"label": "United States Minor Outlying Islands Fields",
"name": "Keys",
"type": Object {
"memberType": Object {
"typeName": "string",
Expand All @@ -1089,19 +1091,19 @@ Object {
"actualPrimaryClassIds": Array [],
"autoExpand": true,
"category": "test-category",
"contentClassInfo": "0",
"contentClassInfo": "0x1",
"editor": undefined,
"isReadonly": true,
"label": "Rue Assurance",
"isReadonly": false,
"label": "24/7 Home Loan Account stable",
"name": "Nested content field",
"nestedFields": Array [
Object {
"category": "test-category",
"editor": undefined,
"isReadonly": false,
"label": "reintermediate Licensed Soft Bike",
"isReadonly": true,
"label": "Avon Planner Ways",
"name": "Simple property field",
"priority": 17182,
"priority": 27093,
"renderer": undefined,
"type": Object {
"typeName": "string",
Expand All @@ -1114,26 +1116,26 @@ Object {
"isForwardRelationship": false,
"isPolymorphicRelationship": false,
"isPolymorphicTargetClass": false,
"relationshipInfo": "0",
"sourceClassInfo": "0",
"targetClassInfo": "0",
"relationshipInfo": "0x1054a000001245d",
"sourceClassInfo": "0xea7d000000f2b6",
"targetClassInfo": "0xab690000009ba9",
},
],
"priority": 60528,
"priority": 77648,
"relationshipMeaning": "RelatedInstance",
"renderer": undefined,
"type": Object {
"members": Array [
Object {
"label": "users Movies",
"name": "navigating",
"label": "Integration web services",
"name": "Integration",
"type": Object {
"typeName": "string",
"valueFormat": "Primitive",
},
},
],
"typeName": "turquoise",
"typeName": "transmitter",
"valueFormat": "Struct",
},
},
Expand Down Expand Up @@ -1221,7 +1223,6 @@ Array [
"pathFromInputToSelectClass": Array [
Object {
"isForwardRelationship": true,
"isPolymorphicRelationship": false,
"isPolymorphicTargetClass": false,
"relationshipInfo": Object {
"id": "0x456",
Expand Down
34 changes: 20 additions & 14 deletions presentation/backend/src/test/PresentationManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
FieldDescriptor, FieldDescriptorType, FieldJSON, FilterByInstancePathsHierarchyRequestOptions, FilterByTextHierarchyRequestOptions,
getLocalesDirectory, HierarchyCompareInfo, HierarchyCompareInfoJSON, HierarchyCompareOptions, HierarchyRequestOptions, InstanceKey,
IntRulesetVariable, ItemJSON, KeySet, KindOfQuantityInfo, LabelDefinition, NestedContentFieldJSON, NodeJSON, NodeKey, Paged, PageOptions,
PresentationError, PrimitiveTypeDescription, PropertiesFieldJSON, PropertyInfoJSON, PropertyJSON, RegisteredRuleset, Ruleset,
PresentationError, PrimitiveTypeDescription, PropertiesFieldJSON, PropertyInfoJSON, PropertyJSON, RegisteredRuleset, RelatedClassInfo, Ruleset,
SelectClassInfo, SelectClassInfoJSON, SelectionInfo, SelectionScope, StandardNodeTypes, StructTypeDescription, VariableValueTypes,
} from "@bentley/presentation-common";
import {
Expand All @@ -27,7 +27,7 @@ import { createTestECClassInfo, createTestRelatedClassInfo, createTestRelationsh
import {
createRandomECClassInfoJSON, createRandomECInstanceKey, createRandomECInstanceKeyJSON, createRandomECInstancesNodeJSON,
createRandomECInstancesNodeKey, createRandomECInstancesNodeKeyJSON, createRandomId, createRandomLabelDefinitionJSON,
createRandomNodePathElementJSON, createRandomRelationshipPathJSON, createRandomRuleset,
createRandomNodePathElementJSON, createRandomRelationshipPath, createRandomRuleset,
} from "@bentley/presentation-common/lib/test/_helpers/random";
import { PRESENTATION_BACKEND_ASSETS_ROOT, PRESENTATION_COMMON_ASSETS_ROOT } from "../presentation-backend/Constants";
import { NativePlatformDefinition, NativePlatformRequestTypes, NativePresentationUnitSystem } from "../presentation-backend/NativePlatform";
Expand Down Expand Up @@ -1222,7 +1222,13 @@ describe("PresentationManager", () => {
};

// what the addon returns
const classesMap = {};
const testClassInfo = createTestECClassInfo();
const classesMap = {
[testClassInfo.id]: {
label: testClassInfo.label,
name: testClassInfo.name,
},
};
const addonResponse: DescriptorJSON = {
connectionId: faker.random.uuid(),
inputKeysHash: faker.random.uuid(),
Expand Down Expand Up @@ -1256,7 +1262,7 @@ describe("PresentationManager", () => {
},
properties: [{
property: {
classInfo: createRandomECClassInfoJSON(),
classInfo: testClassInfo.id,
name: faker.random.word(),
type: "string",
enumerationInfo: {
Expand All @@ -1269,10 +1275,10 @@ describe("PresentationManager", () => {
}],
isStrict: faker.random.boolean(),
},
} as PropertyInfoJSON,
} as PropertyInfoJSON<Id64String>,
relatedClassPath: [],
} as PropertyJSON],
} as PropertiesFieldJSON, {
} as PropertyJSON<Id64String>],
} as PropertiesFieldJSON<Id64String>, {
name: "Complex array of structs property field",
category: "test-category",
label: faker.random.words(),
Expand Down Expand Up @@ -1307,18 +1313,18 @@ describe("PresentationManager", () => {
priority: faker.random.number(),
properties: [{
property: {
classInfo: createRandomECClassInfoJSON(),
classInfo: testClassInfo.id,
name: faker.random.word(),
type: "double",
kindOfQuantity: {
name: faker.random.word(),
label: faker.random.words(),
persistenceUnit: faker.random.word(),
} as KindOfQuantityInfo,
} as PropertyInfoJSON,
} as PropertyInfoJSON<Id64String>,
relatedClassPath: [],
} as PropertyJSON],
} as PropertiesFieldJSON, {
} as PropertyJSON<Id64String>],
} as PropertiesFieldJSON<Id64String>, {
name: "Nested content field",
category: "test-category",
label: faker.random.words(),
Expand All @@ -1334,8 +1340,8 @@ describe("PresentationManager", () => {
},
}],
} as StructTypeDescription,
contentClassInfo: createRandomECClassInfoJSON(),
pathToPrimaryClass: createRandomRelationshipPathJSON(1),
contentClassInfo: testClassInfo.id,
pathToPrimaryClass: createRandomRelationshipPath(1).map((step) => RelatedClassInfo.toCompressedJSON(step, classesMap)),
nestedFields: [{
name: "Simple property field",
category: "test-category",
Expand All @@ -1350,7 +1356,7 @@ describe("PresentationManager", () => {
isReadonly: faker.random.boolean(),
priority: faker.random.number(),
autoExpand: faker.random.boolean(),
} as NestedContentFieldJSON],
} as NestedContentFieldJSON<Id64String>],
contentFlags: 0,
};
setup(addonResponse);
Expand Down
Loading

0 comments on commit fbb670d

Please sign in to comment.