@itwin/ecschema-editing 4.6.0-dev.18 → 4.6.0-dev.21

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 (40) hide show
  1. package/lib/cjs/Differencing/SchemaDifference.d.ts +2 -2
  2. package/lib/cjs/Differencing/SchemaDifference.d.ts.map +1 -1
  3. package/lib/cjs/Differencing/SchemaDifference.js +1 -1
  4. package/lib/cjs/Differencing/SchemaDifference.js.map +1 -1
  5. package/lib/cjs/Editing/CustomAttributes.d.ts +1 -1
  6. package/lib/cjs/Editing/CustomAttributes.d.ts.map +1 -1
  7. package/lib/cjs/Editing/CustomAttributes.js +2 -2
  8. package/lib/cjs/Editing/CustomAttributes.js.map +1 -1
  9. package/lib/cjs/Editing/ECClasses.d.ts +5 -7
  10. package/lib/cjs/Editing/ECClasses.d.ts.map +1 -1
  11. package/lib/cjs/Editing/ECClasses.js +7 -10
  12. package/lib/cjs/Editing/ECClasses.js.map +1 -1
  13. package/lib/cjs/Editing/Entities.d.ts +6 -1
  14. package/lib/cjs/Editing/Entities.d.ts.map +1 -1
  15. package/lib/cjs/Editing/Entities.js +7 -2
  16. package/lib/cjs/Editing/Entities.js.map +1 -1
  17. package/lib/cjs/Editing/Mixins.d.ts +6 -1
  18. package/lib/cjs/Editing/Mixins.d.ts.map +1 -1
  19. package/lib/cjs/Editing/Mixins.js +7 -2
  20. package/lib/cjs/Editing/Mixins.js.map +1 -1
  21. package/lib/cjs/Editing/Properties.d.ts +9 -7
  22. package/lib/cjs/Editing/Properties.d.ts.map +1 -1
  23. package/lib/cjs/Editing/Properties.js +17 -13
  24. package/lib/cjs/Editing/Properties.js.map +1 -1
  25. package/lib/cjs/Editing/RelationshipClasses.d.ts +6 -1
  26. package/lib/cjs/Editing/RelationshipClasses.d.ts.map +1 -1
  27. package/lib/cjs/Editing/RelationshipClasses.js +7 -2
  28. package/lib/cjs/Editing/RelationshipClasses.js.map +1 -1
  29. package/lib/cjs/Editing/Structs.d.ts +1 -1
  30. package/lib/cjs/Editing/Structs.d.ts.map +1 -1
  31. package/lib/cjs/Editing/Structs.js +2 -2
  32. package/lib/cjs/Editing/Structs.js.map +1 -1
  33. package/lib/cjs/Merging/PropertyMerger.d.ts.map +1 -1
  34. package/lib/cjs/Merging/PropertyMerger.js +48 -23
  35. package/lib/cjs/Merging/PropertyMerger.js.map +1 -1
  36. package/lib/cjs/ecschema-editing.d.ts +2 -1
  37. package/lib/cjs/ecschema-editing.d.ts.map +1 -1
  38. package/lib/cjs/ecschema-editing.js +3 -3
  39. package/lib/cjs/ecschema-editing.js.map +1 -1
  40. package/package.json +9 -9
