Skip to content

Commit

Permalink
Merge branch 'master' into native/4.5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
nick4598 authored Feb 27, 2024
2 parents b93907a + 3cc2df3 commit 99578c4
Show file tree
Hide file tree
Showing 64 changed files with 1,104 additions and 652 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/ecschema-editing",
"comment": "Added navigation property merging",
"type": "none"
}
],
"packageName": "@itwin/ecschema-editing"
}
2 changes: 1 addition & 1 deletion common/config/rush/version-policies.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"policyName": "prerelease-monorepo-lockStep",
"definitionName": "lockStepVersion",
"version": "4.5.0-dev.18",
"version": "4.5.0-dev.19",
"nextBump": "prerelease"
}
]
8 changes: 4 additions & 4 deletions core/backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@itwin/core-backend",
"version": "4.5.0-dev.18",
"version": "4.5.0-dev.19",
"description": "iTwin.js backend components",
"main": "lib/cjs/core-backend.js",
"typings": "lib/cjs/core-backend",
Expand Down Expand Up @@ -44,9 +44,9 @@
"url": "http://www.bentley.com"
},
"peerDependencies": {
"@itwin/core-bentley": "workspace:^4.5.0-dev.18",
"@itwin/core-common": "workspace:^4.5.0-dev.18",
"@itwin/core-geometry": "workspace:^4.5.0-dev.18",
"@itwin/core-bentley": "workspace:^4.5.0-dev.19",
"@itwin/core-common": "workspace:^4.5.0-dev.19",
"@itwin/core-geometry": "workspace:^4.5.0-dev.19",
"@opentelemetry/api": "^1.0.4"
},
"peerDependenciesMeta": {
Expand Down
2 changes: 1 addition & 1 deletion core/bentley/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@itwin/core-bentley",
"version": "4.5.0-dev.18",
"version": "4.5.0-dev.19",
"description": "Bentley JavaScript core components",
"main": "lib/cjs/core-bentley.js",
"module": "lib/esm/core-bentley.js",
Expand Down
6 changes: 3 additions & 3 deletions core/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@itwin/core-common",
"version": "4.5.0-dev.18",
"version": "4.5.0-dev.19",
"description": "iTwin.js components common to frontend and backend",
"main": "lib/cjs/core-common.js",
"module": "lib/esm/core-common.js",
Expand Down Expand Up @@ -40,8 +40,8 @@
"js-base64": "^3.6.1"
},
"peerDependencies": {
"@itwin/core-bentley": "workspace:^4.5.0-dev.18",
"@itwin/core-geometry": "workspace:^4.5.0-dev.18"
"@itwin/core-bentley": "workspace:^4.5.0-dev.19",
"@itwin/core-geometry": "workspace:^4.5.0-dev.19"
},
"devDependencies": {
"@itwin/build-tools": "workspace:*",
Expand Down
8 changes: 4 additions & 4 deletions core/ecschema-editing/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@itwin/ecschema-editing",
"version": "4.5.0-dev.18",
"version": "4.5.0-dev.19",
"description": "ECSchema editing and validation API",
"license": "MIT",
"main": "lib/cjs/ecschema-editing.js",
Expand Down Expand Up @@ -62,9 +62,9 @@
"typescript": "~5.0.2"
},
"peerDependencies": {
"@itwin/core-bentley": "workspace:^4.5.0-dev.18",
"@itwin/core-quantity": "workspace:^4.5.0-dev.18",
"@itwin/ecschema-metadata": "workspace:^4.5.0-dev.18"
"@itwin/core-bentley": "workspace:^4.5.0-dev.19",
"@itwin/core-quantity": "workspace:^4.5.0-dev.19",
"@itwin/ecschema-metadata": "workspace:^4.5.0-dev.19"
},
"nyc": {
"extends": "./node_modules/@itwin/build-tools/.nycrc"
Expand Down
31 changes: 30 additions & 1 deletion core/ecschema-editing/src/Editing/ECClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import {
CustomAttribute,
CustomAttributeContainerProps,
DelayedPromiseWithProps,
ECClass, ECName, ECObjectsError, ECObjectsStatus, Enumeration, EnumerationPropertyProps, PrimitiveArrayPropertyProps,
PrimitivePropertyProps, PrimitiveType, SchemaItemKey, SchemaItemType, StructArrayPropertyProps,
PrimitivePropertyProps, PrimitiveType, PropertyCategory, SchemaItemKey, SchemaItemType, StructArrayPropertyProps,
StructClass, StructPropertyProps,
} from "@itwin/ecschema-metadata";
import { assert } from "@itwin/core-bentley";
Expand Down Expand Up @@ -386,6 +387,34 @@ export class ECClasses {
return {};
}

/**
* Sets the Category to the Property.
* @param classKey The SchemaItemKey of the class.
* @param propertyName The name of the property.
* @param categoryKey The SchemaItemKey of the PropertyCategory assigned to the property.
*/
public async setPropertyCategory(classKey: SchemaItemKey, propertyName: string, categoryKey: SchemaItemKey): Promise<PropertyEditResults> {
let mutableClass: MutableClass;
try {
mutableClass = await this.getClass(classKey);
} catch (e: any) {
return { errorMessage: e.message };
}

const property = await mutableClass.getProperty(propertyName) as MutableProperty;
if (property === undefined) {
return { errorMessage: `An ECProperty with the name ${propertyName} could not be found in the class ${classKey.fullName}.` };
}

const category = await mutableClass.schema.lookupItem<PropertyCategory>(categoryKey);
if (category === undefined) {
return { errorMessage: `Can't locate the Property Category ${categoryKey.fullName} in the schema ${mutableClass.schema.fullName}.` };
}

property.setCategory(new DelayedPromiseWithProps<SchemaItemKey, PropertyCategory>(categoryKey, async () => category));
return { itemKey: classKey, propertyName };
}

private async getClass(classKey: SchemaItemKey): Promise<MutableClass> {
const schema = await this._schemaEditor.getSchema(classKey.schemaKey);
if (schema === undefined)
Expand Down
23 changes: 21 additions & 2 deletions core/ecschema-editing/src/Editing/Entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import {
DelayedPromiseWithProps, ECClassModifier, ECObjectsError, ECObjectsStatus, EntityClass, EntityClassProps,
Mixin, RelationshipClass, SchemaItemKey, SchemaItemType, SchemaKey, StrengthDirection,
Mixin, NavigationPropertyProps, RelationshipClass, SchemaItemKey, SchemaItemType, SchemaKey, StrengthDirection,
} from "@itwin/ecschema-metadata";
import { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from "./Editor";
import { ECClasses } from "./ECClasses";
Expand Down Expand Up @@ -140,7 +140,7 @@ export class Entities extends ECClasses {
}

public async createNavigationProperty(entityKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<PropertyEditResults> {
const entity = (await this._schemaEditor.schemaContext.getSchemaItem<MutableEntityClass>(entityKey));
const entity = await this._schemaEditor.schemaContext.getSchemaItem<MutableEntityClass>(entityKey);

if (entity === undefined)
throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Entity Class ${entityKey.fullName} not found in schema context.`);
Expand All @@ -152,6 +152,25 @@ export class Entities extends ECClasses {
return { itemKey: entityKey, propertyName: name };
}

/**
* Creates a Navigation Property through a NavigationPropertyProps.
* @param classKey a SchemaItemKey of the Entity Class that will house the new property.
* @param navigationProps a json object that will be used to populate the new Navigation Property.
*/
public async createNavigationPropertyFromProps(classKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<PropertyEditResults> {
const entity = await this._schemaEditor.schemaContext.getSchemaItem<MutableEntityClass>(classKey);
if (entity === undefined)
return { itemKey: classKey, propertyName: navigationProps.name, errorMessage: `Entity Class ${classKey.fullName} not found in schema context.`};

if (entity.schemaItemType !== SchemaItemType.EntityClass)
return { itemKey: classKey, propertyName: navigationProps.name, errorMessage: `Expected ${classKey.fullName} to be of type EntityClass.` };

const navigationProperty = await entity.createNavigationProperty(navigationProps.name, navigationProps.relationshipName, navigationProps.direction);
await navigationProperty.fromJSON(navigationProps);

return { itemKey: classKey, propertyName: navigationProps.name };
}

/**
* Sets the base class of an Entity.
* @param entityKey The SchemaItemKey of the Entity.
Expand Down
21 changes: 20 additions & 1 deletion core/ecschema-editing/src/Editing/Mixins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import {
DelayedPromiseWithProps, ECObjectsError, ECObjectsStatus, EntityClass, Mixin, MixinProps, RelationshipClass,
DelayedPromiseWithProps, ECObjectsError, ECObjectsStatus, EntityClass, Mixin, MixinProps, NavigationPropertyProps, RelationshipClass,
SchemaItemKey, SchemaItemType, SchemaKey, StrengthDirection,
} from "@itwin/ecschema-metadata";
import { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from "./Editor";
Expand Down Expand Up @@ -109,6 +109,25 @@ export class Mixins extends ECClasses {
return { itemKey: mixinKey, propertyName: name };
}

/**
* Creates a Navigation Property through a NavigationPropertyProps.
* @param classKey a SchemaItemKey of the Mixin that will house the new property.
* @param navigationProps a json object that will be used to populate the new Navigation Property.
*/
public async createNavigationPropertyFromProps(classKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<PropertyEditResults> {
const mixin = await this._schemaEditor.schemaContext.getSchemaItem<MutableMixin>(classKey);
if (mixin === undefined)
return { itemKey: classKey, propertyName: navigationProps.name, errorMessage: `Mixin ${classKey.fullName} not found in schema context.`};

if (mixin.schemaItemType !== SchemaItemType.Mixin)
return { itemKey: classKey, propertyName: navigationProps.name, errorMessage: `Expected ${classKey.fullName} to be of type Mixin.`};

const navigationProperty = await mixin.createNavigationProperty(navigationProps.name, navigationProps.relationshipName, navigationProps.direction);
await navigationProperty.fromJSON(navigationProps);

return { itemKey: classKey, propertyName: navigationProps.name };
}

public async setMixinBaseClass(mixinKey: SchemaItemKey, baseClassKey?: SchemaItemKey): Promise<SchemaItemEditResults>{
const mixin = (await this._schemaEditor.schemaContext.getSchemaItem<MutableMixin>(mixinKey));

Expand Down
7 changes: 6 additions & 1 deletion core/ecschema-editing/src/Editing/RelationshipClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,13 @@ export class RelationshipClasses extends ECClasses {
return { itemKey: relationshipKey, propertyName: name };
}

/**
* Creates a Navigation Property through a NavigationPropertyProps.
* @param classKey a SchemaItemKey of the Relationship Class that will house the new property.
* @param navigationProps a json object that will be used to populate the new Navigation Property.
*/
public async createNavigationPropertyFromProps(relationshipKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<PropertyEditResults> {
const relationshipClass = (await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey));
const relationshipClass = await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey);

if (relationshipClass === undefined)
return { itemKey: relationshipKey, propertyName: navigationProps.name, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };
Expand Down
80 changes: 0 additions & 80 deletions core/ecschema-editing/src/Merging/AnyPropertyMerger.ts

This file was deleted.

Loading

0 comments on commit 99578c4

Please sign in to comment.