@@ -1 +1 @@
1
- {"version":3,"file":"RelationshipClasses.js","sourceRoot":"","sources":["../../../src/Editing/RelationshipClasses.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAIkC;AAElC,2CAAwC;AAExC,+CAA+C;AAG/C;;;GAGG;AACH,MAAa,mBAAoB,SAAQ,qBAAS;IAChD,YAAmB,aAAkC;QACnD,KAAK,CAAC,aAAa,CAAC,CAAC;IACvB,CAAC;IAED;;;;;;;;OAQG;IACI,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,IAAY,EAAE,QAAyB,EAAE,QAAsB,EAAE,SAA4B,EAAE,YAA4B;QACnK,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC7D,IAAI,MAAM,KAAK,SAAS,EAAE;YACxB,OAAO,EAAE,YAAY,EAAE,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC;SACxF;QAED,MAAM,QAAQ,GAAG,CAAC,MAAM,MAAM,CAAC,uBAAuB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAA6B,CAAC;QACpG,IAAI,YAAY,KAAK,SAAS,EAAE;YAC9B,MAAM,eAAe,GAAG,CAAC,YAAY,CAAC,SAAS,CAAC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kBAAkB,CAAC,eAAe,CAAC,CAAC;QAEtD,MAAM,WAAW,GAAG,KAAK,CAAC,+BAA+B,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;QACvF,MAAM,MAAM,GAA0B,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC;QAC3D,IAAI,KAAK,EAAE,MAAM,UAAU,IAAI,WAAW,EAAE;YAC1C,MAAM,CAAC,YAAY,IAAI,GAAG,UAAU,CAAC,IAAI,KAAK,UAAU,CAAC,WAAW,MAAM,CAAC;SAC5E;QAED,IAAI,MAAM,CAAC,YAAY,EAAE;YACvB,IAAI,CAAC,qBAAqB,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;YACxD,OAAO,MAAM,CAAC;SACf;QAED,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,iBAAiB,CAAC,GAAG,EAAE,CAAC;IACvD,CAAC;IAEO,KAAK,CAAC,QAAQ,CAAC,wBAAoE;QACzF,IAAI,WAAmI,CAAC;QAExI,IAAI,wBAAwB,YAAY,qCAAiB,EAAE;YACzD,WAAW,GAAG,KAAK,CAAC,oBAAoB,CAAC,wBAAwB,CAAC,CAAC;SACpE;aAAM;YACL,WAAW,GAAG,KAAK,CAAC,8BAA8B,CAAC,wBAAwB,CAAC,CAAC;SAC9E;QAED,MAAM,aAAa,GAAG,EAAE,CAAC;QACzB,IAAI,KAAK,EAAE,MAAM,UAAU,IAAI,WAAW,EAAE;YAC1C,aAAa,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,IAAI,KAAK,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;SACrE;QAED,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;YAC5B,OAAO,EAAE,YAAY,EAAE,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;SACrD;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AArQD,kDAqQC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Editing\r\n */\r\n\r\nimport {\r\n CustomAttribute, DelayedPromiseWithProps, ECClassModifier, EntityClass, LazyLoadedRelationshipConstraintClass, Mixin, NavigationPropertyProps,\r\n RelationshipClass, RelationshipClassProps, RelationshipConstraint, RelationshipEnd, RelationshipMultiplicity, SchemaItemKey, SchemaItemType,\r\n SchemaKey, StrengthDirection, StrengthType,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\r\nimport { ECClasses } from \"./ECClasses\";\r\nimport { MutableRelationshipClass, MutableRelationshipConstraint } from \"./Mutable/MutableRelationshipClass\";\r\nimport * as Rules from \"../Validation/ECRules\";\r\nimport { RelationshipConstraintDiagnostic, SchemaItemDiagnostic } from \"../Validation/Diagnostic\";\r\n\r\n/**\r\n * @alpha\r\n * A class extending ECClasses allowing you to create schema items of type RelationshipClass.\r\n */\r\nexport class RelationshipClasses extends ECClasses {\r\n public constructor(_schemaEditor: SchemaContextEditor) {\r\n super(_schemaEditor);\r\n }\r\n\r\n /**\r\n * Creates a RelationshipClass.\r\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\r\n * @param name The name of the new class.\r\n * @param modifier The ECClassModifier of the new class.\r\n * @param strength The relationship StrengthType of the class.\r\n * @param StrengthDirection The relationship StrengthDirection of the class.\r\n * @param baseClassKey An optional SchemaItemKey that specifies the base relationship class.\r\n */\r\n public async create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, strength: StrengthType, direction: StrengthDirection, baseClassKey?: SchemaItemKey): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined) {\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n }\r\n\r\n const newClass = (await schema.createRelationshipClass(name, modifier)) as MutableRelationshipClass;\r\n if (baseClassKey !== undefined) {\r\n const baseClassSchema = !baseClassKey.schemaKey.matches(schema.schemaKey) ? await this._schemaEditor.getSchema(baseClassKey.schemaKey) : schema;\r\n if (baseClassSchema === undefined) {\r\n return { errorMessage: `Schema Key ${baseClassKey.schemaKey.toString(true)} not found in context` };\r\n }\r\n\r\n const baseClassItem = await baseClassSchema.lookupItem<RelationshipClass>(baseClassKey);\r\n if (baseClassItem === undefined)\r\n return { errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };\r\n\r\n if (baseClassItem.schemaItemType !== SchemaItemType.RelationshipClass)\r\n return { errorMessage: `${baseClassItem.fullName} is not of type Relationship Class.` };\r\n\r\n newClass.baseClass = new DelayedPromiseWithProps<SchemaItemKey, RelationshipClass>(baseClassKey, async () => baseClassItem);\r\n }\r\n\r\n newClass.setStrength(strength);\r\n newClass.setStrengthDirection(direction);\r\n\r\n return { itemKey: newClass.key };\r\n }\r\n\r\n /**\r\n * Sets the source RelationshipConstraint on the relationship.\r\n * @param relationshipKey The SchemaItemKey for the relationship.\r\n * @param source The RelationshipConstraint to add.\r\n * @returns A promise of type SchemaItemEditResults.\r\n */\r\n public async setSourceConstraint(relationshipKey: SchemaItemKey, source: RelationshipConstraint): Promise<SchemaItemEditResults> {\r\n const relationship = (await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey));\r\n\r\n if (relationship === undefined)\r\n return { itemKey: relationshipKey, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\r\n\r\n relationship.setSourceConstraint(source);\r\n return { itemKey: relationshipKey };\r\n }\r\n\r\n /**\r\n * Sets the target RelationshipConstraint on the relationship.\r\n * @param relationshipKey The SchemaItemKey for the relationship.\r\n * @param target The RelationshipConstraint to add.\r\n * @returns A promise of type SchemaItemEditResults.\r\n */\r\n public async setTargetConstraint(relationshipKey: SchemaItemKey, target: RelationshipConstraint): Promise<SchemaItemEditResults> {\r\n const relationship = await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey);\r\n\r\n if (relationship === undefined)\r\n return { itemKey: relationshipKey, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\r\n\r\n relationship.setTargetConstraint(target);\r\n return { itemKey: relationshipKey };\r\n }\r\n\r\n /**\r\n * Creates a RelationshipClass through a RelationshipClassProps.\r\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\r\n * @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.\r\n */\r\n public async createFromProps(schemaKey: SchemaKey, relationshipProps: RelationshipClassProps): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n if (relationshipProps.name === undefined)\r\n return { errorMessage: `No name was supplied within props.` };\r\n\r\n const newClass = (await schema.createRelationshipClass(relationshipProps.name)) as MutableRelationshipClass;\r\n await newClass.fromJSON(relationshipProps);\r\n await newClass.source.fromJSON(relationshipProps.source);\r\n await newClass.target.fromJSON(relationshipProps.target);\r\n\r\n return { itemKey: newClass.key };\r\n }\r\n\r\n /**\r\n * Sets the base class of a RelationshipClass.\r\n * @param relationshipKey The SchemaItemKey of the RelationshipClass.\r\n * @param baseClassKey The SchemaItemKey of the base class. Specifying 'undefined' removes the base class.\r\n */\r\n public override async setBaseClass(itemKey: SchemaItemKey, baseClassKey?: SchemaItemKey): Promise<SchemaItemEditResults> {\r\n const relClass = await this._schemaEditor.schemaContext.getSchemaItem<RelationshipClass>(itemKey);\r\n const baseClass = relClass?.baseClass;\r\n\r\n const setResult = await super.setBaseClass(itemKey, baseClassKey);\r\n if (setResult.errorMessage === undefined) {\r\n const result = await this.validate(relClass!);\r\n if (result.errorMessage !== undefined) {\r\n relClass!.baseClass = baseClass;\r\n return { itemKey, errorMessage: result.errorMessage };\r\n }\r\n }\r\n return setResult;\r\n }\r\n\r\n public async createNavigationProperty(relationshipKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<PropertyEditResults> {\r\n const relationshipClass = (await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey));\r\n\r\n if (relationshipClass === undefined)\r\n return { itemKey: relationshipKey, propertyName: name, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\r\n\r\n if (relationshipClass.schemaItemType !== SchemaItemType.RelationshipClass)\r\n return { itemKey: relationshipKey, propertyName: name, errorMessage: `Expected ${relationshipKey.fullName} to be of type Relationship Class.` };\r\n\r\n await relationshipClass.createNavigationProperty(name, relationship, direction);\r\n return { itemKey: relationshipKey, propertyName: name };\r\n }\r\n\r\n /**\r\n * Creates a Navigation Property through a NavigationPropertyProps.\r\n * @param classKey a SchemaItemKey of the Relationship Class that will house the new property.\r\n * @param navigationProps a json object that will be used to populate the new Navigation Property.\r\n */\r\n public async createNavigationPropertyFromProps(relationshipKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<PropertyEditResults> {\r\n const relationshipClass = await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey);\r\n\r\n if (relationshipClass === undefined)\r\n return { itemKey: relationshipKey, propertyName: navigationProps.name, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\r\n\r\n if (relationshipClass.schemaItemType !== SchemaItemType.RelationshipClass)\r\n return { itemKey: relationshipKey, propertyName: navigationProps.name, errorMessage: `Expected ${relationshipKey.fullName} to be of type Relationship Class.` };\r\n\r\n const property = await relationshipClass.createNavigationProperty(navigationProps.name, navigationProps.relationshipName, navigationProps.direction);\r\n await property.fromJSON(navigationProps);\r\n return { itemKey: relationshipKey, propertyName: navigationProps.name };\r\n }\r\n\r\n public async setConstraintMultiplicity(constraint: RelationshipConstraint, multiplicity: RelationshipMultiplicity): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.multiplicity = multiplicity;\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async setConstraintPolymorphic(constraint: RelationshipConstraint, polymorphic: boolean): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.polymorphic = polymorphic;\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async setConstraintRelationshipEnd(constraint: RelationshipConstraint, relationshipEnd: RelationshipEnd): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.relationshipEnd = relationshipEnd;\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async setAbstractConstraint(constraint: RelationshipConstraint, abstractConstraint?: EntityClass | Mixin | RelationshipClass): Promise<SchemaItemEditResults> {\r\n const existing: LazyLoadedRelationshipConstraintClass | undefined = constraint.abstractConstraint;\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n\r\n if (undefined === abstractConstraint) {\r\n mutableConstraint.abstractConstraint = undefined;\r\n } else {\r\n mutableConstraint.abstractConstraint = new DelayedPromiseWithProps(abstractConstraint.key, async () => abstractConstraint);\r\n }\r\n\r\n let result = await this.validate(constraint.relationshipClass);\r\n if (result.errorMessage) {\r\n mutableConstraint.abstractConstraint = existing;\r\n return result;\r\n }\r\n\r\n result = await this.validate(constraint);\r\n if (result.errorMessage) {\r\n mutableConstraint.abstractConstraint = existing;\r\n return result;\r\n }\r\n\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async addConstraintClass(constraint: RelationshipConstraint, ecClass: EntityClass | Mixin | RelationshipClass): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.addClass(ecClass);\r\n\r\n let result = await this.validate(constraint.relationshipClass);\r\n if (result.errorMessage) {\r\n mutableConstraint.removeClass(ecClass);\r\n return result;\r\n }\r\n\r\n result = await this.validate(constraint);\r\n if (result.errorMessage) {\r\n mutableConstraint.removeClass(ecClass);\r\n return result;\r\n }\r\n\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async removeConstraintClass(constraint: RelationshipConstraint, ecClass: EntityClass | Mixin | RelationshipClass): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.removeClass(ecClass);\r\n\r\n const result = await this.validate(constraint);\r\n if (result.errorMessage) {\r\n mutableConstraint.addClass(ecClass);\r\n return result;\r\n }\r\n\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async addCustomAttributeToConstraint(constraint: RelationshipConstraint, customAttribute: CustomAttribute): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.addCustomAttribute(customAttribute);\r\n\r\n const diagnostics = Rules.validateCustomAttributeInstance(constraint, customAttribute);\r\n const result: SchemaItemEditResults = { errorMessage: \"\" };\r\n for await (const diagnostic of diagnostics) {\r\n result.errorMessage += `${diagnostic.code}: ${diagnostic.messageText}\\r\\n`;\r\n }\r\n\r\n if (result.errorMessage) {\r\n this.removeCustomAttribute(constraint, customAttribute);\r\n return result;\r\n }\r\n\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n private async validate(relationshipOrConstraint: RelationshipClass | RelationshipConstraint): Promise<SchemaItemEditResults> {\r\n let diagnostics: AsyncIterable<SchemaItemDiagnostic<RelationshipClass, any[]>> | AsyncIterable<RelationshipConstraintDiagnostic<any[]>>;\r\n\r\n if (relationshipOrConstraint instanceof RelationshipClass) {\r\n diagnostics = Rules.validateRelationship(relationshipOrConstraint);\r\n } else {\r\n diagnostics = Rules.validateRelationshipConstraint(relationshipOrConstraint);\r\n }\r\n\r\n const errorMessages = [];\r\n for await (const diagnostic of diagnostics) {\r\n errorMessages.push(`${diagnostic.code}: ${diagnostic.messageText}`);\r\n }\r\n\r\n if (errorMessages.length > 0) {\r\n return { errorMessage: errorMessages.join(\"\\r\\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AAW,EAAE;YAC1C,MAAM,CAAC,YAAY,IAAI,GAAG,UAAU,CAAC,IAAI,KAAK,UAAU,CAAC,WAAW,MAAM,CAAC;SAC5E;QAED,IAAI,MAAM,CAAC,YAAY,EAAE;YACvB,IAAI,CAAC,qBAAqB,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;YACxD,OAAO,MAAM,CAAC;SACf;QAED,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,iBAAiB,CAAC,GAAG,EAAE,CAAC;IACvD,CAAC;IAEO,KAAK,CAAC,QAAQ,CAAC,wBAAoE;QACzF,IAAI,WAAmI,CAAC;QAExI,IAAI,wBAAwB,YAAY,qCAAiB,EAAE;YACzD,WAAW,GAAG,KAAK,CAAC,oBAAoB,CAAC,wBAAwB,CAAC,CAAC;SACpE;aAAM;YACL,WAAW,GAAG,KAAK,CAAC,8BAA8B,CAAC,wBAAwB,CAAC,CAAC;SAC9E;QAED,MAAM,aAAa,GAAG,EAAE,CAAC;QACzB,IAAI,KAAK,EAAE,MAAM,UAAU,IAAI,WAAW,EAAE;YAC1C,aAAa,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,IAAI,KAAK,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;SACrE;QAED,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;YAC5B,OAAO,EAAE,YAAY,EAAE,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;SACrD;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AA1QD,kDA0QC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Editing\r\n */\r\n\r\nimport {\r\n CustomAttribute, DelayedPromiseWithProps, ECClassModifier, EntityClass, LazyLoadedRelationshipConstraintClass, Mixin, NavigationPropertyProps,\r\n RelationshipClass, RelationshipClassProps, RelationshipConstraint, RelationshipEnd, RelationshipMultiplicity, SchemaItemKey, SchemaItemType,\r\n SchemaKey, StrengthDirection, StrengthType,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\r\nimport { ECClasses } from \"./ECClasses\";\r\nimport { MutableRelationshipClass, MutableRelationshipConstraint } from \"./Mutable/MutableRelationshipClass\";\r\nimport * as Rules from \"../Validation/ECRules\";\r\nimport { RelationshipConstraintDiagnostic, SchemaItemDiagnostic } from \"../Validation/Diagnostic\";\r\nimport { NavigationProperties } from \"./Properties\";\r\n\r\n/**\r\n * @alpha\r\n * A class extending ECClasses allowing you to create schema items of type RelationshipClass.\r\n */\r\nexport class RelationshipClasses extends ECClasses {\r\n public constructor(schemaEditor: SchemaContextEditor) {\r\n super(SchemaItemType.RelationshipClass, schemaEditor);\r\n }\r\n\r\n /**\r\n * Allows access for editing of NavigationProperty attributes.\r\n */\r\n public readonly navigationProperties = new NavigationProperties(this.schemaItemType, this._schemaEditor);\r\n\r\n /**\r\n * Creates a RelationshipClass.\r\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\r\n * @param name The name of the new class.\r\n * @param modifier The ECClassModifier of the new class.\r\n * @param strength The relationship StrengthType of the class.\r\n * @param StrengthDirection The relationship StrengthDirection of the class.\r\n * @param baseClassKey An optional SchemaItemKey that specifies the base relationship class.\r\n */\r\n public async create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, strength: StrengthType, direction: StrengthDirection, baseClassKey?: SchemaItemKey): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined) {\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n }\r\n\r\n const newClass = (await schema.createRelationshipClass(name, modifier)) as MutableRelationshipClass;\r\n if (baseClassKey !== undefined) {\r\n const baseClassSchema = !baseClassKey.schemaKey.matches(schema.schemaKey) ? await this._schemaEditor.getSchema(baseClassKey.schemaKey) : schema;\r\n if (baseClassSchema === undefined) {\r\n return { errorMessage: `Schema Key ${baseClassKey.schemaKey.toString(true)} not found in context` };\r\n }\r\n\r\n const baseClassItem = await baseClassSchema.lookupItem<RelationshipClass>(baseClassKey);\r\n if (baseClassItem === undefined)\r\n return { errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };\r\n\r\n if (baseClassItem.schemaItemType !== SchemaItemType.RelationshipClass)\r\n return { errorMessage: `${baseClassItem.fullName} is not of type Relationship Class.` };\r\n\r\n newClass.baseClass = new DelayedPromiseWithProps<SchemaItemKey, RelationshipClass>(baseClassKey, async () => baseClassItem);\r\n }\r\n\r\n newClass.setStrength(strength);\r\n newClass.setStrengthDirection(direction);\r\n\r\n return { itemKey: newClass.key };\r\n }\r\n\r\n /**\r\n * Sets the source RelationshipConstraint on the relationship.\r\n * @param relationshipKey The SchemaItemKey for the relationship.\r\n * @param source The RelationshipConstraint to add.\r\n * @returns A promise of type SchemaItemEditResults.\r\n */\r\n public async setSourceConstraint(relationshipKey: SchemaItemKey, source: RelationshipConstraint): Promise<SchemaItemEditResults> {\r\n const relationship = (await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey));\r\n\r\n if (relationship === undefined)\r\n return { itemKey: relationshipKey, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\r\n\r\n relationship.setSourceConstraint(source);\r\n return { itemKey: relationshipKey };\r\n }\r\n\r\n /**\r\n * Sets the target RelationshipConstraint on the relationship.\r\n * @param relationshipKey The SchemaItemKey for the relationship.\r\n * @param target The RelationshipConstraint to add.\r\n * @returns A promise of type SchemaItemEditResults.\r\n */\r\n public async setTargetConstraint(relationshipKey: SchemaItemKey, target: RelationshipConstraint): Promise<SchemaItemEditResults> {\r\n const relationship = await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey);\r\n\r\n if (relationship === undefined)\r\n return { itemKey: relationshipKey, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\r\n\r\n relationship.setTargetConstraint(target);\r\n return { itemKey: relationshipKey };\r\n }\r\n\r\n /**\r\n * Creates a RelationshipClass through a RelationshipClassProps.\r\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\r\n * @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.\r\n */\r\n public async createFromProps(schemaKey: SchemaKey, relationshipProps: RelationshipClassProps): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n if (relationshipProps.name === undefined)\r\n return { errorMessage: `No name was supplied within props.` };\r\n\r\n const newClass = (await schema.createRelationshipClass(relationshipProps.name)) as MutableRelationshipClass;\r\n await newClass.fromJSON(relationshipProps);\r\n await newClass.source.fromJSON(relationshipProps.source);\r\n await newClass.target.fromJSON(relationshipProps.target);\r\n\r\n return { itemKey: newClass.key };\r\n }\r\n\r\n /**\r\n * Sets the base class of a RelationshipClass.\r\n * @param relationshipKey The SchemaItemKey of the RelationshipClass.\r\n * @param baseClassKey The SchemaItemKey of the base class. Specifying 'undefined' removes the base class.\r\n */\r\n public override async setBaseClass(itemKey: SchemaItemKey, baseClassKey?: SchemaItemKey): Promise<SchemaItemEditResults> {\r\n const relClass = await this._schemaEditor.schemaContext.getSchemaItem<RelationshipClass>(itemKey);\r\n const baseClass = relClass?.baseClass;\r\n\r\n const setResult = await super.setBaseClass(itemKey, baseClassKey);\r\n if (setResult.errorMessage === undefined) {\r\n const result = await this.validate(relClass!);\r\n if (result.errorMessage !== undefined) {\r\n relClass!.baseClass = baseClass;\r\n return { itemKey, errorMessage: result.errorMessage };\r\n }\r\n }\r\n return setResult;\r\n }\r\n\r\n public async createNavigationProperty(relationshipKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<PropertyEditResults> {\r\n const relationshipClass = (await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey));\r\n\r\n if (relationshipClass === undefined)\r\n return { itemKey: relationshipKey, propertyName: name, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\r\n\r\n if (relationshipClass.schemaItemType !== SchemaItemType.RelationshipClass)\r\n return { itemKey: relationshipKey, propertyName: name, errorMessage: `Expected ${relationshipKey.fullName} to be of type Relationship Class.` };\r\n\r\n await relationshipClass.createNavigationProperty(name, relationship, direction);\r\n return { itemKey: relationshipKey, propertyName: name };\r\n }\r\n\r\n /**\r\n * Creates a Navigation Property through a NavigationPropertyProps.\r\n * @param classKey a SchemaItemKey of the Relationship Class that will house the new property.\r\n * @param navigationProps a json object that will be used to populate the new Navigation Property.\r\n */\r\n public async createNavigationPropertyFromProps(relationshipKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<PropertyEditResults> {\r\n const relationshipClass = await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey);\r\n\r\n if (relationshipClass === undefined)\r\n return { itemKey: relationshipKey, propertyName: navigationProps.name, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\r\n\r\n if (relationshipClass.schemaItemType !== SchemaItemType.RelationshipClass)\r\n return { itemKey: relationshipKey, propertyName: navigationProps.name, errorMessage: `Expected ${relationshipKey.fullName} to be of type Relationship Class.` };\r\n\r\n const property = await relationshipClass.createNavigationProperty(navigationProps.name, navigationProps.relationshipName, navigationProps.direction);\r\n await property.fromJSON(navigationProps);\r\n return { itemKey: relationshipKey, propertyName: navigationProps.name };\r\n }\r\n\r\n public async setConstraintMultiplicity(constraint: RelationshipConstraint, multiplicity: RelationshipMultiplicity): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.multiplicity = multiplicity;\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async setConstraintPolymorphic(constraint: RelationshipConstraint, polymorphic: boolean): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.polymorphic = polymorphic;\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async setConstraintRelationshipEnd(constraint: RelationshipConstraint, relationshipEnd: RelationshipEnd): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.relationshipEnd = relationshipEnd;\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async setAbstractConstraint(constraint: RelationshipConstraint, abstractConstraint?: EntityClass | Mixin | RelationshipClass): Promise<SchemaItemEditResults> {\r\n const existing: LazyLoadedRelationshipConstraintClass | undefined = constraint.abstractConstraint;\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n\r\n if (undefined === abstractConstraint) {\r\n mutableConstraint.abstractConstraint = undefined;\r\n } else {\r\n mutableConstraint.abstractConstraint = new DelayedPromiseWithProps(abstractConstraint.key, async () => abstractConstraint);\r\n }\r\n\r\n let result = await this.validate(constraint.relationshipClass);\r\n if (result.errorMessage) {\r\n mutableConstraint.abstractConstraint = existing;\r\n return result;\r\n }\r\n\r\n result = await this.validate(constraint);\r\n if (result.errorMessage) {\r\n mutableConstraint.abstractConstraint = existing;\r\n return result;\r\n }\r\n\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async addConstraintClass(constraint: RelationshipConstraint, ecClass: EntityClass | Mixin | RelationshipClass): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.addClass(ecClass);\r\n\r\n let result = await this.validate(constraint.relationshipClass);\r\n if (result.errorMessage) {\r\n mutableConstraint.removeClass(ecClass);\r\n return result;\r\n }\r\n\r\n result = await this.validate(constraint);\r\n if (result.errorMessage) {\r\n mutableConstraint.removeClass(ecClass);\r\n return result;\r\n }\r\n\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async removeConstraintClass(constraint: RelationshipConstraint, ecClass: EntityClass | Mixin | RelationshipClass): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.removeClass(ecClass);\r\n\r\n const result = await this.validate(constraint);\r\n if (result.errorMessage) {\r\n mutableConstraint.addClass(ecClass);\r\n return result;\r\n }\r\n\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async addCustomAttributeToConstraint(constraint: RelationshipConstraint, customAttribute: CustomAttribute): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.addCustomAttribute(customAttribute);\r\n\r\n const diagnostics = Rules.validateCustomAttributeInstance(constraint, customAttribute);\r\n const result: SchemaItemEditResults = { errorMessage: \"\" };\r\n for await (const diagnostic of diagnostics) {\r\n result.errorMessage += `${diagnostic.code}: ${diagnostic.messageText}\\r\\n`;\r\n }\r\n\r\n if (result.errorMessage) {\r\n this.removeCustomAttribute(constraint, customAttribute);\r\n return result;\r\n }\r\n\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n private async validate(relationshipOrConstraint: RelationshipClass | RelationshipConstraint): Promise<SchemaItemEditResults> {\r\n let diagnostics: AsyncIterable<SchemaItemDiagnostic<RelationshipClass, any[]>> | AsyncIterable<RelationshipConstraintDiagnostic<any[]>>;\r\n\r\n if (relationshipOrConstraint instanceof RelationshipClass) {\r\n diagnostics = Rules.validateRelationship(relationshipOrConstraint);\r\n } else {\r\n diagnostics = Rules.validateRelationshipConstraint(relationshipOrConstraint);\r\n }\r\n\r\n const errorMessages = [];\r\n for await (const diagnostic of diagnostics) {\r\n errorMessages.push(`${diagnostic.code}: ${diagnostic.messageText}`);\r\n }\r\n\r\n if (errorMessages.length > 0) {\r\n return { errorMessage: errorMessages.join(\"\\r\\n\") };\r\n }\r\n\r\n return {};\r\n }\r\n}\r\n"]}
@@ -8,7 +8,7 @@ import { ECClasses } from "./ECClasses";
8
8
  * @alpha A class extending ECClasses allowing you to create schema items of type StructClass.
9
9
  */
10
10
  export declare class Structs extends ECClasses {
11
- constructor(_schemaEditor: SchemaContextEditor);
11
+ constructor(schemaEditor: SchemaContextEditor);
12
12
  create(schemaKey: SchemaKey, name: string, displayLabel?: string, baseClass?: SchemaItemKey): Promise<SchemaItemEditResults>;
13
13
  /**
14
14
  * Creates a StructClass through a StructClassProps.
@@ -1 +1 @@
1
- {"version":3,"file":"Structs.d.ts","sourceRoot":"","sources":["../../../src/Editing/Structs.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAoC,aAAa,EAAkB,SAAS,EAAe,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACrJ,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC;;GAEG;AACH,qBAAa,OAAQ,SAAQ,SAAS;gBACjB,aAAa,EAAE,mBAAmB;IAIxC,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,qBAAqB,CAAC;IA0BzI;;;;OAIG;IACU,eAAe,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,gBAAgB,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAelH"}
1
+ {"version":3,"file":"Structs.d.ts","sourceRoot":"","sources":["../../../src/Editing/Structs.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAoC,aAAa,EAAkB,SAAS,EAAe,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACrJ,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC;;GAEG;AACH,qBAAa,OAAQ,SAAQ,SAAS;gBACjB,YAAY,EAAE,mBAAmB;IAIvC,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,qBAAqB,CAAC;IA0BzI;;;;OAIG;IACU,eAAe,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,gBAAgB,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAelH"}
@@ -14,8 +14,8 @@ const ECClasses_1 = require("./ECClasses");
14
14
  * @alpha A class extending ECClasses allowing you to create schema items of type StructClass.
15
15
  */
16
16
  class Structs extends ECClasses_1.ECClasses {
17
- constructor(_schemaEditor) {
18
- super(_schemaEditor);
17
+ constructor(schemaEditor) {
18
+ super(ecschema_metadata_1.SchemaItemType.StructClass, schemaEditor);
19
19
  }
20
20
  async create(schemaKey, name, displayLabel, baseClass) {
21
21
  const schema = await this._schemaEditor.getSchema(schemaKey);
@@ -1 +1 @@
1
- {"version":3,"file":"Structs.js","sourceRoot":"","sources":["../../../src/Editing/Structs.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAqJ;AAErJ,2CAAwC;AAGxC;;GAEG;AACH,MAAa,OAAQ,SAAQ,qBAAS;IACpC,YAAmB,aAAkC;QACnD,KAAK,CAAC,aAAa,CAAC,CAAC;IACvB,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,IAAY,EAAE,YAAqB,EAAE,SAAyB;QACtG,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC7D,IAAI,MAAM,KAAK,SAAS;YACtB,OAAO,EAAE,YAAY,EAAE,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAEzF,MAAM,QAAQ,GAAG,CAAC,MAAM,MAAM,CAAC,iBAA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,CAAC,WAAW,CAAC,IAAI,CAAC,CAAiB,CAAC;QACpF,IAAI,QAAQ,KAAK,SAAS;YACxB,OAAO,EAAE,YAAY,EAAE,0BAA0B,WAAW,CAAC,IAAI,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;QAE/G,MAAM,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QACrC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC;IACnC,CAAC;CACF;AAnDD,0BAmDC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Editing\r\n */\r\n\r\nimport { DelayedPromiseWithProps, ECClass, SchemaItemKey, SchemaItemType, SchemaKey, StructClass, StructClassProps } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\r\nimport { ECClasses } from \"./ECClasses\";\r\nimport { MutableClass, MutableStructClass } from \"./Mutable/MutableClass\";\r\n\r\n/**\r\n * @alpha A class extending ECClasses allowing you to create schema items of type StructClass.\r\n */\r\nexport class Structs extends ECClasses {\r\n public constructor(_schemaEditor: SchemaContextEditor) {\r\n super(_schemaEditor);\r\n }\r\n\r\n public async create(schemaKey: SchemaKey, name: string, displayLabel?: string, baseClass?: SchemaItemKey): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n const newClass = (await schema.createStructClass(name)) as MutableStructClass;\r\n if (newClass === undefined)\r\n return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };\r\n\r\n if (baseClass !== undefined) {\r\n const baseClassItem = await schema.lookupItem<StructClass>(baseClass);\r\n if (baseClassItem === undefined)\r\n return { errorMessage: `Unable to locate base class ${baseClass.fullName} in schema ${schema.fullName}.` };\r\n\r\n if (baseClassItem.schemaItemType !== SchemaItemType.StructClass)\r\n return { errorMessage: `${baseClassItem.fullName} is not of type Struct Class.` };\r\n\r\n newClass.baseClass = new DelayedPromiseWithProps<SchemaItemKey, ECClass>(baseClass, async () => baseClassItem);\r\n }\r\n\r\n if (displayLabel)\r\n newClass.setDisplayLabel(displayLabel);\r\n\r\n return { itemKey: newClass.key };\r\n }\r\n\r\n /**\r\n * Creates a StructClass through a StructClassProps.\r\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\r\n * @param structProps a json object that will be used to populate the new StructClass. Needs a name value passed in.\r\n */\r\n public async createFromProps(schemaKey: SchemaKey, structProps: StructClassProps): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n if (structProps.name === undefined)\r\n return { errorMessage: `No name was supplied within props.` };\r\n\r\n const newClass = (await schema.createStructClass(structProps.name)) as MutableClass;\r\n if (newClass === undefined)\r\n return { errorMessage: `Failed to create class ${structProps.name} in schema ${schemaKey.toString(true)}.` };\r\n\r\n await newClass.fromJSON(structProps);\r\n return { itemKey: newClass.key };\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"Structs.js","sourceRoot":"","sources":["../../../src/Editing/Structs.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAqJ;AAErJ,2CAAwC;AAGxC;;GAEG;AACH,MAAa,OAAQ,SAAQ,qBAAS;IACpC,YAAmB,YAAiC;QAClD,KAAK,CAAC,kCAAc,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;IAClD,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,IAAY,EAAE,YAAqB,EAAE,SAAyB;QACtG,MAAM,MAAM,GAAG,MAAM,IA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AAE,YAAY,EAAE,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAEzF,IAAI,WAAW,CAAC,IAAI,KAAK,SAAS;YAChC,OAAO,EAAE,YAAY,EAAE,oCAAoC,EAAE,CAAC;QAEhE,MAAM,QAAQ,GAAG,CAAC,MAAM,MAAM,CAAC,iBAAiB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAiB,CAAC;QACpF,IAAI,QAAQ,KAAK,SAAS;YACxB,OAAO,EAAE,YAAY,EAAE,0BAA0B,WAAW,CAAC,IAAI,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;QAE/G,MAAM,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QACrC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC;IACnC,CAAC;CACF;AAnDD,0BAmDC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Editing\r\n */\r\n\r\nimport { DelayedPromiseWithProps, ECClass, SchemaItemKey, SchemaItemType, SchemaKey, StructClass, StructClassProps } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\r\nimport { ECClasses } from \"./ECClasses\";\r\nimport { MutableClass, MutableStructClass } from \"./Mutable/MutableClass\";\r\n\r\n/**\r\n * @alpha A class extending ECClasses allowing you to create schema items of type StructClass.\r\n */\r\nexport class Structs extends ECClasses {\r\n public constructor(schemaEditor: SchemaContextEditor) {\r\n super(SchemaItemType.StructClass, schemaEditor);\r\n }\r\n\r\n public async create(schemaKey: SchemaKey, name: string, displayLabel?: string, baseClass?: SchemaItemKey): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n const newClass = (await schema.createStructClass(name)) as MutableStructClass;\r\n if (newClass === undefined)\r\n return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };\r\n\r\n if (baseClass !== undefined) {\r\n const baseClassItem = await schema.lookupItem<StructClass>(baseClass);\r\n if (baseClassItem === undefined)\r\n return { errorMessage: `Unable to locate base class ${baseClass.fullName} in schema ${schema.fullName}.` };\r\n\r\n if (baseClassItem.schemaItemType !== SchemaItemType.StructClass)\r\n return { errorMessage: `${baseClassItem.fullName} is not of type Struct Class.` };\r\n\r\n newClass.baseClass = new DelayedPromiseWithProps<SchemaItemKey, ECClass>(baseClass, async () => baseClassItem);\r\n }\r\n\r\n if (displayLabel)\r\n newClass.setDisplayLabel(displayLabel);\r\n\r\n return { itemKey: newClass.key };\r\n }\r\n\r\n /**\r\n * Creates a StructClass through a StructClassProps.\r\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\r\n * @param structProps a json object that will be used to populate the new StructClass. Needs a name value passed in.\r\n */\r\n public async createFromProps(schemaKey: SchemaKey, structProps: StructClassProps): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n if (structProps.name === undefined)\r\n return { errorMessage: `No name was supplied within props.` };\r\n\r\n const newClass = (await schema.createStructClass(structProps.name)) as MutableClass;\r\n if (newClass === undefined)\r\n return { errorMessage: `Failed to create class ${structProps.name} in schema ${schemaKey.toString(true)}.` };\r\n\r\n await newClass.fromJSON(structProps);\r\n return { itemKey: newClass.key };\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"PropertyMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/PropertyMerger.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,uBAAuB,EAAkB,MAAM,kCAAkC,CAAC;AACrH,OAAO,EAA8M,aAAa,EAAoD,MAAM,0BAA0B,CAAC;AAiBvT;;GAEG;AACH,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAMtI;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,mBAAmB,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAQvJ"}
1
+ {"version":3,"file":"PropertyMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/PropertyMerger.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,uBAAuB,EAAkB,MAAM,kCAAkC,CAAC;AACrH,OAAO,EAA8M,aAAa,EAAoD,MAAM,0BAA0B,CAAC;AAgBvT;;GAEG;AACH,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAMtI;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,mBAAmB,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAQvJ"}
@@ -47,7 +47,8 @@ async function addClassProperty(context, itemKey, property) {
47
47
  if (property.customAttributes !== undefined) {
48
48
  const result = await (0, CustomAttributeMerger_1.applyCustomAttributes)(context, property.customAttributes, async (ca) => {
49
49
  try {
50
- await context.editor.entities.properties.addCustomAttribute(itemKey, property.name, ca);
50
+ const classEditor = await getClassEditor(context, itemKey);
51
+ await classEditor.properties.addCustomAttribute(itemKey, property.name, ca);
51
52
  return {};
52
53
  }
53
54
  catch (e) {
@@ -87,24 +88,25 @@ async function modifyClassProperty(context, itemKey, propertyProps) {
87
88
  if (propertyProps.kindOfQuantity !== undefined) {
88
89
  return { errorMessage: `Changing the property '${property.fullName}' kind of quantity is not supported.` };
89
90
  }
91
+ const classEditor = await getClassEditor(context, ecClass);
90
92
  if (propertyProps.description !== undefined) {
91
- property.setDescription(propertyProps.description);
93
+ await classEditor.properties.setDescription(itemKey, propertyProps.name, propertyProps.description);
92
94
  }
93
95
  if (propertyProps.label !== undefined) {
94
- property.setLabel(propertyProps.label);
96
+ await classEditor.properties.setLabel(itemKey, propertyProps.name, propertyProps.label);
95
97
  }
96
98
  if (propertyProps.isReadOnly !== undefined) {
97
- property.setIsReadOnly(propertyProps.isReadOnly);
99
+ await classEditor.properties.setIsReadOnly(itemKey, propertyProps.name, propertyProps.isReadOnly);
98
100
  }
99
101
  if (propertyProps.priority !== undefined) {
100
- property.setPriority(propertyProps.priority);
102
+ await classEditor.properties.setPriority(itemKey, propertyProps.name, propertyProps.priority);
101
103
  }
102
104
  if (property.isArray()) {
103
- await arrayProperty.merge(property, propertyProps);
105
+ await arrayProperty.merge(context, itemKey, property.name, propertyProps);
104
106
  }
105
107
  if (propertyProps.category !== undefined) {
106
108
  const categoryKey = await (0, SchemaItemMerger_1.updateSchemaItemKey)(context, propertyProps.category);
107
- await context.editor.entities.properties.setCategory(itemKey, property.name, categoryKey);
109
+ await classEditor.properties.setCategory(itemKey, property.name, categoryKey);
108
110
  }
109
111
  if (property.isEnumeration()) {
110
112
  return enumerationProperty.merge(context, itemKey, property, propertyProps);
@@ -120,16 +122,36 @@ async function modifyClassProperty(context, itemKey, propertyProps) {
120
122
  }
121
123
  return {};
122
124
  }
125
+ async function getClassEditor(context, ecClass) {
126
+ const schemaItemType = ecschema_metadata_1.ECClass.isECClass(ecClass)
127
+ ? ecClass.schemaItemType
128
+ : (await context.editor.schemaContext.getSchemaItem(ecClass))?.schemaItemType;
129
+ switch (schemaItemType) {
130
+ case ecschema_metadata_1.SchemaItemType.EntityClass:
131
+ return context.editor.entities;
132
+ case ecschema_metadata_1.SchemaItemType.Mixin:
133
+ return context.editor.mixins;
134
+ case ecschema_metadata_1.SchemaItemType.StructClass:
135
+ return context.editor.structs;
136
+ case ecschema_metadata_1.SchemaItemType.CustomAttributeClass:
137
+ return context.editor.customAttributes;
138
+ case ecschema_metadata_1.SchemaItemType.RelationshipClass:
139
+ return context.editor.relationships;
140
+ default:
141
+ throw new Error("SchemaItemType not supported");
142
+ }
143
+ }
123
144
  const arrayProperty = {
124
145
  is(property) {
125
146
  return "minOccurs" in property && "maxOccurs" in property;
126
147
  },
127
- async merge(property, props) {
148
+ async merge(context, itemKey, propertyName, props) {
149
+ const classEditor = await getClassEditor(context, itemKey);
128
150
  if (props.minOccurs !== undefined) {
129
- property.setMinOccurs(props.minOccurs);
151
+ await classEditor.arrayProperties.setMinOccurs(itemKey, propertyName, props.minOccurs);
130
152
  }
131
153
  if (props.maxOccurs !== undefined) {
132
- property.setMaxOccurs(props.maxOccurs);
154
+ await classEditor.arrayProperties.setMaxOccurs(itemKey, propertyName, props.maxOccurs);
133
155
  }
134
156
  },
135
157
  };
@@ -144,9 +166,10 @@ const enumerationProperty = {
144
166
  return { errorMessage: `Unable to locate the enumeration class ${enumerationKey.name} in the context schema.` };
145
167
  }
146
168
  property.typeName = enumerationKey.fullName;
169
+ const classEditor = await getClassEditor(context, itemKey);
147
170
  return arrayProperty.is(property)
148
- ? context.editor.entities.createEnumerationArrayPropertyFromProps(itemKey, property.name, enumerationType, property)
149
- : context.editor.entities.createEnumerationPropertyFromProps(itemKey, property.name, enumerationType, property);
171
+ ? classEditor.createEnumerationArrayPropertyFromProps(itemKey, property.name, enumerationType, property)
172
+ : classEditor.createEnumerationPropertyFromProps(itemKey, property.name, enumerationType, property);
150
173
  },
151
174
  async merge(context, itemKey, property, props) {
152
175
  if ("enumeration" in props && props.enumeration !== undefined) {
@@ -194,29 +217,30 @@ const primitiveProperty = {
194
217
  if (propertyType === undefined) {
195
218
  return { errorMessage: `Invalid property type ${property.typeName} on property ${property.name}` };
196
219
  }
220
+ const classEditor = await getClassEditor(context, itemKey);
197
221
  return arrayProperty.is(property)
198
- ? context.editor.entities.createPrimitiveArrayPropertyFromProps(itemKey, property.name, propertyType, property)
199
- : context.editor.entities.createPrimitivePropertyFromProps(itemKey, property.name, propertyType, property);
222
+ ? classEditor.createPrimitiveArrayPropertyFromProps(itemKey, property.name, propertyType, property)
223
+ : classEditor.createPrimitivePropertyFromProps(itemKey, property.name, propertyType, property);
200
224
  },
201
- async merge(_context, _itemKey, property, props) {
202
- const mutable = property;
225
+ async merge(context, itemKey, property, props) {
203
226
  if (props.typeName) {
204
227
  return { errorMessage: `Changing the property '${property.fullName}' primitiveType is not supported.` };
205
228
  }
229
+ const classEditor = await getClassEditor(context, itemKey);
206
230
  if (props.extendedTypeName !== undefined) {
207
- mutable.setExtendedTypeName(props.extendedTypeName);
231
+ await classEditor.primitiveProperties.setExtendedTypeName(itemKey, property.name, props.extendedTypeName);
208
232
  }
209
233
  if (props.minLength !== undefined) {
210
- mutable.setMinLength(props.minLength);
234
+ await classEditor.primitiveProperties.setMinLength(itemKey, property.name, props.minLength);
211
235
  }
212
236
  if (props.maxLength !== undefined) {
213
- mutable.setMaxLength(props.maxLength);
237
+ await classEditor.primitiveProperties.setMaxLength(itemKey, property.name, props.maxLength);
214
238
  }
215
239
  if (props.minValue !== undefined) {
216
- mutable.setMinValue(props.minValue);
240
+ await classEditor.primitiveProperties.setMinValue(itemKey, property.name, props.minValue);
217
241
  }
218
242
  if (props.maxValue !== undefined) {
219
- mutable.setMaxValue(props.maxValue);
243
+ await classEditor.primitiveProperties.setMaxValue(itemKey, property.name, props.maxValue);
220
244
  }
221
245
  return {};
222
246
  },
@@ -232,9 +256,10 @@ const structProperty = {
232
256
  return { errorMessage: `Unable to locate the struct ${structKey.name} in the context schema.` };
233
257
  }
234
258
  property.typeName = structKey.fullName;
259
+ const classEditor = await getClassEditor(context, itemKey);
235
260
  return arrayProperty.is(property)
236
- ? context.editor.entities.createStructArrayPropertyFromProps(itemKey, property.name, structType, property)
237
- : context.editor.entities.createStructPropertyFromProps(itemKey, property.name, structType, property);
261
+ ? classEditor.createStructArrayPropertyFromProps(itemKey, property.name, structType, property)
262
+ : classEditor.createStructPropertyFromProps(itemKey, property.name, structType, property);
238
263
  },
239
264
  async merge(_context, _itemKey, property, props) {
240
265
  if ("structClass" in props && props.structClass !== undefined) {
@@ -1 +1 @@
1
- {"version":3,"file":"PropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/PropertyMerger.ts"],"names":[],"mappings":";;;AAOA,gEAAuT;AACvT,yDAAmF;AAInF,mEAAgE;AAYhE;;GAEG;AACI,KAAK,UAAU,uBAAuB,CAAC,OAA2B,EAAE,MAA+B;IACxG,MAAM,QAAQ,GAAG,IAAI,iCAAa,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAC7E,OAAO,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE;QACnD,GAAG,MAAM,CAAC,UAAU;QACpB,IAAI,EAAE,MAAM,CAAC,IAAI;KACE,CAAC,CAAC;AACzB,CAAC;AAND,0DAMC;AAED;;GAEG;AACI,KAAK,UAAU,oBAAoB,CAAC,OAA2B,EAAE,MAA2B,EAAE,OAAsB;IACzH,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,UAAU,CAAC,UAAU,IAAI,EAAE,EAAE;QACzD,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QAC5E,IAAI,MAAM,CAAC,YAAY,EAAE;YACvB,O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/B,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kCAAkC,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC;YAC1G,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,6BAA6B,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;IAC1G,CAAC;IACD,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK;QAC7C,IAAI,aAAa,IAAI,KAAK,IAAI,KAAK,CAAC,WAAW,KAAK,SAAS,EAAE;YAC7D,OAAO,EAAE,YAAY,EAAE,0BAA0B,QAAQ,CAAC,QAAQ,iCAAiC,EAAE,CAAC;SACvG;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;CACF,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport type { SchemaEditResults } from \"../ecschema-editing\";\r\nimport type { SchemaMergeContext } from \"./SchemaMerger\";\r\nimport type { ClassItemDifference, ClassPropertyDifference, DifferenceType } from \"../Differencing/SchemaDifference\";\r\nimport { AnyProperty, AnyPropertyProps, ArrayPropertyProps, CustomAttribute, ECClass, Enumeration, EnumerationPropertyProps, NavigationPropertyProps, parsePrimitiveType, PrimitivePropertyProps, RelationshipClass, SchemaItemKey, SchemaItemType, StructClass, StructPropertyProps } from \"@itwin/ecschema-metadata\";\r\nimport { updateSchemaItemFullName, updateSchemaItemKey } from \"./SchemaItemMerger\";\r\nimport { MutableProperty } from \"../Editing/Mutable/MutableProperty\";\r\nimport { MutableArrayProperty } from \"../Editing/Mutable/MutableArrayProperty\";\r\nimport { MutablePrimitiveOrEnumPropertyBase } from \"../Editing/Mutable/MutablePrimitiveOrEnumProperty\";\r\nimport { applyCustomAttributes } from \"./CustomAttributeMerger\";\r\n\r\ntype PartialEditable<T> = {\r\n -readonly [P in keyof T]: T[P];\r\n};\r\n\r\ninterface PropertyMerger<T extends AnyPropertyProps> {\r\n is(property: AnyPropertyProps): property is T;\r\n add(context: SchemaMergeContext, itemKey: SchemaItemKey, props: PartialEditable<T>): Promise<SchemaEditResults>;\r\n merge(context: SchemaMergeContext, itemKey: SchemaItemKey, property: AnyProperty, props: T): Promise<SchemaEditResults>;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport async function mergePropertyDifference(context: SchemaMergeContext, change: ClassPropertyDifference): Promise<SchemaEditResults> {\r\n const classKey = new SchemaItemKey(change.itemName, context.targetSchemaKey);\r\n return mergeClassProperty(context, change, classKey, {\r\n ...change.difference,\r\n name: change.path,\r\n } as AnyPropertyProps);\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport async function mergeClassProperties(context: SchemaMergeContext, change: ClassItemDifference, itemKey: SchemaItemKey): Promise<SchemaEditResults> {\r\n for (const property of change.difference.properties || []) {\r\n const result = await mergeClassProperty(context, change, itemKey, property);\r\n if (result.errorMessage) {\r\n return result;\r\n }\r\n }\r\n return {};\r\n}\r\n\r\nasync function mergeClassProperty(context: SchemaMergeContext, change: { changeType: DifferenceType }, itemKey: SchemaItemKey, property: AnyPropertyProps) {\r\n return change.changeType === \"add\"\r\n ? addClassProperty(context, itemKey, property)\r\n : modifyClassProperty(context, itemKey, property);\r\n}\r\n\r\nasync function addClassProperty(context: SchemaMergeContext, itemKey: SchemaItemKey, property: PartialEditable<AnyPropertyProps>): Promise<SchemaEditResults> {\r\n\r\n if (property.category !== undefined) {\r\n property.category = await updateSchemaItemFullName(context, property.category);\r\n }\r\n\r\n if (property.kindOfQuantity !== undefined) {\r\n property.kindOfQuantity = await updateSchemaItemFullName(context, property.kindOfQuantity);\r\n }\r\n\r\n const createResult = await createProperty(context, itemKey, property);\r\n if (createResult.errorMessage) {\r\n return createResult;\r\n }\r\n\r\n if (property.customAttributes !== undefined) {\r\n const result = await applyCustomAttributes(context, property.customAttributes as CustomAttribute[], async (ca) => {\r\n try{\r\n await context.editor.entities.properties.addCustomAttribute(itemKey, property.name, ca);\r\n return {};\r\n } catch(e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n });\r\n if (result.errorMessage) {\r\n return result;\r\n }\r\n }\r\n\r\n return {};\r\n}\r\n\r\nasync function createProperty(context: SchemaMergeContext, itemKey: SchemaItemKey, property: PartialEditable<AnyPropertyProps>) {\r\n if (enumerationProperty.is(property)) {\r\n return enumerationProperty.add(context, itemKey, property);\r\n }\r\n if (navigationProperty.is(property)) {\r\n return navigationProperty.add(context, itemKey, property);\r\n }\r\n if (primitiveProperty.is(property)) {\r\n return primitiveProperty.add(context, itemKey, property);\r\n }\r\n if (structProperty.is(property)) {\r\n return structProperty.add(context, itemKey, property);\r\n }\r\n return {};\r\n}\r\n\r\nasync function modifyClassProperty(context: SchemaMergeContext, itemKey: SchemaItemKey, propertyProps: AnyPropertyProps): Promise<SchemaEditResults> {\r\n const ecClass = await context.editor.schemaContext.getSchemaItem(itemKey) as ECClass;\r\n const property = await ecClass.getProperty(propertyProps.name) as MutableProperty;\r\n if (property === undefined) {\r\n return { errorMessage: `Couldn't find property ${propertyProps.name} on class ${itemKey.name}` };\r\n }\r\n\r\n if (propertyProps.type !== undefined) {\r\n return { errorMessage: `Changing the property '${property.fullName}' type is not supported.` };\r\n }\r\n if (propertyProps.kindOfQuantity !== undefined) {\r\n return { errorMessage: `Changing the property '${property.fullName}' kind of quantity is not supported.` };\r\n }\r\n\r\n if (propertyProps.description !== undefined) {\r\n property.setDescription(propertyProps.description);\r\n }\r\n if (propertyProps.label !== undefined) {\r\n property.setLabel(propertyProps.label);\r\n }\r\n if (propertyProps.isReadOnly !== undefined) {\r\n property.setIsReadOnly(propertyProps.isReadOnly);\r\n }\r\n if (propertyProps.priority !== undefined) {\r\n property.setPriority(propertyProps.priority);\r\n }\r\n\r\n if (property.isArray()) {\r\n await arrayProperty.merge(property as any, propertyProps);\r\n }\r\n\r\n if (propertyProps.category !== undefined) {\r\n const categoryKey = await updateSchemaItemKey(context, propertyProps.category);\r\n await context.editor.entities.properties.setCategory(itemKey, property.name, categoryKey);\r\n }\r\n\r\n if (property.isEnumeration()) {\r\n return enumerationProperty.merge(context, itemKey, property, propertyProps as any);\r\n }\r\n if (property.isNavigation()) {\r\n return navigationProperty.merge(context, itemKey, property, propertyProps as any);\r\n }\r\n if (property.isPrimitive()) {\r\n return primitiveProperty.merge(context, itemKey, property, propertyProps as any);\r\n }\r\n if (property.isStruct()) {\r\n return structProperty.merge(context, itemKey, property, propertyProps as any);\r\n }\r\n\r\n return {};\r\n}\r\n\r\nconst arrayProperty = {\r\n is(property: AnyPropertyProps): boolean {\r\n return \"minOccurs\" in property && \"maxOccurs\" in property;\r\n },\r\n async merge(property: MutableArrayProperty, props: ArrayPropertyProps) {\r\n if (props.minOccurs !== undefined) {\r\n property.setMinOccurs(props.minOccurs);\r\n }\r\n if (props.maxOccurs !== undefined) {\r\n property.setMaxOccurs(props.maxOccurs);\r\n }\r\n },\r\n};\r\n\r\nconst enumerationProperty: PropertyMerger<EnumerationPropertyProps> = {\r\n is(property): property is EnumerationPropertyProps {\r\n return primitiveProperty.is(property) && property.typeName.includes(\".\");\r\n },\r\n async add(context, itemKey, property): Promise<SchemaEditResults> {\r\n const enumerationKey = await updateSchemaItemKey(context, property.typeName);\r\n const enumerationType = await context.editor.schemaContext.getSchemaItem<Enumeration>(enumerationKey);\r\n if (enumerationType === undefined) {\r\n return { errorMessage: `Unable to locate the enumeration class ${enumerationKey.name} in the context schema.` };\r\n }\r\n\r\n property.typeName = enumerationKey.fullName;\r\n\r\n return arrayProperty.is(property)\r\n ? context.editor.entities.createEnumerationArrayPropertyFromProps(itemKey, property.name, enumerationType, property)\r\n : context.editor.entities.createEnumerationPropertyFromProps(itemKey, property.name, enumerationType, property);\r\n },\r\n async merge(context, itemKey, property, props) {\r\n if (\"enumeration\" in props && props.enumeration !== undefined) {\r\n return { errorMessage: `Changing the property '${property.fullName}' enumeration is not supported.` };\r\n }\r\n return primitiveProperty.merge(context, itemKey, property, props);\r\n },\r\n};\r\n\r\nconst navigationProperty: PropertyMerger<NavigationPropertyProps> = {\r\n is(property): property is NavigationPropertyProps {\r\n return property.type === \"NavigationProperty\";\r\n },\r\n async add(context, itemKey, property): Promise<SchemaEditResults> {\r\n const relationshipKey = await updateSchemaItemKey(context, property.relationshipName);\r\n const relationshipType = await context.editor.schemaContext.getSchemaItem<RelationshipClass>(relationshipKey);\r\n if (relationshipType === undefined) {\r\n return { errorMessage: `Unable to locate the relationship class ${relationshipKey.name} in the context schema.` };\r\n }\r\n\r\n property.relationshipName = relationshipKey.fullName;\r\n\r\n const ecClass = await context.editor.schemaContext.getSchemaItem(itemKey) as ECClass;\r\n if (ecClass.schemaItemType === SchemaItemType.EntityClass)\r\n return context.editor.entities.createNavigationPropertyFromProps(itemKey, property);\r\n if (ecClass.schemaItemType === SchemaItemType.Mixin)\r\n return context.editor.mixins.createNavigationPropertyFromProps(itemKey, property);\r\n if (ecClass.schemaItemType === SchemaItemType.RelationshipClass)\r\n return context.editor.relationships.createNavigationPropertyFromProps(itemKey, property);\r\n return { errorMessage: `Navigation property can't be added to ${ecClass.schemaItemType}.` };\r\n },\r\n async merge(_context, _itemKey, property, props) {\r\n if (props.direction !== undefined) {\r\n return { errorMessage: `Changing the property '${property.fullName}' direction is not supported.` };\r\n }\r\n if (\"relationshipClass\" in props && props.relationshipClass !== undefined) {\r\n return { errorMessage: `Changing the property '${property.fullName}' relationship class is not supported.` };\r\n }\r\n return {};\r\n },\r\n};\r\n\r\nconst primitiveProperty: PropertyMerger<PrimitivePropertyProps> = {\r\n is(property): property is PrimitivePropertyProps {\r\n return property.type === \"PrimitiveProperty\" || property.type === \"PrimitiveArrayProperty\";\r\n },\r\n async add(context, itemKey, property): Promise<SchemaEditResults> {\r\n const propertyType = parsePrimitiveType(property.typeName);\r\n if (propertyType === undefined) {\r\n return { errorMessage: `Invalid property type ${property.typeName} on property ${property.name}` };\r\n }\r\n\r\n return arrayProperty.is(property)\r\n ? context.editor.entities.createPrimitiveArrayPropertyFromProps(itemKey, property.name, propertyType, property)\r\n : context.editor.entities.createPrimitivePropertyFromProps(itemKey, property.name, propertyType, property);\r\n },\r\n async merge(_context, _itemKey, property, props) {\r\n const mutable = property as unknown as MutablePrimitiveOrEnumPropertyBase;\r\n if (props.typeName) {\r\n return { errorMessage: `Changing the property '${property.fullName}' primitiveType is not supported.` };\r\n }\r\n\r\n if (props.extendedTypeName !== undefined) {\r\n mutable.setExtendedTypeName(props.extendedTypeName);\r\n }\r\n if (props.minLength !== undefined) {\r\n mutable.setMinLength(props.minLength);\r\n }\r\n if (props.maxLength !== undefined) {\r\n mutable.setMaxLength(props.maxLength);\r\n }\r\n if (props.minValue !== undefined) {\r\n mutable.setMinValue(props.minValue);\r\n }\r\n if (props.maxValue !== undefined) {\r\n mutable.setMaxValue(props.maxValue);\r\n }\r\n return {};\r\n },\r\n};\r\n\r\nconst structProperty: PropertyMerger<StructPropertyProps> = {\r\n is(property): property is StructPropertyProps {\r\n return property.type === \"StructProperty\" || property.type === \"StructArrayProperty\";\r\n },\r\n async add(context, itemKey, property): Promise<SchemaEditResults> {\r\n const structKey = await updateSchemaItemKey(context, property.typeName);\r\n const structType = await context.editor.schemaContext.getSchemaItem<StructClass>(structKey);\r\n if (structType === undefined) {\r\n return { errorMessage: `Unable to locate the struct ${structKey.name} in the context schema.` };\r\n }\r\n\r\n property.typeName = structKey.fullName;\r\n\r\n return arrayProperty.is(property)\r\n ? context.editor.entities.createStructArrayPropertyFromProps(itemKey, property.name, structType, property)\r\n : context.editor.entities.createStructPropertyFromProps(itemKey, property.name, structType, property);\r\n },\r\n async merge(_context, _itemKey, property, props) {\r\n if (\"structClass\" in props && props.structClass !== undefined) {\r\n return { errorMessage: `Changing the property '${property.fullName}' structClass is not supported.` };\r\n }\r\n return {};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O,CAAC,CAAC;QAC3D,OAAO,aAAa,CAAC,EAAE,CAAC,QAAQ,CAAC;YAC/B,CAAC,CAAC,WAAW,CAAC,kCAAkC,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC;YAC9F,CAAC,CAAC,WAAW,CAAC,6BAA6B,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;IAC9F,CAAC;IACD,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK;QAC7C,IAAI,aAAa,IAAI,KAAK,IAAI,KAAK,CAAC,WAAW,KAAK,SAAS,EAAE;YAC7D,OAAO,EAAE,YAAY,EAAE,0BAA0B,QAAQ,CAAC,QAAQ,iCAAiC,EAAE,CAAC;SACvG;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;CACF,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport type { SchemaEditResults } from \"../ecschema-editing\";\r\nimport type { SchemaMergeContext } from \"./SchemaMerger\";\r\nimport type { ClassItemDifference, ClassPropertyDifference, DifferenceType } from \"../Differencing/SchemaDifference\";\r\nimport { AnyProperty, AnyPropertyProps, ArrayPropertyProps, CustomAttribute, ECClass, Enumeration, EnumerationPropertyProps, NavigationPropertyProps, parsePrimitiveType, PrimitivePropertyProps, RelationshipClass, SchemaItemKey, SchemaItemType, StructClass, StructPropertyProps } from \"@itwin/ecschema-metadata\";\r\nimport { updateSchemaItemFullName, updateSchemaItemKey } from \"./SchemaItemMerger\";\r\nimport { MutableProperty } from \"../Editing/Mutable/MutableProperty\";\r\nimport { applyCustomAttributes } from \"./CustomAttributeMerger\";\r\nimport { ECClasses } from \"../Editing/ECClasses\";\r\n\r\ntype PartialEditable<T> = {\r\n -readonly [P in keyof T]: T[P];\r\n};\r\n\r\ninterface PropertyMerger<T extends AnyPropertyProps> {\r\n is(property: AnyPropertyProps): property is T;\r\n add(context: SchemaMergeContext, itemKey: SchemaItemKey, props: PartialEditable<T>): Promise<SchemaEditResults>;\r\n merge(context: SchemaMergeContext, itemKey: SchemaItemKey, property: AnyProperty, props: T): Promise<SchemaEditResults>;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport async function mergePropertyDifference(context: SchemaMergeContext, change: ClassPropertyDifference): Promise<SchemaEditResults> {\r\n const classKey = new SchemaItemKey(change.itemName, context.targetSchemaKey);\r\n return mergeClassProperty(context, change, classKey, {\r\n ...change.difference,\r\n name: change.path,\r\n } as AnyPropertyProps);\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport async function mergeClassProperties(context: SchemaMergeContext, change: ClassItemDifference, itemKey: SchemaItemKey): Promise<SchemaEditResults> {\r\n for (const property of change.difference.properties || []) {\r\n const result = await mergeClassProperty(context, change, itemKey, property);\r\n if (result.errorMessage) {\r\n return result;\r\n }\r\n }\r\n return {};\r\n}\r\n\r\nasync function mergeClassProperty(context: SchemaMergeContext, change: { changeType: DifferenceType }, itemKey: SchemaItemKey, property: AnyPropertyProps) {\r\n return change.changeType === \"add\"\r\n ? addClassProperty(context, itemKey, property)\r\n : modifyClassProperty(context, itemKey, property);\r\n}\r\n\r\nasync function addClassProperty(context: SchemaMergeContext, itemKey: SchemaItemKey, property: PartialEditable<AnyPropertyProps>): Promise<SchemaEditResults> {\r\n if (property.category !== undefined) {\r\n property.category = await updateSchemaItemFullName(context, property.category);\r\n }\r\n\r\n if (property.kindOfQuantity !== undefined) {\r\n property.kindOfQuantity = await updateSchemaItemFullName(context, property.kindOfQuantity);\r\n }\r\n\r\n const createResult = await createProperty(context, itemKey, property);\r\n if (createResult.errorMessage) {\r\n return createResult;\r\n }\r\n\r\n if (property.customAttributes !== undefined) {\r\n const result = await applyCustomAttributes(context, property.customAttributes as CustomAttribute[], async (ca) => {\r\n try{\r\n const classEditor = await getClassEditor(context, itemKey);\r\n await classEditor.properties.addCustomAttribute(itemKey, property.name, ca);\r\n return {};\r\n } catch(e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n });\r\n if (result.errorMessage) {\r\n return result;\r\n }\r\n }\r\n\r\n return {};\r\n}\r\n\r\nasync function createProperty(context: SchemaMergeContext, itemKey: SchemaItemKey, property: PartialEditable<AnyPropertyProps>) {\r\n if (enumerationProperty.is(property)) {\r\n return enumerationProperty.add(context, itemKey, property);\r\n }\r\n if (navigationProperty.is(property)) {\r\n return navigationProperty.add(context, itemKey, property);\r\n }\r\n if (primitiveProperty.is(property)) {\r\n return primitiveProperty.add(context, itemKey, property);\r\n }\r\n if (structProperty.is(property)) {\r\n return structProperty.add(context, itemKey, property);\r\n }\r\n return {};\r\n}\r\n\r\nasync function modifyClassProperty(context: SchemaMergeContext, itemKey: SchemaItemKey, propertyProps: AnyPropertyProps): Promise<SchemaEditResults> {\r\n const ecClass = await context.editor.schemaContext.getSchemaItem(itemKey) as ECClass;\r\n const property = await ecClass.getProperty(propertyProps.name) as MutableProperty;\r\n if (property === undefined) {\r\n return { errorMessage: `Couldn't find property ${propertyProps.name} on class ${itemKey.name}` };\r\n }\r\n\r\n if (propertyProps.type !== undefined) {\r\n return { errorMessage: `Changing the property '${property.fullName}' type is not supported.` };\r\n }\r\n if (propertyProps.kindOfQuantity !== undefined) {\r\n return { errorMessage: `Changing the property '${property.fullName}' kind of quantity is not supported.` };\r\n }\r\n\r\n const classEditor = await getClassEditor(context, ecClass);\r\n\r\n if (propertyProps.description !== undefined) {\r\n await classEditor.properties.setDescription(itemKey, propertyProps.name, propertyProps.description);\r\n }\r\n if (propertyProps.label !== undefined) {\r\n await classEditor.properties.setLabel(itemKey, propertyProps.name, propertyProps.label);\r\n }\r\n if (propertyProps.isReadOnly !== undefined) {\r\n await classEditor.properties.setIsReadOnly(itemKey, propertyProps.name, propertyProps.isReadOnly);\r\n }\r\n if (propertyProps.priority !== undefined) {\r\n await classEditor.properties.setPriority(itemKey, propertyProps.name, propertyProps.priority);\r\n }\r\n\r\n if (property.isArray()) {\r\n await arrayProperty.merge(context, itemKey, property.name, propertyProps);\r\n }\r\n\r\n if (propertyProps.category !== undefined) {\r\n const categoryKey = await updateSchemaItemKey(context, propertyProps.category);\r\n await classEditor.properties.setCategory(itemKey, property.name, categoryKey);\r\n }\r\n\r\n if (property.isEnumeration()) {\r\n return enumerationProperty.merge(context, itemKey, property, propertyProps as any);\r\n }\r\n if (property.isNavigation()) {\r\n return navigationProperty.merge(context, itemKey, property, propertyProps as any);\r\n }\r\n if (property.isPrimitive()) {\r\n return primitiveProperty.merge(context, itemKey, property, propertyProps as any);\r\n }\r\n if (property.isStruct()) {\r\n return structProperty.merge(context, itemKey, property, propertyProps as any);\r\n }\r\n\r\n return {};\r\n}\r\n\r\nasync function getClassEditor(context: SchemaMergeContext, ecClass: ECClass | SchemaItemKey): Promise<ECClasses> {\r\n const schemaItemType = ECClass.isECClass(ecClass)\r\n ? ecClass.schemaItemType\r\n : (await context.editor.schemaContext.getSchemaItem<ECClass>(ecClass))?.schemaItemType;\r\n\r\n switch(schemaItemType) {\r\n case SchemaItemType.EntityClass:\r\n return context.editor.entities;\r\n case SchemaItemType.Mixin:\r\n return context.editor.mixins;\r\n case SchemaItemType.StructClass:\r\n return context.editor.structs;\r\n case SchemaItemType.CustomAttributeClass:\r\n return context.editor.customAttributes;\r\n case SchemaItemType.RelationshipClass:\r\n return context.editor.relationships;\r\n default:\r\n throw new Error(\"SchemaItemType not supported\");\r\n }\r\n}\r\n\r\nconst arrayProperty = {\r\n is(property: AnyPropertyProps): boolean {\r\n return \"minOccurs\" in property && \"maxOccurs\" in property;\r\n },\r\n async merge(context: SchemaMergeContext, itemKey: SchemaItemKey, propertyName: string, props: ArrayPropertyProps) {\r\n const classEditor = await getClassEditor(context, itemKey);\r\n if (props.minOccurs !== undefined) {\r\n await classEditor.arrayProperties.setMinOccurs(itemKey, propertyName, props.minOccurs);\r\n }\r\n if (props.maxOccurs !== undefined) {\r\n await classEditor.arrayProperties.setMaxOccurs(itemKey, propertyName, props.maxOccurs);\r\n }\r\n },\r\n};\r\n\r\nconst enumerationProperty: PropertyMerger<EnumerationPropertyProps> = {\r\n is(property): property is EnumerationPropertyProps {\r\n return primitiveProperty.is(property) && property.typeName.includes(\".\");\r\n },\r\n async add(context, itemKey, property): Promise<SchemaEditResults> {\r\n const enumerationKey = await updateSchemaItemKey(context, property.typeName);\r\n const enumerationType = await context.editor.schemaContext.getSchemaItem<Enumeration>(enumerationKey);\r\n if (enumerationType === undefined) {\r\n return { errorMessage: `Unable to locate the enumeration class ${enumerationKey.name} in the context schema.` };\r\n }\r\n\r\n property.typeName = enumerationKey.fullName;\r\n\r\n const classEditor = await getClassEditor(context, itemKey);\r\n return arrayProperty.is(property)\r\n ? classEditor.createEnumerationArrayPropertyFromProps(itemKey, property.name, enumerationType, property)\r\n : classEditor.createEnumerationPropertyFromProps(itemKey, property.name, enumerationType, property);\r\n },\r\n async merge(context, itemKey, property, props) {\r\n if (\"enumeration\" in props && props.enumeration !== undefined) {\r\n return { errorMessage: `Changing the property '${property.fullName}' enumeration is not supported.` };\r\n }\r\n return primitiveProperty.merge(context, itemKey, property, props);\r\n },\r\n};\r\n\r\nconst navigationProperty: PropertyMerger<NavigationPropertyProps> = {\r\n is(property): property is NavigationPropertyProps {\r\n return property.type === \"NavigationProperty\";\r\n },\r\n async add(context, itemKey, property): Promise<SchemaEditResults> {\r\n const relationshipKey = await updateSchemaItemKey(context, property.relationshipName);\r\n const relationshipType = await context.editor.schemaContext.getSchemaItem<RelationshipClass>(relationshipKey);\r\n if (relationshipType === undefined) {\r\n return { errorMessage: `Unable to locate the relationship class ${relationshipKey.name} in the context schema.` };\r\n }\r\n\r\n property.relationshipName = relationshipKey.fullName;\r\n\r\n const ecClass = await context.editor.schemaContext.getSchemaItem(itemKey) as ECClass;\r\n if (ecClass.schemaItemType === SchemaItemType.EntityClass)\r\n return context.editor.entities.createNavigationPropertyFromProps(itemKey, property);\r\n if (ecClass.schemaItemType === SchemaItemType.Mixin)\r\n return context.editor.mixins.createNavigationPropertyFromProps(itemKey, property);\r\n if (ecClass.schemaItemType === SchemaItemType.RelationshipClass)\r\n return context.editor.relationships.createNavigationPropertyFromProps(itemKey, property);\r\n return { errorMessage: `Navigation property can't be added to ${ecClass.schemaItemType}.` };\r\n },\r\n async merge(_context, _itemKey, property, props) {\r\n if (props.direction !== undefined) {\r\n return { errorMessage: `Changing the property '${property.fullName}' direction is not supported.` };\r\n }\r\n if (\"relationshipClass\" in props && props.relationshipClass !== undefined) {\r\n return { errorMessage: `Changing the property '${property.fullName}' relationship class is not supported.` };\r\n }\r\n return {};\r\n },\r\n};\r\n\r\nconst primitiveProperty: PropertyMerger<PrimitivePropertyProps> = {\r\n is(property): property is PrimitivePropertyProps {\r\n return property.type === \"PrimitiveProperty\" || property.type === \"PrimitiveArrayProperty\";\r\n },\r\n async add(context, itemKey, property): Promise<SchemaEditResults> {\r\n const propertyType = parsePrimitiveType(property.typeName);\r\n if (propertyType === undefined) {\r\n return { errorMessage: `Invalid property type ${property.typeName} on property ${property.name}` };\r\n }\r\n\r\n const classEditor = await getClassEditor(context, itemKey);\r\n return arrayProperty.is(property)\r\n ? classEditor.createPrimitiveArrayPropertyFromProps(itemKey, property.name, propertyType, property)\r\n : classEditor.createPrimitivePropertyFromProps(itemKey, property.name, propertyType, property);\r\n },\r\n async merge(context, itemKey, property, props) {\r\n if (props.typeName) {\r\n return { errorMessage: `Changing the property '${property.fullName}' primitiveType is not supported.` };\r\n }\r\n\r\n const classEditor = await getClassEditor(context, itemKey);\r\n if (props.extendedTypeName !== undefined) {\r\n await classEditor.primitiveProperties.setExtendedTypeName(itemKey, property.name, props.extendedTypeName);\r\n }\r\n if (props.minLength !== undefined) {\r\n await classEditor.primitiveProperties.setMinLength(itemKey, property.name, props.minLength);\r\n }\r\n if (props.maxLength !== undefined) {\r\n await classEditor.primitiveProperties.setMaxLength(itemKey, property.name, props.maxLength);\r\n }\r\n if (props.minValue !== undefined) {\r\n await classEditor.primitiveProperties.setMinValue(itemKey, property.name, props.minValue);\r\n }\r\n if (props.maxValue !== undefined) {\r\n await classEditor.primitiveProperties.setMaxValue(itemKey, property.name, props.maxValue);\r\n }\r\n return {};\r\n },\r\n};\r\n\r\nconst structProperty: PropertyMerger<StructPropertyProps> = {\r\n is(property): property is StructPropertyProps {\r\n return property.type === \"StructProperty\" || property.type === \"StructArrayProperty\";\r\n },\r\n async add(context, itemKey, property): Promise<SchemaEditResults> {\r\n const structKey = await updateSchemaItemKey(context, property.typeName);\r\n const structType = await context.editor.schemaContext.getSchemaItem<StructClass>(structKey);\r\n if (structType === undefined) {\r\n return { errorMessage: `Unable to locate the struct ${structKey.name} in the context schema.` };\r\n }\r\n\r\n property.typeName = structKey.fullName;\r\n\r\n const classEditor = await getClassEditor(context, itemKey);\r\n return arrayProperty.is(property)\r\n ? classEditor.createStructArrayPropertyFromProps(itemKey, property.name, structType, property)\r\n : classEditor.createStructPropertyFromProps(itemKey, property.name, structType, property);\r\n },\r\n async merge(_context, _itemKey, property, props) {\r\n if (\"structClass\" in props && props.structClass !== undefined) {\r\n return { errorMessage: `Changing the property '${property.fullName}' structClass is not supported.` };\r\n }\r\n return {};\r\n },\r\n};\r\n"]}
@@ -13,7 +13,8 @@ export * from "./Editing/Editor";
13
13
  export { ISuppressionRule, IRuleSuppressionSet, IRuleSuppressionMap } from "./Validation/RuleSuppressionSet";
14
14
  export { SchemaValidater } from "./Validation/SchemaValidater";
15
15
  export { SchemaMerger } from "./Merging/SchemaMerger";
16
- export { SchemaDifference } from "./Differencing/SchemaDifference";
16
+ export * from "./Differencing/SchemaDifference";
17
+ export * from "./Differencing/SchemaConflicts";
17
18
  /** @docs-package-description
18
19
  * The ecschema-editing package contains classes for validating, and editing ECSchemas that can be used in both [frontend]($docs/learning/frontend/index.md) and [backend]($docs/learning/backend/index.md).
19
20
  */
@@ -1 +1 @@
1
- {"version":3,"file":"ecschema-editing.d.ts","sourceRoot":"","sources":["../../src/ecschema-editing.ts"],"names":[],"mappings":"AAKA,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC/E,cAAc,wCAAwC,CAAC;AACvD,cAAc,oBAAoB,CAAC;AACnC,cAAc,sCAAsC,CAAC;AACrD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uCAAuC,CAAC;AACtD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oCAAoC,CAAC;AACnD,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC7G,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEnE;;GAEG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG"}
1
+ {"version":3,"file":"ecschema-editing.d.ts","sourceRoot":"","sources":["../../src/ecschema-editing.ts"],"names":[],"mappings":"AAKA,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC/E,cAAc,wCAAwC,CAAC;AACvD,cAAc,oBAAoB,CAAC;AACnC,cAAc,sCAAsC,CAAC;AACrD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uCAAuC,CAAC;AACtD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oCAAoC,CAAC;AACnD,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC7G,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAE/C;;GAEG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG"}
@@ -18,7 +18,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
18
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.SchemaDifference = exports.SchemaMerger = exports.SchemaValidater = exports.ECRuleSet = exports.Diagnostics = exports.DiagnosticCodes = void 0;
21
+ exports.SchemaMerger = exports.SchemaValidater = exports.ECRuleSet = exports.Diagnostics = exports.DiagnosticCodes = void 0;
22
22
  __exportStar(require("./Validation/Diagnostic"), exports);
23
23
  __exportStar(require("./Validation/DiagnosticReporter"), exports);
24
24
  /* eslint-disable-next-line deprecation/deprecation */
@@ -39,8 +39,8 @@ var SchemaValidater_1 = require("./Validation/SchemaValidater");
39
39
  Object.defineProperty(exports, "SchemaValidater", { enumerable: true, get: function () { return SchemaValidater_1.SchemaValidater; } });
40
40
  var SchemaMerger_1 = require("./Merging/SchemaMerger");
41
41
  Object.defineProperty(exports, "SchemaMerger", { enumerable: true, get: function () { return SchemaMerger_1.SchemaMerger; } });
42
- var SchemaDifference_1 = require("./Differencing/SchemaDifference");
43
- Object.defineProperty(exports, "SchemaDifference", { enumerable: true, get: function () { return SchemaDifference_1.SchemaDifference; } });
42
+ __exportStar(require("./Differencing/SchemaDifference"), exports);
43
+ __exportStar(require("./Differencing/SchemaConflicts"), exports);
44
44
  /** @docs-package-description
45
45
  * The ecschema-editing package contains classes for validating, and editing ECSchemas that can be used in both [frontend]($docs/learning/frontend/index.md) and [backend]($docs/learning/backend/index.md).
46
46
  */
@@ -1 +1 @@
1
- {"version":3,"file":"ecschema-editing.js","sourceRoot":"","sources":["../../src/ecschema-editing.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;;;;;AAE/F,0DAAwC;AACxC,kEAAgD;AAChD,sDAAsD;AACtD,gDAA+E;AAAtE,0GAAA,eAAe,OAAA;AAAE,sGAAA,WAAW,OAAA;AAAE,oGAAA,SAAS,OAAA;AAChD,yEAAuD;AACvD,qDAAmC;AACnC,uEAAqD;AACrD,4DAA0C;AAC1C,wEAAsD;AACtD,6DAA2C;AAC3C,8DAA4C;AAC5C,qEAAmD;AACnD,mDAAiC;AAEjC,gEAA+D;AAAtD,kHAAA,eAAe,OAAA;AACxB,uDAAsD;AAA7C,4GAAA,YAAY,OAAA;AACrB,oEAAmE;AAA1D,oHAAA,gBAAgB,OAAA;AAEzB;;GAEG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nexport * from \"./Validation/Diagnostic\";\r\nexport * from \"./Validation/DiagnosticReporter\";\r\n/* eslint-disable-next-line deprecation/deprecation */\r\nexport { DiagnosticCodes, Diagnostics, ECRuleSet } from \"./Validation/ECRules\";\r\nexport * from \"./Validation/LoggingDiagnosticReporter\";\r\nexport * from \"./Validation/Rules\";\r\nexport * from \"./Validation/SchemaValidationVisitor\";\r\nexport * from \"./Validation/SchemaWalker\";\r\nexport * from \"./Validation/SchemaCompareDiagnostics\";\r\nexport * from \"./Validation/SchemaChanges\";\r\nexport * from \"./Validation/SchemaComparer\";\r\nexport * from \"./Validation/SchemaCompareReporter\";\r\nexport * from \"./Editing/Editor\";\r\nexport { ISuppressionRule, IRuleSuppressionSet, IRuleSuppressionMap } from \"./Validation/RuleSuppressionSet\";\r\nexport { SchemaValidater } from \"./Validation/SchemaValidater\";\r\nexport { SchemaMerger } from \"./Merging/SchemaMerger\";\r\nexport { SchemaDifference } from \"./Differencing/SchemaDifference\";\r\n\r\n/** @docs-package-description\r\n * The ecschema-editing package contains classes for validating, and editing ECSchemas that can be used in both [frontend]($docs/learning/frontend/index.md) and [backend]($docs/learning/backend/index.md).\r\n */\r\n/**\r\n * @docs-group-description Editing\r\n * Set of classes used to perform editing of ECSchemas.\r\n */\r\n/**\r\n * @docs-group-description Diagnostic\r\n * Set of classes to categorize and manage ECSchema validation results.\r\n */\r\n/**\r\n * @docs-group-description Validation\r\n * Set of classes used to perform validation on ECSchemas.\r\n */\r\n/**\r\n * @docs-group-description Comparison\r\n * Set of classes to enable comparison of ECSchemas.\r\n */\r\n/**\r\n * @docs-group-description Merging\r\n * Set of classes used to merge schemas.\r\n */\r\n/**\r\n * @docs-group-description Differencing\r\n * Set of classes used to perform differences between ECSchemas.\r\n */\r\n"]}
1
+ {"version":3,"file":"ecschema-editing.js","sourceRoot":"","sources":["../../src/ecschema-editing.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;;;;;AAE/F,0DAAwC;AACxC,kEAAgD;AAChD,sDAAsD;AACtD,gDAA+E;AAAtE,0GAAA,eAAe,OAAA;AAAE,sGAAA,WAAW,OAAA;AAAE,oGAAA,SAAS,OAAA;AAChD,yEAAuD;AACvD,qDAAmC;AACnC,uEAAqD;AACrD,4DAA0C;AAC1C,wEAAsD;AACtD,6DAA2C;AAC3C,8DAA4C;AAC5C,qEAAmD;AACnD,mDAAiC;AAEjC,gEAA+D;AAAtD,kHAAA,eAAe,OAAA;AACxB,uDAAsD;AAA7C,4GAAA,YAAY,OAAA;AACrB,kEAAgD;AAChD,iEAA+C;AAE/C;;GAEG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nexport * from \"./Validation/Diagnostic\";\r\nexport * from \"./Validation/DiagnosticReporter\";\r\n/* eslint-disable-next-line deprecation/deprecation */\r\nexport { DiagnosticCodes, Diagnostics, ECRuleSet } from \"./Validation/ECRules\";\r\nexport * from \"./Validation/LoggingDiagnosticReporter\";\r\nexport * from \"./Validation/Rules\";\r\nexport * from \"./Validation/SchemaValidationVisitor\";\r\nexport * from \"./Validation/SchemaWalker\";\r\nexport * from \"./Validation/SchemaCompareDiagnostics\";\r\nexport * from \"./Validation/SchemaChanges\";\r\nexport * from \"./Validation/SchemaComparer\";\r\nexport * from \"./Validation/SchemaCompareReporter\";\r\nexport * from \"./Editing/Editor\";\r\nexport { ISuppressionRule, IRuleSuppressionSet, IRuleSuppressionMap } from \"./Validation/RuleSuppressionSet\";\r\nexport { SchemaValidater } from \"./Validation/SchemaValidater\";\r\nexport { SchemaMerger } from \"./Merging/SchemaMerger\";\r\nexport * from \"./Differencing/SchemaDifference\";\r\nexport * from \"./Differencing/SchemaConflicts\";\r\n\r\n/** @docs-package-description\r\n * The ecschema-editing package contains classes for validating, and editing ECSchemas that can be used in both [frontend]($docs/learning/frontend/index.md) and [backend]($docs/learning/backend/index.md).\r\n */\r\n/**\r\n * @docs-group-description Editing\r\n * Set of classes used to perform editing of ECSchemas.\r\n */\r\n/**\r\n * @docs-group-description Diagnostic\r\n * Set of classes to categorize and manage ECSchema validation results.\r\n */\r\n/**\r\n * @docs-group-description Validation\r\n * Set of classes used to perform validation on ECSchemas.\r\n */\r\n/**\r\n * @docs-group-description Comparison\r\n * Set of classes to enable comparison of ECSchemas.\r\n */\r\n/**\r\n * @docs-group-description Merging\r\n * Set of classes used to merge schemas.\r\n */\r\n/**\r\n * @docs-group-description Differencing\r\n * Set of classes used to perform differences between ECSchemas.\r\n */\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/ecschema-editing",
3
- "version": "4.6.0-dev.18",
3
+ "version": "4.6.0-dev.21",
4
4
  "description": "ECSchema editing and validation API",
5
5
  "license": "MIT",
6
6
  "main": "lib/cjs/ecschema-editing.js",
@@ -42,16 +42,16 @@
42
42
  "rimraf": "^3.0.2",
43
43
  "sinon": "^17.0.1",
44
44
  "typescript": "~5.0.2",
45
- "@itwin/build-tools": "4.6.0-dev.18",
46
- "@itwin/ecschema-metadata": "4.6.0-dev.18",
47
- "@itwin/core-common": "4.6.0-dev.18",
48
- "@itwin/core-quantity": "4.6.0-dev.18",
49
- "@itwin/core-bentley": "4.6.0-dev.18"
45
+ "@itwin/core-common": "4.6.0-dev.21",
46
+ "@itwin/build-tools": "4.6.0-dev.21",
47
+ "@itwin/ecschema-metadata": "4.6.0-dev.21",
48
+ "@itwin/core-bentley": "4.6.0-dev.21",
49
+ "@itwin/core-quantity": "4.6.0-dev.21"
50
50
  },
51
51
  "peerDependencies": {
52
- "@itwin/core-bentley": "^4.6.0-dev.18",
53
- "@itwin/core-quantity": "^4.6.0-dev.18",
54
- "@itwin/ecschema-metadata": "^4.6.0-dev.18"
52
+ "@itwin/core-bentley": "^4.6.0-dev.21",
53
+ "@itwin/core-quantity": "^4.6.0-dev.21",
54
+ "@itwin/ecschema-metadata": "^4.6.0-dev.21"
55
55
  },
56
56
  "nyc": {
57
57
  "extends": "./node_modules/@itwin/build-tools/.nycrc"