@itwin/ecschema-editing 4.4.0-dev.4 → 4.4.0-dev.6

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/CHANGELOG.md +6 -1
  2. package/lib/cjs/Editing/ECClasses.d.ts +2 -0
  3. package/lib/cjs/Editing/ECClasses.d.ts.map +1 -1
  4. package/lib/cjs/Editing/ECClasses.js +23 -0
  5. package/lib/cjs/Editing/ECClasses.js.map +1 -1
  6. package/lib/cjs/Editing/Mutable/MutableArrayProperty.d.ts +10 -0
  7. package/lib/cjs/Editing/Mutable/MutableArrayProperty.d.ts.map +1 -0
  8. package/lib/cjs/Editing/Mutable/MutableArrayProperty.js +16 -0
  9. package/lib/cjs/Editing/Mutable/MutableArrayProperty.js.map +1 -0
  10. package/lib/cjs/Editing/Mutable/MutablePrimitiveOrEnumProperty.d.ts +13 -0
  11. package/lib/cjs/Editing/Mutable/MutablePrimitiveOrEnumProperty.d.ts.map +1 -0
  12. package/lib/cjs/Editing/Mutable/MutablePrimitiveOrEnumProperty.js +16 -0
  13. package/lib/cjs/Editing/Mutable/MutablePrimitiveOrEnumProperty.js.map +1 -0
  14. package/lib/cjs/Editing/Mutable/MutableProperty.d.ts +6 -1
  15. package/lib/cjs/Editing/Mutable/MutableProperty.d.ts.map +1 -1
  16. package/lib/cjs/Editing/Mutable/MutableProperty.js.map +1 -1
  17. package/lib/cjs/Merging/AnyPropertyMerger.d.ts +15 -0
  18. package/lib/cjs/Merging/AnyPropertyMerger.d.ts.map +1 -0
  19. package/lib/cjs/Merging/AnyPropertyMerger.js +71 -0
  20. package/lib/cjs/Merging/AnyPropertyMerger.js.map +1 -0
  21. package/lib/cjs/Merging/ArrayPropertyMerger.d.ts +32 -0
  22. package/lib/cjs/Merging/ArrayPropertyMerger.d.ts.map +1 -0
  23. package/lib/cjs/Merging/ArrayPropertyMerger.js +143 -0
  24. package/lib/cjs/Merging/ArrayPropertyMerger.js.map +1 -0
  25. package/lib/cjs/Merging/ClassMerger.d.ts.map +1 -1
  26. package/lib/cjs/Merging/ClassMerger.js +5 -0
  27. package/lib/cjs/Merging/ClassMerger.js.map +1 -1
  28. package/lib/cjs/Merging/ClassPropertyMerger.d.ts +16 -0
  29. package/lib/cjs/Merging/ClassPropertyMerger.d.ts.map +1 -0
  30. package/lib/cjs/Merging/ClassPropertyMerger.js +83 -0
  31. package/lib/cjs/Merging/ClassPropertyMerger.js.map +1 -0
  32. package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.d.ts +24 -0
  33. package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.d.ts.map +1 -0
  34. package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.js +106 -0
  35. package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.js.map +1 -0
  36. package/lib/cjs/Merging/StructPropertyMerger.d.ts +11 -0
  37. package/lib/cjs/Merging/StructPropertyMerger.d.ts.map +1 -0
  38. package/lib/cjs/Merging/StructPropertyMerger.js +47 -0
  39. package/lib/cjs/Merging/StructPropertyMerger.js.map +1 -0
  40. package/package.json +15 -15
package/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Change Log - @itwin/ecschema-editing
2
2
 
3
- This log was last generated on Fri, 08 Dec 2023 15:26:18 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 13 Dec 2023 17:26:56 GMT and should not be manually modified.
4
+
5
+ ## 4.3.1
6
+ Wed, 13 Dec 2023 17:25:55 GMT
7
+
8
+ _Version update only_
4
9
 
5
10
  ## 4.3.0
6
11
  Thu, 07 Dec 2023 17:43:09 GMT
@@ -30,6 +30,8 @@ export declare class ECClasses {
30
30
  createEnumerationPropertyFromProps(classKey: SchemaItemKey, name: string, type: Enumeration, enumProps: EnumerationPropertyProps): Promise<PropertyEditResults>;
31
31
  createPrimitiveArrayProperty(classKey: SchemaItemKey, name: string, type: PrimitiveType): Promise<PropertyEditResults>;
32
32
  createPrimitiveArrayPropertyFromProps(classKey: SchemaItemKey, name: string, type: PrimitiveType, primitiveProps: PrimitiveArrayPropertyProps): Promise<PropertyEditResults>;
33
+ createEnumerationArrayProperty(classKey: SchemaItemKey, name: string, type: Enumeration): Promise<PropertyEditResults>;
34
+ createEnumerationArrayPropertyFromProps(classKey: SchemaItemKey, name: string, type: Enumeration, props: PrimitiveArrayPropertyProps): Promise<PropertyEditResults>;
33
35
  createStructProperty(classKey: SchemaItemKey, name: string, type: StructClass): Promise<PropertyEditResults>;
34
36
  createStructPropertyFromProps(classKey: SchemaItemKey, name: string, type: StructClass, structProps: StructPropertyProps): Promise<PropertyEditResults>;
35
37
  createStructArrayProperty(classKey: SchemaItemKey, name: string, type: StructClass): Promise<PropertyEditResults>;
@@ -1 +1 @@
1
- {"version":3,"file":"ECClasses.d.ts","sourceRoot":"","sources":["../../../src/Editing/ECClasses.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EACL,eAAe,EAEmC,WAAW,EAAE,wBAAwB,EAAE,2BAA2B,EACpH,sBAAsB,EAAE,aAAa,EAAE,aAAa,EAAkB,wBAAwB,EAC9F,WAAW,EAAE,mBAAmB,EACjC,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAK3F;;;GAGG;AACH,qBAAa,SAAS;IAEE,SAAS,CAAC,aAAa,EAAE,mBAAmB;IAAlE,SAAS,aAAuB,aAAa,EAAE,mBAAmB;IAElE;;;;;;OAMG;IACU,cAAc,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAsBrI;;;;;OAKG;IACU,uBAAuB,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,mBAAmB,CAAC;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YAMf,kBAAkB;CAejC"}
@@ -121,6 +121,29 @@ class ECClasses {
121
121
  await newProperty.fromJSON(primitiveProps);
122
122
  return { itemKey: classKey, propertyName: name };
123
123
  }
124
+ async createEnumerationArrayProperty(classKey, name, type) {
125
+ let mutableClass;
126
+ try {
127
+ mutableClass = await this.getClass(classKey);
128
+ }
129
+ catch (e) {
130
+ return { errorMessage: e.message };
131
+ }
132
+ await mutableClass.createPrimitiveArrayProperty(name, type);
133
+ return { itemKey: classKey, propertyName: name };
134
+ }
135
+ async createEnumerationArrayPropertyFromProps(classKey, name, type, props) {
136
+ let mutableClass;
137
+ try {
138
+ mutableClass = await this.getClass(classKey);
139
+ }
140
+ catch (e) {
141
+ return { errorMessage: e.message };
142
+ }
143
+ const newProperty = await mutableClass.createPrimitiveArrayProperty(name, type);
144
+ await newProperty.fromJSON(props);
145
+ return { itemKey: classKey, propertyName: name };
146
+ }
124
147
  async createStructProperty(classKey, name, type) {
125
148
  let mutableClass;
126
149
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"ECClasses.js","sourceRoot":"","sources":["../../../src/Editing/ECClasses.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAMkC;AAClC,sDAA6C;AAG7C,+CAA+C;AAG/C;;;GAGG;AACH,MAAa,SAAS;IAEpB,YAAgC,aAAkC;QAAlC,kBAAa,GAAb,aAAa,CAAqB;IAAI,CAAC;IAEvE;;;;;;OAMG;IACI,KAAK,CAAC,cAAc,CAAC,QAAuB,EAAE,IAAY,EAAE,IAAmB,EAAE,MAAc;QACpG,IAAI,YAA0B,CAAC;QAE/B,IAAI,IAAI,KAAK,iCAAa,CAAC,MAAM,IAAI,IAAI,KAAK,iCAAa,CAAC,MAAM,IAAI,IAAI,KAAK,iCAAa,CAAC,QAAQ;eAChG,IAAI,KAAK,iCAAa,CAAC,OAAO;YACjC,MAAM,IAAI,KAAK,CAAE,gFAAgF,CAAC,CAAC;QAErG,IAAI,EAAE,KAA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,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC;QACjD,MAAM,GAAG,GAAG,SAAS,CAAC,gBAAgD,CAAC;QACvE,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;IAEO,KAAK,CAAC,kBAAkB,CAAC,YAA0B;QACzD,MAAM,cAAc,GAAwB,EAAE,CAAC;QAC/C,MAAM,WAAW,GAAG,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,cAAc,EAAE,CAAC;QACtE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC;QACzC,OAAO,CAAC,IAAI,EAAE;YACZ,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,EAAE;gBAChC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;oBACxC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBAC5B;aACF;YACD,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;SACxC;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;CACF;AAvXD,8BAuXC","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,\r\n CustomAttributeContainerProps,\r\n ECClass, ECName, ECObjectsError, ECObjectsStatus, Enumeration, EnumerationPropertyProps, PrimitiveArrayPropertyProps,\r\n PrimitivePropertyProps, PrimitiveType, SchemaItemKey, SchemaItemType, StructArrayPropertyProps,\r\n StructClass, StructPropertyProps,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { assert } from \"@itwin/core-bentley\";\r\nimport { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\r\nimport { MutableClass } from \"./Mutable/MutableClass\";\r\nimport * as Rules from \"../Validation/ECRules\";\r\nimport { MutableProperty } from \"./Mutable/MutableProperty\";\r\n\r\n/**\r\n * @alpha\r\n * Acts as a base class for schema class creation. Enables property creation.\r\n */\r\nexport class ECClasses {\r\n\r\n protected constructor(protected _schemaEditor: SchemaContextEditor) { }\r\n\r\n /**\r\n * Creates a property on class identified by the given SchemaItemKey. This method restricts the\r\n * property type to primitives of type Double, String, DateTime and Integer.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param name The name of the new property.\r\n * @param type The PrimitiveType assigned to the new property.\r\n */\r\n public async createProperty(classKey: SchemaItemKey, name: string, type: PrimitiveType, prefix: string): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n\r\n if (type !== PrimitiveType.Double && type !== PrimitiveType.String && type !== PrimitiveType.DateTime\r\n && type !== PrimitiveType.Integer)\r\n throw new Error (\"Property creation is restricted to type Double, String, DateTime, and Integer.\");\r\n\r\n if (\"\" === prefix)\r\n throw new Error(\"The specified property name prefix is invalid\");\r\n\r\n const prefixedName = `${prefix}_${name}`;\r\n\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n await mutableClass.createPrimitiveProperty(prefixedName, type);\r\n return { itemKey: classKey, propertyName: prefixedName };\r\n }\r\n\r\n /**\r\n * Create a primitive property on class identified by the given SchemaItemKey.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param name The name of the new property.\r\n * @param type The PrimitiveType assigned to the new property.\r\n */\r\n public async createPrimitiveProperty(classKey: SchemaItemKey, name: string, type: PrimitiveType): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n await mutableClass.createPrimitiveProperty(name, type);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createPrimitivePropertyFromProps(classKey: SchemaItemKey, name: string, type: PrimitiveType, primitiveProps: PrimitivePropertyProps): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const newProperty = await mutableClass.createPrimitiveProperty(name, type);\r\n await newProperty.fromJSON(primitiveProps);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createEnumerationProperty(classKey: SchemaItemKey, name: string, type: Enumeration): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const enumSchemaItemKey = mutableClass.schema.getSchemaItemKey(type.fullName);\r\n if (enumSchemaItemKey === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the enumeration ${type.fullName}.`);\r\n\r\n await mutableClass.createPrimitiveProperty(name, type);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createEnumerationPropertyFromProps(classKey: SchemaItemKey, name: string, type: Enumeration, enumProps: EnumerationPropertyProps): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const newProperty = await mutableClass.createPrimitiveProperty(name, type);\r\n await newProperty.fromJSON(enumProps);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createPrimitiveArrayProperty(classKey: SchemaItemKey, name: string, type: PrimitiveType): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n await mutableClass.createPrimitiveArrayProperty(name, type);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createPrimitiveArrayPropertyFromProps(classKey: SchemaItemKey, name: string, type: PrimitiveType, primitiveProps: PrimitiveArrayPropertyProps): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const newProperty = await mutableClass.createPrimitiveArrayProperty(name, type);\r\n await newProperty.fromJSON(primitiveProps);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createStructProperty(classKey: SchemaItemKey, name: string, type: StructClass): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n await mutableClass.createStructProperty(name, type);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createStructPropertyFromProps(classKey: SchemaItemKey, name: string, type: StructClass, structProps: StructPropertyProps): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const newProperty = await mutableClass.createStructProperty(name, type);\r\n await newProperty.fromJSON(structProps);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createStructArrayProperty(classKey: SchemaItemKey, name: string, type: StructClass): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n await mutableClass.createStructArrayProperty(name, type);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createStructArrayPropertyFromProps(classKey: SchemaItemKey, name: string, type: StructClass, structProps: StructArrayPropertyProps): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const newProperty = await mutableClass.createStructArrayProperty(name, type);\r\n await newProperty.fromJSON(structProps);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async deleteProperty(classKey: SchemaItemKey, name: string): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n await mutableClass.deleteProperty(name);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async delete(classKey: SchemaItemKey): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(classKey.schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${classKey.schemaKey.toString(true)} not found in context` };\r\n\r\n const ecClass = await schema.getItem<ECClass>(classKey.name);\r\n if (ecClass === undefined)\r\n return {};\r\n\r\n await schema.deleteClass(ecClass.name);\r\n\r\n return { itemKey: classKey };\r\n }\r\n\r\n /**\r\n * Adds a CustomAttribute instance to the Class identified by the given SchemaItemKey\r\n * @param classKey The SchemaItemKey identifying the schema.\r\n * @param customAttribute The CustomAttribute instance to add.\r\n */\r\n public async addCustomAttribute(classKey: SchemaItemKey, customAttribute: CustomAttribute): Promise<SchemaItemEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n mutableClass.addCustomAttribute(customAttribute);\r\n\r\n const diagnostics = Rules.validateCustomAttributeInstance(mutableClass, customAttribute);\r\n\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(mutableClass, customAttribute);\r\n return result;\r\n }\r\n\r\n return {};\r\n }\r\n\r\n /**\r\n * Adds a CustomAttribute instance to the Property identified by the given SchemaItemKey and property name.\r\n * @param classKey The SchemaItemKey identifying the class.\r\n * @param propertyName The name of the property.\r\n * @param customAttribute The CustomAttribute instance to add.\r\n */\r\n public async addCustomAttributeToProperty(classKey: SchemaItemKey, propertyName: string, customAttribute: CustomAttribute): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const property = await mutableClass.getProperty(propertyName) as MutableProperty;\r\n if (!property) {\r\n return { errorMessage: `Property with the name ${propertyName} could not be found in the class ${classKey.fullName}.` };\r\n }\r\n\r\n property.addCustomAttribute(customAttribute);\r\n\r\n const diagnostics = Rules.validateCustomAttributeInstance(property, customAttribute);\r\n\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(property, customAttribute);\r\n return result;\r\n }\r\n\r\n return {};\r\n }\r\n\r\n /**\r\n * Renames the property on the specified class. The rename will fail if the new\r\n * name causes a conflict with a base or derived property. All derived classes\r\n * containing a property override will be renamed, as well.\r\n * @param classKey The SchemaItemKey identifying the class.\r\n * @param existingPropertyName The name of the property.\r\n * @param newPropertyName The new property name.\r\n */\r\n public async setPropertyName(classKey: SchemaItemKey, existingPropertyName: string, newPropertyName: string): Promise<PropertyEditResults> {\r\n const newName = new ECName(newPropertyName);\r\n\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const existingProperty = await mutableClass.getProperty(existingPropertyName) as MutableProperty;\r\n if (!existingProperty) {\r\n return { errorMessage: `An ECProperty with the name ${existingPropertyName} could not be found in the class ${classKey.fullName}.` };\r\n }\r\n\r\n const baseProperty = await mutableClass.getProperty(newPropertyName, true) as MutableProperty;\r\n if (baseProperty)\r\n return { errorMessage: `An ECProperty with the name ${newPropertyName} already exists in the class ${baseProperty.class.name}.` };\r\n\r\n // Handle derived classes\r\n const derivedProperties: Array<MutableProperty> = [];\r\n const derivedClasses = await this.findDerivedClasses(mutableClass);\r\n for (const derivedClass of derivedClasses) {\r\n if (await derivedClass.getProperty(newPropertyName))\r\n return { errorMessage: `An ECProperty with the name ${newPropertyName} already exists in the class ${derivedClass.fullName}.` };\r\n\r\n const propertyOverride = await derivedClass.getProperty(existingPropertyName) as MutableProperty;\r\n // If found the property is overridden in the derived class.\r\n if (propertyOverride)\r\n derivedProperties.push(propertyOverride);\r\n }\r\n\r\n // Re-name the overridden property in all derived classes\r\n derivedProperties.forEach((prop: MutableProperty) => {\r\n prop.setName(newName);\r\n });\r\n\r\n existingProperty.setName(newName);\r\n\r\n return { itemKey: classKey, propertyName: newName.name };\r\n }\r\n\r\n /**\r\n * Sets the name of the ECClass.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param name The new name of the class.\r\n * @throws ECObjectsError if `name` does not meet the criteria for a valid EC name\r\n */\r\n public async setName(classKey: SchemaItemKey, name: string): Promise<SchemaItemEditResults> {\r\n let mutableClass: MutableClass;\r\n\r\n const schema = await this._schemaEditor.getSchema(classKey.schemaKey);\r\n const ecClass = await schema.getItem<MutableClass>(name);\r\n if (ecClass !== undefined)\r\n return { errorMessage: `An EC Class with the name ${name} already exists within the schema ${schema.name}` };\r\n\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n mutableClass.setName(name);\r\n\r\n return {};\r\n }\r\n\r\n private async getClass(classKey: SchemaItemKey): Promise<MutableClass> {\r\n const schema = await this._schemaEditor.getSchema(classKey.schemaKey);\r\n const ecClass = await schema.getItem<MutableClass>(classKey.name);\r\n if (ecClass === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Class ${classKey.name} was not found in schema ${classKey.schemaKey.toString(true)}`);\r\n\r\n switch (ecClass.schemaItemType) {\r\n case SchemaItemType.EntityClass:\r\n case SchemaItemType.Mixin:\r\n case SchemaItemType.StructClass:\r\n case SchemaItemType.CustomAttributeClass:\r\n case SchemaItemType.RelationshipClass:\r\n break;\r\n default:\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Schema item type not supported`);\r\n }\r\n\r\n return ecClass;\r\n }\r\n\r\n private removeCustomAttribute(container: CustomAttributeContainerProps, customAttribute: CustomAttribute) {\r\n assert(container.customAttributes !== undefined);\r\n const map = container.customAttributes as Map<string, CustomAttribute>;\r\n map.delete(customAttribute.className);\r\n }\r\n\r\n private async findDerivedClasses(mutableClass: MutableClass): Promise<Array<MutableClass>>{\r\n const derivedClasses: Array<MutableClass> = [];\r\n const schemaItems = this._schemaEditor.schemaContext.getSchemaItems();\r\n let { value, done } = schemaItems.next();\r\n while (!done) {\r\n if (await value.is(mutableClass)) {\r\n if (!mutableClass.key.matches(value.key)) {\r\n derivedClasses.push(value);\r\n }\r\n }\r\n ({ value, done } = schemaItems.next());\r\n }\r\n\r\n return derivedClasses;\r\n }\r\n}\r\n\r\n"]}
1
+ {"version":3,"file":"ECClasses.js","sourceRoot":"","sources":["../../../src/Editing/ECClasses.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAMkC;AAClC,sDAA6C;AAG7C,+CAA+C;AAG/C;;;GAGG;AACH,MAAa,SAAS;IAEpB,YAAgC,aAAkC;QAAlC,kBAAa,GAAb,aAAa,CAAqB;IAAI,CAAC;IAEvE;;;;;;OAMG;IACI,KAAK,CAAC,cAAc,CAAC,QAAuB,EAAE,IAAY,EAAE,IAAmB,EAAE,MAAc;QACpG,IAAI,YAA0B,CAAC;QAE/B,IAAI,IAAI,KAAK,iCAAa,CAAC,MAAM,IAAI,IAAI,KAAK,iCAAa,CAAC,MAAM,IAAI,IAAI,KAAK,iCAAa,CAAC,QAAQ;eAChG,IAAI,KAAK,iC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cAAc,GAAwB,EAAE,CAAC;QAC/C,MAAM,WAAW,GAAG,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,cAAc,EAAE,CAAC;QACtE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC;QACzC,OAAO,CAAC,IAAI,EAAE;YACZ,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,EAAE;gBAChC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;oBACxC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBAC5B;aACF;YACD,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;SACxC;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;CACF;AAhZD,8BAgZC","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,\r\n CustomAttributeContainerProps,\r\n ECClass, ECName, ECObjectsError, ECObjectsStatus, Enumeration, EnumerationPropertyProps, PrimitiveArrayPropertyProps,\r\n PrimitivePropertyProps, PrimitiveType, SchemaItemKey, SchemaItemType, StructArrayPropertyProps,\r\n StructClass, StructPropertyProps,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { assert } from \"@itwin/core-bentley\";\r\nimport { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\r\nimport { MutableClass } from \"./Mutable/MutableClass\";\r\nimport * as Rules from \"../Validation/ECRules\";\r\nimport { MutableProperty } from \"./Mutable/MutableProperty\";\r\n\r\n/**\r\n * @alpha\r\n * Acts as a base class for schema class creation. Enables property creation.\r\n */\r\nexport class ECClasses {\r\n\r\n protected constructor(protected _schemaEditor: SchemaContextEditor) { }\r\n\r\n /**\r\n * Creates a property on class identified by the given SchemaItemKey. This method restricts the\r\n * property type to primitives of type Double, String, DateTime and Integer.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param name The name of the new property.\r\n * @param type The PrimitiveType assigned to the new property.\r\n */\r\n public async createProperty(classKey: SchemaItemKey, name: string, type: PrimitiveType, prefix: string): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n\r\n if (type !== PrimitiveType.Double && type !== PrimitiveType.String && type !== PrimitiveType.DateTime\r\n && type !== PrimitiveType.Integer)\r\n throw new Error (\"Property creation is restricted to type Double, String, DateTime, and Integer.\");\r\n\r\n if (\"\" === prefix)\r\n throw new Error(\"The specified property name prefix is invalid\");\r\n\r\n const prefixedName = `${prefix}_${name}`;\r\n\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n await mutableClass.createPrimitiveProperty(prefixedName, type);\r\n return { itemKey: classKey, propertyName: prefixedName };\r\n }\r\n\r\n /**\r\n * Create a primitive property on class identified by the given SchemaItemKey.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param name The name of the new property.\r\n * @param type The PrimitiveType assigned to the new property.\r\n */\r\n public async createPrimitiveProperty(classKey: SchemaItemKey, name: string, type: PrimitiveType): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n await mutableClass.createPrimitiveProperty(name, type);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createPrimitivePropertyFromProps(classKey: SchemaItemKey, name: string, type: PrimitiveType, primitiveProps: PrimitivePropertyProps): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const newProperty = await mutableClass.createPrimitiveProperty(name, type);\r\n await newProperty.fromJSON(primitiveProps);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createEnumerationProperty(classKey: SchemaItemKey, name: string, type: Enumeration): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const enumSchemaItemKey = mutableClass.schema.getSchemaItemKey(type.fullName);\r\n if (enumSchemaItemKey === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the enumeration ${type.fullName}.`);\r\n\r\n await mutableClass.createPrimitiveProperty(name, type);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createEnumerationPropertyFromProps(classKey: SchemaItemKey, name: string, type: Enumeration, enumProps: EnumerationPropertyProps): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const newProperty = await mutableClass.createPrimitiveProperty(name, type);\r\n await newProperty.fromJSON(enumProps);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createPrimitiveArrayProperty(classKey: SchemaItemKey, name: string, type: PrimitiveType): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n await mutableClass.createPrimitiveArrayProperty(name, type);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createPrimitiveArrayPropertyFromProps(classKey: SchemaItemKey, name: string, type: PrimitiveType, primitiveProps: PrimitiveArrayPropertyProps): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const newProperty = await mutableClass.createPrimitiveArrayProperty(name, type);\r\n await newProperty.fromJSON(primitiveProps);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createEnumerationArrayProperty(classKey: SchemaItemKey, name: string, type: Enumeration): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n await mutableClass.createPrimitiveArrayProperty(name, type);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createEnumerationArrayPropertyFromProps(classKey: SchemaItemKey, name: string, type: Enumeration, props: PrimitiveArrayPropertyProps): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const newProperty = await mutableClass.createPrimitiveArrayProperty(name, type);\r\n await newProperty.fromJSON(props);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createStructProperty(classKey: SchemaItemKey, name: string, type: StructClass): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n await mutableClass.createStructProperty(name, type);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createStructPropertyFromProps(classKey: SchemaItemKey, name: string, type: StructClass, structProps: StructPropertyProps): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const newProperty = await mutableClass.createStructProperty(name, type);\r\n await newProperty.fromJSON(structProps);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createStructArrayProperty(classKey: SchemaItemKey, name: string, type: StructClass): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n await mutableClass.createStructArrayProperty(name, type);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createStructArrayPropertyFromProps(classKey: SchemaItemKey, name: string, type: StructClass, structProps: StructArrayPropertyProps): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const newProperty = await mutableClass.createStructArrayProperty(name, type);\r\n await newProperty.fromJSON(structProps);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async deleteProperty(classKey: SchemaItemKey, name: string): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n await mutableClass.deleteProperty(name);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async delete(classKey: SchemaItemKey): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(classKey.schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${classKey.schemaKey.toString(true)} not found in context` };\r\n\r\n const ecClass = await schema.getItem<ECClass>(classKey.name);\r\n if (ecClass === undefined)\r\n return {};\r\n\r\n await schema.deleteClass(ecClass.name);\r\n\r\n return { itemKey: classKey };\r\n }\r\n\r\n /**\r\n * Adds a CustomAttribute instance to the Class identified by the given SchemaItemKey\r\n * @param classKey The SchemaItemKey identifying the schema.\r\n * @param customAttribute The CustomAttribute instance to add.\r\n */\r\n public async addCustomAttribute(classKey: SchemaItemKey, customAttribute: CustomAttribute): Promise<SchemaItemEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n mutableClass.addCustomAttribute(customAttribute);\r\n\r\n const diagnostics = Rules.validateCustomAttributeInstance(mutableClass, customAttribute);\r\n\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(mutableClass, customAttribute);\r\n return result;\r\n }\r\n\r\n return {};\r\n }\r\n\r\n /**\r\n * Adds a CustomAttribute instance to the Property identified by the given SchemaItemKey and property name.\r\n * @param classKey The SchemaItemKey identifying the class.\r\n * @param propertyName The name of the property.\r\n * @param customAttribute The CustomAttribute instance to add.\r\n */\r\n public async addCustomAttributeToProperty(classKey: SchemaItemKey, propertyName: string, customAttribute: CustomAttribute): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const property = await mutableClass.getProperty(propertyName) as MutableProperty;\r\n if (!property) {\r\n return { errorMessage: `Property with the name ${propertyName} could not be found in the class ${classKey.fullName}.` };\r\n }\r\n\r\n property.addCustomAttribute(customAttribute);\r\n\r\n const diagnostics = Rules.validateCustomAttributeInstance(property, customAttribute);\r\n\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(property, customAttribute);\r\n return result;\r\n }\r\n\r\n return {};\r\n }\r\n\r\n /**\r\n * Renames the property on the specified class. The rename will fail if the new\r\n * name causes a conflict with a base or derived property. All derived classes\r\n * containing a property override will be renamed, as well.\r\n * @param classKey The SchemaItemKey identifying the class.\r\n * @param existingPropertyName The name of the property.\r\n * @param newPropertyName The new property name.\r\n */\r\n public async setPropertyName(classKey: SchemaItemKey, existingPropertyName: string, newPropertyName: string): Promise<PropertyEditResults> {\r\n const newName = new ECName(newPropertyName);\r\n\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const existingProperty = await mutableClass.getProperty(existingPropertyName) as MutableProperty;\r\n if (!existingProperty) {\r\n return { errorMessage: `An ECProperty with the name ${existingPropertyName} could not be found in the class ${classKey.fullName}.` };\r\n }\r\n\r\n const baseProperty = await mutableClass.getProperty(newPropertyName, true) as MutableProperty;\r\n if (baseProperty)\r\n return { errorMessage: `An ECProperty with the name ${newPropertyName} already exists in the class ${baseProperty.class.name}.` };\r\n\r\n // Handle derived classes\r\n const derivedProperties: Array<MutableProperty> = [];\r\n const derivedClasses = await this.findDerivedClasses(mutableClass);\r\n for (const derivedClass of derivedClasses) {\r\n if (await derivedClass.getProperty(newPropertyName))\r\n return { errorMessage: `An ECProperty with the name ${newPropertyName} already exists in the class ${derivedClass.fullName}.` };\r\n\r\n const propertyOverride = await derivedClass.getProperty(existingPropertyName) as MutableProperty;\r\n // If found the property is overridden in the derived class.\r\n if (propertyOverride)\r\n derivedProperties.push(propertyOverride);\r\n }\r\n\r\n // Re-name the overridden property in all derived classes\r\n derivedProperties.forEach((prop: MutableProperty) => {\r\n prop.setName(newName);\r\n });\r\n\r\n existingProperty.setName(newName);\r\n\r\n return { itemKey: classKey, propertyName: newName.name };\r\n }\r\n\r\n /**\r\n * Sets the name of the ECClass.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param name The new name of the class.\r\n * @throws ECObjectsError if `name` does not meet the criteria for a valid EC name\r\n */\r\n public async setName(classKey: SchemaItemKey, name: string): Promise<SchemaItemEditResults> {\r\n let mutableClass: MutableClass;\r\n\r\n const schema = await this._schemaEditor.getSchema(classKey.schemaKey);\r\n const ecClass = await schema.getItem<MutableClass>(name);\r\n if (ecClass !== undefined)\r\n return { errorMessage: `An EC Class with the name ${name} already exists within the schema ${schema.name}` };\r\n\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n mutableClass.setName(name);\r\n\r\n return {};\r\n }\r\n\r\n private async getClass(classKey: SchemaItemKey): Promise<MutableClass> {\r\n const schema = await this._schemaEditor.getSchema(classKey.schemaKey);\r\n const ecClass = await schema.getItem<MutableClass>(classKey.name);\r\n if (ecClass === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Class ${classKey.name} was not found in schema ${classKey.schemaKey.toString(true)}`);\r\n\r\n switch (ecClass.schemaItemType) {\r\n case SchemaItemType.EntityClass:\r\n case SchemaItemType.Mixin:\r\n case SchemaItemType.StructClass:\r\n case SchemaItemType.CustomAttributeClass:\r\n case SchemaItemType.RelationshipClass:\r\n break;\r\n default:\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Schema item type not supported`);\r\n }\r\n\r\n return ecClass;\r\n }\r\n\r\n private removeCustomAttribute(container: CustomAttributeContainerProps, customAttribute: CustomAttribute) {\r\n assert(container.customAttributes !== undefined);\r\n const map = container.customAttributes as Map<string, CustomAttribute>;\r\n map.delete(customAttribute.className);\r\n }\r\n\r\n private async findDerivedClasses(mutableClass: MutableClass): Promise<Array<MutableClass>>{\r\n const derivedClasses: Array<MutableClass> = [];\r\n const schemaItems = this._schemaEditor.schemaContext.getSchemaItems();\r\n let { value, done } = schemaItems.next();\r\n while (!done) {\r\n if (await value.is(mutableClass)) {\r\n if (!mutableClass.key.matches(value.key)) {\r\n derivedClasses.push(value);\r\n }\r\n }\r\n ({ value, done } = schemaItems.next());\r\n }\r\n\r\n return derivedClasses;\r\n }\r\n}\r\n\r\n"]}
@@ -0,0 +1,10 @@
1
+ import { ArrayProperty } from "@itwin/ecschema-metadata";
2
+ /**
3
+ * @internal
4
+ * An abstract class used for schema editing.
5
+ */
6
+ export declare abstract class MutableArrayProperty extends ArrayProperty {
7
+ abstract setMinOccurs(minOccurs: number): void;
8
+ abstract setMaxOccurs(maxOccurs: number): void;
9
+ }
10
+ //# sourceMappingURL=MutableArrayProperty.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MutableArrayProperty.d.ts","sourceRoot":"","sources":["../../../../src/Editing/Mutable/MutableArrayProperty.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD;;;GAGG;AACH,8BAAsB,oBAAqB,SAAQ,aAAa;aACrC,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;aACrC,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;CAC/D"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MutableArrayProperty = void 0;
4
+ /*---------------------------------------------------------------------------------------------
5
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
+ * See LICENSE.md in the project root for license terms and full copyright notice.
7
+ *--------------------------------------------------------------------------------------------*/
8
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
9
+ /**
10
+ * @internal
11
+ * An abstract class used for schema editing.
12
+ */
13
+ class MutableArrayProperty extends ecschema_metadata_1.ArrayProperty {
14
+ }
15
+ exports.MutableArrayProperty = MutableArrayProperty;
16
+ //# sourceMappingURL=MutableArrayProperty.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MutableArrayProperty.js","sourceRoot":"","sources":["../../../../src/Editing/Mutable/MutableArrayProperty.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAyD;AAEzD;;;GAGG;AACH,MAAsB,oBAAqB,SAAQ,iCAAa;CAG/D;AAHD,oDAGC","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 { ArrayProperty } from \"@itwin/ecschema-metadata\";\r\n\r\n/**\r\n * @internal\r\n * An abstract class used for schema editing.\r\n */\r\nexport abstract class MutableArrayProperty extends ArrayProperty {\r\n public abstract override setMinOccurs(minOccurs: number): void;\r\n public abstract override setMaxOccurs(maxOccurs: number): void;\r\n}\r\n"]}
@@ -0,0 +1,13 @@
1
+ import { PrimitiveOrEnumPropertyBase } from "@itwin/ecschema-metadata";
2
+ /**
3
+ * @internal
4
+ * An abstract class used for schema editing.
5
+ */
6
+ export declare abstract class MutablePrimitiveOrEnumPropertyBase extends PrimitiveOrEnumPropertyBase {
7
+ abstract setExtendedTypeName(extendedTypeName: string): void;
8
+ abstract setMinLength(minLength: number): void;
9
+ abstract setMaxLength(maxLength: number): void;
10
+ abstract setMinValue(minValue: number): void;
11
+ abstract setMaxValue(maxValue: number): void;
12
+ }
13
+ //# sourceMappingURL=MutablePrimitiveOrEnumProperty.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MutablePrimitiveOrEnumProperty.d.ts","sourceRoot":"","sources":["../../../../src/Editing/Mutable/MutablePrimitiveOrEnumProperty.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAEvE;;;GAGG;AACH,8BAAsB,kCAAmC,SAAQ,2BAA2B;aACjE,mBAAmB,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI;aACnD,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;aACrC,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;aACrC,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;aACnC,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;CAC7D"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MutablePrimitiveOrEnumPropertyBase = void 0;
4
+ /*---------------------------------------------------------------------------------------------
5
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
+ * See LICENSE.md in the project root for license terms and full copyright notice.
7
+ *--------------------------------------------------------------------------------------------*/
8
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
9
+ /**
10
+ * @internal
11
+ * An abstract class used for schema editing.
12
+ */
13
+ class MutablePrimitiveOrEnumPropertyBase extends ecschema_metadata_1.PrimitiveOrEnumPropertyBase {
14
+ }
15
+ exports.MutablePrimitiveOrEnumPropertyBase = MutablePrimitiveOrEnumPropertyBase;
16
+ //# sourceMappingURL=MutablePrimitiveOrEnumProperty.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MutablePrimitiveOrEnumProperty.js","sourceRoot":"","sources":["../../../../src/Editing/Mutable/MutablePrimitiveOrEnumProperty.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAuE;AAEvE;;;GAGG;AACH,MAAsB,kCAAmC,SAAQ,+CAA2B;CAM3F;AAND,gFAMC","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 { PrimitiveOrEnumPropertyBase } from \"@itwin/ecschema-metadata\";\r\n\r\n/**\r\n * @internal\r\n * An abstract class used for schema editing.\r\n */\r\nexport abstract class MutablePrimitiveOrEnumPropertyBase extends PrimitiveOrEnumPropertyBase {\r\n public abstract override setExtendedTypeName(extendedTypeName: string): void;\r\n public abstract override setMinLength(minLength: number): void;\r\n public abstract override setMaxLength(maxLength: number): void;\r\n public abstract override setMinValue(minValue: number): void;\r\n public abstract override setMaxValue(maxValue: number): void;\r\n}\r\n"]}
@@ -1,10 +1,15 @@
1
- import { CustomAttribute, ECName, Property } from "@itwin/ecschema-metadata";
1
+ import { CustomAttribute, ECName, LazyLoadedPropertyCategory, Property } from "@itwin/ecschema-metadata";
2
2
  /**
3
3
  * @internal
4
4
  * An abstract class used for schema editing.
5
5
  */
6
6
  export declare abstract class MutableProperty extends Property {
7
7
  abstract setName(name: ECName): void;
8
+ abstract setDescription(description: string): void;
9
+ abstract setLabel(label: string): void;
10
+ abstract setIsReadOnly(isReadOnly: boolean): void;
11
+ abstract setPriority(priority: number): void;
12
+ abstract setCategory(category: LazyLoadedPropertyCategory): void;
8
13
  abstract addCustomAttribute(customAttribute: CustomAttribute): void;
9
14
  }
10
15
  //# sourceMappingURL=MutableProperty.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MutableProperty.d.ts","sourceRoot":"","sources":["../../../../src/Editing/Mutable/MutableProperty.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAE7E;;;GAGG;AACH,8BAAsB,eAAgB,SAAQ,QAAQ;aAC3B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;aAC3B,kBAAkB,CAAC,eAAe,EAAE,eAAe,GAAG,IAAI;CACpF"}
1
+ {"version":3,"file":"MutableProperty.d.ts","sourceRoot":"","sources":["../../../../src/Editing/Mutable/MutableProperty.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,0BAA0B,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzG;;;GAGG;AACH,8BAAsB,eAAgB,SAAQ,QAAQ;aAC3B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;aAC3B,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;aACzC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;aAC7B,aAAa,CAAC,UAAU,EAAE,OAAO,GAAG,IAAI;aACxC,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;aACnC,WAAW,CAAC,QAAQ,EAAE,0BAA0B,GAAG,IAAI;aACvD,kBAAkB,CAAC,eAAe,EAAE,eAAe,GAAG,IAAI;CACpF"}
@@ -1 +1 @@
1
- {"version":3,"file":"MutableProperty.js","sourceRoot":"","sources":["../../../../src/Editing/Mutable/MutableProperty.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAA6E;AAE7E;;;GAGG;AACH,MAAsB,eAAgB,SAAQ,4BAAQ;CAGrD;AAHD,0CAGC","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 { CustomAttribute, ECName, Property } from \"@itwin/ecschema-metadata\";\r\n\r\n/**\r\n * @internal\r\n * An abstract class used for schema editing.\r\n */\r\nexport abstract class MutableProperty extends Property {\r\n public abstract override setName(name: ECName): void;\r\n public abstract override addCustomAttribute(customAttribute: CustomAttribute): void;\r\n}\r\n"]}
1
+ {"version":3,"file":"MutableProperty.js","sourceRoot":"","sources":["../../../../src/Editing/Mutable/MutableProperty.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAyG;AAEzG;;;GAGG;AACH,MAAsB,eAAgB,SAAQ,4BAAQ;CAQrD;AARD,0CAQC","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 { CustomAttribute, ECName, LazyLoadedPropertyCategory, Property } from \"@itwin/ecschema-metadata\";\r\n\r\n/**\r\n * @internal\r\n * An abstract class used for schema editing.\r\n */\r\nexport abstract class MutableProperty extends Property {\r\n public abstract override setName(name: ECName): void;\r\n public abstract override setDescription(description: string): void;\r\n public abstract override setLabel(label: string): void;\r\n public abstract override setIsReadOnly(isReadOnly: boolean): void;\r\n public abstract override setPriority(priority: number): void;\r\n public abstract override setCategory(category: LazyLoadedPropertyCategory): void;\r\n public abstract override addCustomAttribute(customAttribute: CustomAttribute): void;\r\n}\r\n"]}
@@ -0,0 +1,15 @@
1
+ import { Property, PropertyProps, SchemaItemKey } from "@itwin/ecschema-metadata";
2
+ import { SchemaMergeContext } from "./SchemaMerger";
3
+ import { PropertyEditResults } from "../Editing/Editor";
4
+ /**
5
+ * @internal
6
+ */
7
+ export declare class AnyPropertyMerger<TProperty extends Property> {
8
+ protected readonly context: SchemaMergeContext;
9
+ constructor(context: SchemaMergeContext);
10
+ createFromProps(_classKey: SchemaItemKey, property: TProperty): Promise<PropertyEditResults>;
11
+ protected isPropertyEditResults(obj: any): obj is PropertyEditResults;
12
+ protected getPropertyProps(property: TProperty): Promise<PropertyEditResults | PropertyProps>;
13
+ mergeAttributes(property: TProperty, attributeName: string, attributeNewValue: any, _attributeOldValue: any): Promise<PropertyEditResults | boolean>;
14
+ }
15
+ //# sourceMappingURL=AnyPropertyMerger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnyPropertyMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/AnyPropertyMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAkB,QAAQ,EAAoB,aAAa,EAAwB,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC1I,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAGxD;;GAEG;AACH,qBAAa,iBAAiB,CAAC,SAAS,SAAS,QAAQ;IACvD,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;gBAEnC,OAAO,EAAE,kBAAkB;IAI1B,eAAe,CAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAIzG,SAAS,CAAC,qBAAqB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,mBAAmB;cAIrD,gBAAgB,CAAC,QAAQ,EAAE,SAAS,GAAG,OAAO,CAAC,mBAAmB,GAAG,aAAa,CAAC;IA+BtF,eAAe,CAAC,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,EAAE,kBAAkB,EAAE,GAAG,GAAG,OAAO,CAAC,mBAAmB,GAAG,OAAO,CAAC;CAqBlK"}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AnyPropertyMerger = void 0;
4
+ /*---------------------------------------------------------------------------------------------
5
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
+ * See LICENSE.md in the project root for license terms and full copyright notice.
7
+ *--------------------------------------------------------------------------------------------*/
8
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
9
+ /**
10
+ * @internal
11
+ */
12
+ class AnyPropertyMerger {
13
+ constructor(context) {
14
+ this.context = context;
15
+ }
16
+ async createFromProps(_classKey, property) {
17
+ return { errorMessage: `Property Type ${(0, ecschema_metadata_1.propertyTypeToString)(property.propertyType)} is not implemented.` };
18
+ }
19
+ isPropertyEditResults(obj) {
20
+ return typeof obj === "object" && "errorMessage" in obj;
21
+ }
22
+ async getPropertyProps(property) {
23
+ let props = {};
24
+ if (property.category !== undefined) {
25
+ const sourceCategory = await property.category;
26
+ const itemKey = new ecschema_metadata_1.SchemaItemKey(sourceCategory.name, this.context.sourceSchema.schemaKey.matches(sourceCategory.schema.schemaKey)
27
+ ? this.context.targetSchema.schemaKey
28
+ : sourceCategory.schema.schemaKey);
29
+ const targetCategory = await this.context.targetSchema.lookupItem(itemKey);
30
+ if (targetCategory === undefined) {
31
+ return { errorMessage: `Unable to locate the property category class ${sourceCategory.name} in the merged schema.` };
32
+ }
33
+ props = { ...props, category: targetCategory.fullName };
34
+ }
35
+ if (property.kindOfQuantity !== undefined) {
36
+ const sourceKoq = await property.kindOfQuantity;
37
+ const itemKey = new ecschema_metadata_1.SchemaItemKey(sourceKoq.name, this.context.sourceSchema.schemaKey.matches(sourceKoq.schema.schemaKey)
38
+ ? this.context.targetSchema.schemaKey
39
+ : sourceKoq.schema.schemaKey);
40
+ const targetKoq = await this.context.targetSchema.lookupItem(itemKey);
41
+ if (targetKoq === undefined) {
42
+ return { errorMessage: `Unable to locate the property kind of quantity ${sourceKoq.name} in the merged schema.` };
43
+ }
44
+ props = { ...props, kindOfQuantity: targetKoq.fullName };
45
+ }
46
+ return props;
47
+ }
48
+ async mergeAttributes(property, attributeName, attributeNewValue, _attributeOldValue) {
49
+ const mutableProperty = property;
50
+ switch (attributeName) {
51
+ case "description":
52
+ mutableProperty.setDescription(attributeNewValue);
53
+ return true;
54
+ case "label":
55
+ mutableProperty.setLabel(attributeNewValue);
56
+ return true;
57
+ case "isReadOnly":
58
+ mutableProperty.setIsReadOnly(attributeNewValue);
59
+ return true;
60
+ case "priority":
61
+ mutableProperty.setPriority(attributeNewValue);
62
+ return true;
63
+ case "type":
64
+ case "primitiveType":
65
+ return { errorMessage: `Changing the property '${property.name}' ${attributeName} is not supported.` };
66
+ }
67
+ return false;
68
+ }
69
+ }
70
+ exports.AnyPropertyMerger = AnyPropertyMerger;
71
+ //# sourceMappingURL=AnyPropertyMerger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnyPropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/AnyPropertyMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAA0I;AAK1I;;GAEG;AACH,MAAa,iBAAiB;IAG5B,YAAY,OAA2B;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,SAAwB,EAAE,QAAmB;QACxE,OAAO,EAAE,YAAY,EAAE,iBAAiB,IAAA,wCAAoB,EAAC,QAAQ,CAAC,YAAY,CAAC,sBAAsB,EAAE,CAAC;IAC9G,CAAC;IAES,qBAAqB,CAAC,GAAQ;QACtC,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,cAAc,IAAI,GAAG,CAAC;IAC1D,CAAC;IAES,KAAK,CAAC,gBAAgB,CAAC,QAAmB;QAClD,IAAI,KAAK,GAAG,EAAoB,CAAC;Q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3B,OAAO,EAAE,YAAY,EAAE,kDAAkD,SAAS,CAAC,IAAI,wBAAwB,EAAE,CAAC;aACnH;YACD,KAAK,GAAG,EAAC,GAAG,KAAK,EAAE,cAAc,EAAE,SAAS,CAAC,QAAQ,EAAC,CAAC;SACxD;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,QAAmB,EAAE,aAAqB,EAAE,iBAAsB,EAAE,kBAAuB;QACtH,MAAM,eAAe,GAAG,QAAsC,CAAC;QAC/D,QAAO,aAAa,EAAE;YACpB,KAAK,aAAa;gBAChB,eAAe,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;gBAClD,OAAO,IAAI,CAAC;YACd,KAAK,OAAO;gBACV,eAAe,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;gBAC5C,OAAO,IAAI,CAAC;YACd,KAAK,YAAY;gBACf,eAAe,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC;gBACjD,OAAO,IAAI,CAAC;YACd,KAAK,UAAU;gBACb,eAAe,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;gBAC/C,OAAO,IAAI,CAAC;YACd,KAAK,MAAM,CAAC;YACZ,KAAK,eAAe;gBAClB,OAAO,EAAE,YAAY,EAAE,0BAA0B,QAAQ,CAAC,IAAI,KAAK,aAAa,oBAAoB,EAAE,CAAC;SAC1G;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAnED,8CAmEC","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 { KindOfQuantity, Property, PropertyCategory, PropertyProps, propertyTypeToString, SchemaItemKey } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaMergeContext } from \"./SchemaMerger\";\r\nimport { PropertyEditResults } from \"../Editing/Editor\";\r\nimport { MutableProperty } from \"../Editing/Mutable/MutableProperty\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class AnyPropertyMerger<TProperty extends Property> {\r\n protected readonly context: SchemaMergeContext;\r\n\r\n constructor(context: SchemaMergeContext) {\r\n this.context = context;\r\n }\r\n\r\n public async createFromProps(_classKey: SchemaItemKey, property: TProperty): Promise<PropertyEditResults> {\r\n return { errorMessage: `Property Type ${propertyTypeToString(property.propertyType)} is not implemented.` };\r\n }\r\n\r\n protected isPropertyEditResults(obj: any): obj is PropertyEditResults {\r\n return typeof obj === \"object\" && \"errorMessage\" in obj;\r\n }\r\n\r\n protected async getPropertyProps(property: TProperty): Promise<PropertyEditResults | PropertyProps> {\r\n let props = {} as PropertyProps;\r\n\r\n if (property.category !== undefined) {\r\n const sourceCategory = await property.category;\r\n const itemKey = new SchemaItemKey(sourceCategory.name, this.context.sourceSchema.schemaKey.matches(sourceCategory.schema.schemaKey)\r\n ? this.context.targetSchema.schemaKey\r\n : sourceCategory.schema.schemaKey,\r\n );\r\n const targetCategory = await this.context.targetSchema.lookupItem<PropertyCategory>(itemKey);\r\n if (targetCategory === undefined) {\r\n return { errorMessage: `Unable to locate the property category class ${sourceCategory.name} in the merged schema.` };\r\n }\r\n props = {...props, category: targetCategory.fullName};\r\n }\r\n\r\n if (property.kindOfQuantity !== undefined) {\r\n const sourceKoq = await property.kindOfQuantity;\r\n const itemKey = new SchemaItemKey(sourceKoq.name, this.context.sourceSchema.schemaKey.matches(sourceKoq.schema.schemaKey)\r\n ? this.context.targetSchema.schemaKey\r\n : sourceKoq.schema.schemaKey,\r\n );\r\n const targetKoq = await this.context.targetSchema.lookupItem<KindOfQuantity>(itemKey);\r\n if (targetKoq === undefined) {\r\n return { errorMessage: `Unable to locate the property kind of quantity ${sourceKoq.name} in the merged schema.` };\r\n }\r\n props = {...props, kindOfQuantity: targetKoq.fullName};\r\n }\r\n return props;\r\n }\r\n\r\n public async mergeAttributes(property: TProperty, attributeName: string, attributeNewValue: any, _attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n const mutableProperty = property as unknown as MutableProperty;\r\n switch(attributeName) {\r\n case \"description\":\r\n mutableProperty.setDescription(attributeNewValue);\r\n return true;\r\n case \"label\":\r\n mutableProperty.setLabel(attributeNewValue);\r\n return true;\r\n case \"isReadOnly\":\r\n mutableProperty.setIsReadOnly(attributeNewValue);\r\n return true;\r\n case \"priority\":\r\n mutableProperty.setPriority(attributeNewValue);\r\n return true;\r\n case \"type\":\r\n case \"primitiveType\":\r\n return { errorMessage: `Changing the property '${property.name}' ${attributeName} is not supported.` };\r\n }\r\n return false;\r\n }\r\n}\r\n"]}
@@ -0,0 +1,32 @@
1
+ import { ArrayProperty, EnumerationArrayProperty, PrimitiveArrayProperty, SchemaItemKey, StructArrayProperty } from "@itwin/ecschema-metadata";
2
+ import { AnyPropertyMerger } from "./AnyPropertyMerger";
3
+ import { PropertyEditResults } from "../Editing/Editor";
4
+ /**
5
+ * @internal
6
+ */
7
+ declare class ArrayPropertyMerger<TArrayProperty extends ArrayProperty> extends AnyPropertyMerger<TArrayProperty> {
8
+ mergeAttributes(property: TArrayProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean>;
9
+ }
10
+ /**
11
+ * @internal
12
+ */
13
+ export declare class StructArrayPropertyMerger extends ArrayPropertyMerger<StructArrayProperty> {
14
+ mergeAttributes(property: StructArrayProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean>;
15
+ createFromProps(classKey: SchemaItemKey, property: StructArrayProperty): Promise<PropertyEditResults>;
16
+ }
17
+ /**
18
+ * @internal
19
+ */
20
+ export declare class EnumerationArrayPropertyMerger extends ArrayPropertyMerger<EnumerationArrayProperty> {
21
+ mergeAttributes(property: EnumerationArrayProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean>;
22
+ createFromProps(classKey: SchemaItemKey, property: EnumerationArrayProperty): Promise<PropertyEditResults>;
23
+ }
24
+ /**
25
+ * @internal
26
+ */
27
+ export declare class PrimitiveArraPropertyMerger extends ArrayPropertyMerger<PrimitiveArrayProperty> {
28
+ mergeAttributes(property: PrimitiveArrayProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean>;
29
+ createFromProps(classKey: SchemaItemKey, property: PrimitiveArrayProperty): Promise<PropertyEditResults>;
30
+ }
31
+ export {};
32
+ //# sourceMappingURL=ArrayPropertyMerger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArrayPropertyMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/ArrayPropertyMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAe,wBAAwB,EAAE,sBAAsB,EAAE,aAAa,EAAE,mBAAmB,EAAyC,MAAM,0BAA0B,CAAC;AAEnM,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAGxD;;GAEG;AACH,cAAM,mBAAmB,CAAC,cAAc,SAAS,aAAa,CAAG,SAAQ,iBAAiB,CAAE,cAAc,CAAC;IACnF,eAAe,CAAC,QAAQ,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,EAAE,GAAG,GAAG,OAAO,CAAC,mBAAmB,GAAG,OAAO,CAAC;CAmB/K;AAED;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,mBAAmB,CAAE,mBAAmB,CAAC;IAChE,eAAe,CAAC,QAAQ,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,EAAE,GAAG,GAAG,OAAO,CAAC,mBAAmB,GAAG,OAAO,CAAC;IAiB7J,eAAe,CAAC,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAsB5H;AAED;;GAEG;AACH,qBAAa,8BAA+B,SAAQ,mBAAmB,CAAE,wBAAwB,CAAC;IAC1E,eAAe,CAAC,QAAQ,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,EAAE,GAAG,GAAG,OAAO,CAAC,mBAAmB,GAAG,OAAO,CAAC;IAiBlK,eAAe,CAAC,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,wBAAwB,GAAG,OAAO,CAAC,mBAAmB,CAAC;CA0BjI;AAED;;GAEG;AACH,qBAAa,2BAA4B,SAAQ,mBAAmB,CAAE,sBAAsB,CAAC;IACrE,eAAe,CAAC,QAAQ,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,EAAE,GAAG,GAAG,OAAO,CAAC,mBAAmB,GAAG,OAAO,CAAC;IAchK,eAAe,CAAC,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,sBAAsB,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAY/H"}
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PrimitiveArraPropertyMerger = exports.EnumerationArrayPropertyMerger = exports.StructArrayPropertyMerger = void 0;
4
+ /*---------------------------------------------------------------------------------------------
5
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
+ * See LICENSE.md in the project root for license terms and full copyright notice.
7
+ *--------------------------------------------------------------------------------------------*/
8
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
9
+ const AnyPropertyMerger_1 = require("./AnyPropertyMerger");
10
+ /**
11
+ * @internal
12
+ */
13
+ class ArrayPropertyMerger extends AnyPropertyMerger_1.AnyPropertyMerger {
14
+ async mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue) {
15
+ const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);
16
+ if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {
17
+ return results;
18
+ }
19
+ const mutableProperty = property;
20
+ switch (attributeName) {
21
+ case "minOccurs":
22
+ mutableProperty.setMinOccurs(attributeNewValue);
23
+ return true;
24
+ case "maxOccurs":
25
+ mutableProperty.setMaxOccurs(attributeNewValue);
26
+ return true;
27
+ }
28
+ return false;
29
+ }
30
+ }
31
+ /**
32
+ * @internal
33
+ */
34
+ class StructArrayPropertyMerger extends ArrayPropertyMerger {
35
+ async mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue) {
36
+ const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);
37
+ if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {
38
+ return results;
39
+ }
40
+ switch (attributeName) {
41
+ case "structClass": {
42
+ if (attributeOldValue !== undefined) {
43
+ return { errorMessage: `Changing the property '${property.name}' structClass is not supported.` };
44
+ }
45
+ return true;
46
+ }
47
+ }
48
+ return false;
49
+ }
50
+ async createFromProps(classKey, property) {
51
+ const results = await super.getPropertyProps(property);
52
+ if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {
53
+ return results;
54
+ }
55
+ const itemKey = new ecschema_metadata_1.SchemaItemKey(property.structClass.name, this.context.sourceSchema.schemaKey.matches(property.structClass.schema.schemaKey)
56
+ ? this.context.targetSchema.schemaKey
57
+ : property.structClass.schema.schemaKey);
58
+ const type = await this.context.targetSchema.lookupItem(itemKey);
59
+ if (type === undefined) {
60
+ return { errorMessage: `Unable to locate the struct class ${property.structClass.name} in the merged schema.` };
61
+ }
62
+ const props = {
63
+ ...property.toJSON(),
64
+ ...results,
65
+ typeName: type.fullName,
66
+ };
67
+ return this.context.editor.entities.createStructArrayPropertyFromProps(classKey, property.name, type, props);
68
+ }
69
+ }
70
+ exports.StructArrayPropertyMerger = StructArrayPropertyMerger;
71
+ /**
72
+ * @internal
73
+ */
74
+ class EnumerationArrayPropertyMerger extends ArrayPropertyMerger {
75
+ async mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue) {
76
+ const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);
77
+ if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {
78
+ return results;
79
+ }
80
+ switch (attributeName) {
81
+ case "enumeration": {
82
+ if (attributeOldValue !== undefined) {
83
+ return { errorMessage: `Changing the property '${property.name}' enumeration is not supported.` };
84
+ }
85
+ return true;
86
+ }
87
+ }
88
+ return false;
89
+ }
90
+ async createFromProps(classKey, property) {
91
+ const results = await super.getPropertyProps(property);
92
+ if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {
93
+ return results;
94
+ }
95
+ if (property.enumeration === undefined) {
96
+ return { errorMessage: `Property '${property.fullName}' is missing the required 'enumeration' attribute.` };
97
+ }
98
+ const enumeration = await property.enumeration;
99
+ const itemKey = new ecschema_metadata_1.SchemaItemKey(enumeration.name, this.context.sourceSchema.schemaKey.matches(enumeration.schema.schemaKey)
100
+ ? this.context.targetSchema.schemaKey
101
+ : enumeration.schema.schemaKey);
102
+ const type = await this.context.targetSchema.lookupItem(itemKey);
103
+ if (type === undefined) {
104
+ return { errorMessage: `Unable to locate the enumeration class ${enumeration.name} in the merged schema.` };
105
+ }
106
+ const props = {
107
+ ...property.toJSON(),
108
+ ...results,
109
+ };
110
+ return this.context.editor.entities.createEnumerationArrayPropertyFromProps(classKey, property.name, type, props);
111
+ }
112
+ }
113
+ exports.EnumerationArrayPropertyMerger = EnumerationArrayPropertyMerger;
114
+ /**
115
+ * @internal
116
+ */
117
+ class PrimitiveArraPropertyMerger extends ArrayPropertyMerger {
118
+ async mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue) {
119
+ const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);
120
+ if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {
121
+ return results;
122
+ }
123
+ switch (attributeName) {
124
+ case "primitiveType": {
125
+ return { errorMessage: `Changing the property '${property.name}' typeName is not supported.` };
126
+ }
127
+ }
128
+ return false;
129
+ }
130
+ async createFromProps(classKey, property) {
131
+ const results = await super.getPropertyProps(property);
132
+ if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {
133
+ return results;
134
+ }
135
+ const props = {
136
+ ...property.toJSON(),
137
+ ...results,
138
+ };
139
+ return this.context.editor.entities.createPrimitiveArrayPropertyFromProps(classKey, property.name, property.primitiveType, props);
140
+ }
141
+ }
142
+ exports.PrimitiveArraPropertyMerger = PrimitiveArraPropertyMerger;
143
+ //# sourceMappingURL=ArrayPropertyMerger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArrayPropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/ArrayPropertyMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAmM;AAEnM,2DAAwD;AAIxD;;GAEG;AACH,MAAM,mBAA2D,SAAQ,qCAAkC;IACzF,KAAK,CAAC,eAAe,CAAC,QAAwB,EAAE,aAAqB,EAAE,iBAAsB,EAAE,iBAAsB;QACnI,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,eAAe,CAAC,QAAQ,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;QAC3G,IAAI,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;YACjG,OAAO,OAAO,CAAC;SAChB;QAED,MAAM,eAAe,GAAG,QAA2C,CAAC;QACpE,QAAQ,aAAa,EAAE;YACrB,KAAK,WAAW;gBACd,eAAe,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC;gBAChD,OAAO,IAAI,CAAC;YAEd,KAAK,WAAW;gBACd,eAAe,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC;gBAChD,OAAO,IAAI,CAAC;SAEf;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED;;GAEG;AACH,MAAa,yBAA0B,SAAQ,mBAAyC;IACtE,KAAK,CAAC,e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eAAe,CAAC,QAAQ,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;QAC3G,IAAI,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;YACjG,OAAO,OAAO,CAAC;SAChB;QAED,QAAQ,aAAa,EAAE;YACrB,KAAK,eAAe,CAAC,CAAC;gBACpB,OAAO,EAAE,YAAY,EAAE,0BAA0B,QAAQ,CAAC,IAAI,8BAA8B,EAAC,CAAC;aAC/F;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAEe,KAAK,CAAC,eAAe,CAAC,QAAuB,EAAE,QAAgC;QAC7F,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QACvD,IAAI,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;YAC7E,OAAO,OAAO,CAAC;SAChB;QAED,MAAM,KAAK,GAAgC;YACzC,GAAG,QAAQ,CAAC,MAAM,EAAE;YACpB,GAAG,OAAO;SACX,CAAC;QACF,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,qCAAqC,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;IACpI,CAAC;CACF;AA3BD,kEA2BC","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 { ArrayProperty, Enumeration, EnumerationArrayProperty, PrimitiveArrayProperty, SchemaItemKey, StructArrayProperty, StructArrayPropertyProps, StructClass } from \"@itwin/ecschema-metadata\";\r\nimport { PrimitiveArrayPropertyProps } from \"@itwin/ecschema-metadata/src/Deserialization/JsonProps\";\r\nimport { AnyPropertyMerger } from \"./AnyPropertyMerger\";\r\nimport { PropertyEditResults } from \"../Editing/Editor\";\r\nimport { MutableArrayProperty } from \"../Editing/Mutable/MutableArrayProperty\";\r\n\r\n/**\r\n * @internal\r\n */\r\nclass ArrayPropertyMerger<TArrayProperty extends ArrayProperty> extends AnyPropertyMerger <TArrayProperty> {\r\n public override async mergeAttributes(property: TArrayProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\r\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n const mutableProperty = property as unknown as MutableArrayProperty;\r\n switch (attributeName) {\r\n case \"minOccurs\":\r\n mutableProperty.setMinOccurs(attributeNewValue);\r\n return true;\r\n\r\n case \"maxOccurs\":\r\n mutableProperty.setMaxOccurs(attributeNewValue);\r\n return true;\r\n\r\n }\r\n return false;\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class StructArrayPropertyMerger extends ArrayPropertyMerger <StructArrayProperty> {\r\n public override async mergeAttributes(property: StructArrayProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\r\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n switch (attributeName) {\r\n case \"structClass\": {\r\n if (attributeOldValue !== undefined) {\r\n return { errorMessage: `Changing the property '${property.name}' structClass is not supported.` };\r\n }\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n public override async createFromProps(classKey: SchemaItemKey, property: StructArrayProperty): Promise<PropertyEditResults> {\r\n const results = await super.getPropertyProps(property);\r\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n const itemKey = new SchemaItemKey(property.structClass.name, this.context.sourceSchema.schemaKey.matches(property.structClass.schema.schemaKey)\r\n ? this.context.targetSchema.schemaKey\r\n : property.structClass.schema.schemaKey,\r\n );\r\n const type = await this.context.targetSchema.lookupItem<StructClass>(itemKey);\r\n if (type === undefined) {\r\n return { errorMessage: `Unable to locate the struct class ${property.structClass.name} in the merged schema.` };\r\n }\r\n\r\n const props: StructArrayPropertyProps = {\r\n ...property.toJSON(),\r\n ...results,\r\n typeName: type.fullName,\r\n };\r\n return this.context.editor.entities.createStructArrayPropertyFromProps(classKey, property.name, type, props);\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class EnumerationArrayPropertyMerger extends ArrayPropertyMerger <EnumerationArrayProperty> {\r\n public override async mergeAttributes(property: EnumerationArrayProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\r\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n switch (attributeName) {\r\n case \"enumeration\": {\r\n if (attributeOldValue !== undefined) {\r\n return { errorMessage: `Changing the property '${property.name}' enumeration is not supported.` };\r\n }\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n public override async createFromProps(classKey: SchemaItemKey, property: EnumerationArrayProperty): Promise<PropertyEditResults> {\r\n const results = await super.getPropertyProps(property);\r\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n if (property.enumeration === undefined) {\r\n return { errorMessage: `Property '${property.fullName}' is missing the required 'enumeration' attribute.` };\r\n }\r\n\r\n const enumeration = await property.enumeration;\r\n const itemKey = new SchemaItemKey(enumeration.name, this.context.sourceSchema.schemaKey.matches(enumeration.schema.schemaKey)\r\n ? this.context.targetSchema.schemaKey\r\n : enumeration.schema.schemaKey,\r\n );\r\n const type = await this.context.targetSchema.lookupItem<Enumeration>(itemKey);\r\n if (type === undefined) {\r\n return { errorMessage: `Unable to locate the enumeration class ${enumeration.name} in the merged schema.` };\r\n }\r\n\r\n const props: PrimitiveArrayPropertyProps = {\r\n ...property.toJSON(),\r\n ...results,\r\n };\r\n return this.context.editor.entities.createEnumerationArrayPropertyFromProps(classKey, property.name, type, props);\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class PrimitiveArraPropertyMerger extends ArrayPropertyMerger <PrimitiveArrayProperty> {\r\n public override async mergeAttributes(property: PrimitiveArrayProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\r\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n switch (attributeName) {\r\n case \"primitiveType\": {\r\n return { errorMessage: `Changing the property '${property.name}' typeName is not supported.`};\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n public override async createFromProps(classKey: SchemaItemKey, property: PrimitiveArrayProperty): Promise<PropertyEditResults> {\r\n const results = await super.getPropertyProps(property);\r\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n const props: PrimitiveArrayPropertyProps = {\r\n ...property.toJSON(),\r\n ...results,\r\n };\r\n return this.context.editor.entities.createPrimitiveArrayPropertyFromProps(classKey, property.name, property.primitiveType, props);\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ClassMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/ClassMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAmB,KAAK,EAAsB,aAAa,EAA0B,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACjJ,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAA8B,YAAY,EAA2C,MAA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EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;cAI9E,QAAQ,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,qBAAqB,CAAC;cAI9E,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,EAAE,GAAG,GAAG,OAAO,CAAC,qBAAqB,GAAG,OAAO,CAAC;IAgCjK,SAAS,CAAC,uBAAuB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,qBAAqB;YAI3D,YAAY;YAwBZ,SAAS;YAkBT,0BAA0B;WAmBpB,YAAY,CAAC,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,QAAQ,CAAC,YAAY,CAAC;CA0CnG"}
@@ -7,6 +7,7 @@ exports.ClassMerger = void 0;
7
7
  *--------------------------------------------------------------------------------------------*/
8
8
  const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
9
9
  const SchemaChanges_1 = require("../Validation/SchemaChanges");
10
+ const ClassPropertyMerger_1 = require("./ClassPropertyMerger");
10
11
  /**
11
12
  * @internal
12
13
  */
@@ -133,6 +134,10 @@ class ClassMerger {
133
134
  }
134
135
  }
135
136
  await merger.mergeAttributeValueChanges(targetItemKey, change.propertyValueChanges);
137
+ const mergeResults = await ClassPropertyMerger_1.ClassPropertyMerger.mergeChanges(context, targetItemKey, change.propertyChanges.values());
138
+ if (mergeResults.errorMessage !== undefined) {
139
+ throw new Error(mergeResults.errorMessage);
140
+ }
136
141
  }
137
142
  }
138
143
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/ClassMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAiJ;AAIjJ,+DAAgI;AAEhI;;GAEG;AACH,MAAa,WAAW;IAGtB,YAAY,OAA2B;QACrC,IAA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C,CAAC;iBACvC;gBACD,aAAa,GAAG,OAAO,CAAC,OAAQ,CAAC;aAClC;YAED,IAAI,MAAM,CAAC,cAAc,KAAK,SAAS,EAAE;gBACvC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;gBAC5F,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;oBACtC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;iBACvC;aACF;YAED,IAAI,MAAM,CAAC,kBAAkB,CAAC,IAAI,GAAG,CAAC,EAAE;gBACtC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,aAAa,EAAE,MAAM,CAAC,kBAAkB,CAAC,MAAM,EAAE,EAAE,UAAU,CAAC,CAAC;gBACtG,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;oBACtC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;iBACvC;aACF;YAED,MAAM,MAAM,CAAC,0BAA0B,CAAC,aAAa,EAAE,MAAM,CAAC,oBAAoB,CAAC,CAAC;SACrF;IACH,CAAC;CACF;AAtJD,kCAsJC","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 { ECClass, ECClassModifier, Mixin, parseClassModifier, SchemaItemKey, schemaItemTypeToString, SchemaKey } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaItemEditResults } from \"../Editing/Editor\";\r\nimport { MutableClass } from \"../Editing/Mutable/MutableClass\";\r\nimport { SchemaMergeContext } from \"./SchemaMerger\";\r\nimport { BaseClassDelta, ChangeType, ClassChanges, EntityMixinChanges, PropertyValueChange } from \"../Validation/SchemaChanges\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class ClassMerger<TClass extends ECClass> {\r\n protected readonly context: SchemaMergeContext;\r\n\r\n constructor(context: SchemaMergeContext) {\r\n this.context = context;\r\n }\r\n\r\n protected async create(_schemaKey: SchemaKey, ecClass: TClass): Promise<SchemaItemEditResults> {\r\n return { errorMessage: `${schemaItemTypeToString(ecClass.schemaItemType)} class type is not implemented.`};\r\n }\r\n\r\n protected async addMixin(itemKey: SchemaItemKey, mixin: Mixin): Promise<SchemaItemEditResults> {\r\n return { errorMessage: `Adding mixin '${mixin.name}' to '${itemKey.name}' class is not implemented.` };\r\n }\r\n\r\n protected async mergeAttributes(ecClass: TClass, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<SchemaItemEditResults | boolean> {\r\n const mutableClass = ecClass as unknown as MutableClass;\r\n switch(attributeName) {\r\n case \"schemaItemType\":\r\n if (attributeOldValue !== undefined && attributeOldValue !== attributeNewValue) {\r\n return { errorMessage: `Changing the class '${ecClass.name}' type is not supported.` };\r\n }\r\n return true;\r\n\r\n case \"label\":\r\n mutableClass.setDisplayLabel(attributeNewValue);\r\n return true;\r\n\r\n case \"description\":\r\n mutableClass.setDescription(attributeNewValue);\r\n return true;\r\n\r\n case \"modifier\":\r\n const modifier = parseClassModifier(attributeNewValue);\r\n if (modifier === undefined) {\r\n return { errorMessage: \"An invalid class modifier has been provided.\" };\r\n }\r\n\r\n if (attributeOldValue === undefined || modifier === ECClassModifier.None) {\r\n mutableClass.setModifier(modifier);\r\n return true;\r\n }\r\n return { errorMessage: `Changing the class '${ecClass.name}' modifier is not supported.` };\r\n }\r\n return false;\r\n }\r\n\r\n protected isSchemaItemEditResults(obj: any): obj is SchemaItemEditResults {\r\n return typeof obj === \"object\" && \"errorMessage\" in obj;\r\n }\r\n\r\n private async setBaseClass(itemKey: SchemaItemKey, baseClassDelta: BaseClassDelta, changeType?: ChangeType): Promise<SchemaItemEditResults> {\r\n const [sourceBaseClass, targetBaseClass] = baseClassDelta.diagnostic.messageArgs! as [ECClass, ECClass];\r\n if (sourceBaseClass !== undefined) {\r\n const baseClassKey = new SchemaItemKey(sourceBaseClass.name, sourceBaseClass.schema.schemaKey.matches(this.context.sourceSchema.schemaKey)\r\n ? this.context.targetSchema.schemaKey\r\n : sourceBaseClass.schema.schemaKey);\r\n\r\n if (changeType === ChangeType.Missing && targetBaseClass === undefined) {\r\n return this.context.editor.entities.setBaseClass(itemKey, baseClassKey);\r\n }\r\n\r\n if (targetBaseClass !== undefined) {\r\n const baseClass = await this.context.targetSchema.lookupItem<ECClass>(baseClassKey);\r\n if (baseClass === undefined) {\r\n return { errorMessage: `'${baseClassKey.name}' class could not be located in the merged schema.`};\r\n }\r\n if (await baseClass.is(targetBaseClass)) {\r\n return this.context.editor.entities.setBaseClass(itemKey, baseClassKey);\r\n }\r\n }\r\n }\r\n return { errorMessage: `Changing the class '${itemKey.name}' baseClass is not supported.`};\r\n }\r\n\r\n private async addMixins(itemKey: SchemaItemKey, entityMixinChanges: Iterable<EntityMixinChanges>, changeType?: ChangeType): Promise<SchemaItemEditResults> {\r\n if (changeType === ChangeType.Missing) {\r\n for (const entityMixinChange of entityMixinChanges) {\r\n for (const change of entityMixinChange.entityMixinChange) {\r\n const mixins = change.diagnostic.messageArgs! as unknown as [Mixin];\r\n for (const mixin of mixins) {\r\n const result = await this.addMixin(itemKey, mixin);\r\n if (result.errorMessage !== undefined) {\r\n return result;\r\n }\r\n }\r\n }\r\n }\r\n return {};\r\n }\r\n return { errorMessage: `Changing the class '${itemKey.name}' mixins is not supported.`};\r\n }\r\n\r\n private async mergeAttributeValueChanges(itemKey: SchemaItemKey, propertyValueChanges: PropertyValueChange[]) {\r\n if (propertyValueChanges.length === 0) {\r\n return;\r\n }\r\n\r\n const targetItem = await this.context.targetSchema.lookupItem<TClass>(itemKey);\r\n if (targetItem === undefined) {\r\n throw new Error(`'${itemKey.name}' class could not be located in the merged schema.`);\r\n }\r\n\r\n for (const change of propertyValueChanges) {\r\n const [attributeName, attributeNewValue, attributeOldValue] = change.diagnostic.messageArgs!;\r\n const results = await this.mergeAttributes(targetItem, attributeName, attributeNewValue, attributeOldValue);\r\n if (this.isSchemaItemEditResults(results) && results.errorMessage !== undefined) {\r\n throw new Error(results.errorMessage);\r\n }\r\n }\r\n }\r\n\r\n public static async mergeChanges(context: SchemaMergeContext, classChanges: Iterable<ClassChanges>) {\r\n const merger = new this(context);\r\n\r\n for (const change of classChanges) {\r\n const sourceItem = (await change.schema.getItem<ECClass>(change.ecTypeName))!;\r\n let targetItemKey = new SchemaItemKey(change.ecTypeName, context.targetSchema.schemaKey);\r\n const changeType = change.schemaItemMissing?.changeType;\r\n\r\n if (changeType === ChangeType.Missing) {\r\n\r\n if (await context.targetSchema.lookupItem<ECClass>(targetItemKey) !== undefined) {\r\n throw new Error(`Merged schema already contains a class '${change.ecTypeName}'.`);\r\n }\r\n\r\n const results = await merger.create(context.targetSchema.schemaKey, sourceItem);\r\n if (results.errorMessage !== undefined) {\r\n throw new Error(results.errorMessage);\r\n }\r\n targetItemKey = results.itemKey!;\r\n }\r\n\r\n if (change.baseClassDelta !== undefined) {\r\n const results = await merger.setBaseClass(targetItemKey, change.baseClassDelta, changeType);\r\n if (results.errorMessage !== undefined) {\r\n throw new Error(results.errorMessage);\r\n }\r\n }\r\n\r\n if (change.entityMixinChanges.size > 0) {\r\n const results = await merger.addMixins(targetItemKey, change.entityMixinChanges.values(), changeType);\r\n if (results.errorMessage !== undefined) {\r\n throw new Error(results.errorMessage);\r\n }\r\n }\r\n\r\n await merger.mergeAttributeValueChanges(targetItemKey, change.propertyValueChanges);\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"ClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/ClassMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAiJ;AAIjJ,+DAAgI;AAChI,+DAA4D;AAE5D;;GAEG;AACH,MAAa,WAAW;IAGtB,YAAY,OAA2B;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC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AAO,CAAC,OAAQ,CAAC;aAClC;YAED,IAAI,MAAM,CAAC,cAAc,KAAK,SAAS,EAAE;gBACvC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;gBAC5F,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;oBACtC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;iBACvC;aACF;YAED,IAAI,MAAM,CAAC,kBAAkB,CAAC,IAAI,GAAG,CAAC,EAAE;gBACtC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,aAAa,EAAE,MAAM,CAAC,kBAAkB,CAAC,MAAM,EAAE,EAAE,UAAU,CAAC,CAAC;gBACtG,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;oBACtC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;iBACvC;aACF;YAED,MAAM,MAAM,CAAC,0BAA0B,CAAC,aAAa,EAAE,MAAM,CAAC,oBAAoB,CAAC,CAAC;YACpF,MAAM,YAAY,GAAI,MAAM,yCAAmB,CAAC,YAAY,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC;YACtH,IAAI,YAAY,CAAC,YAAY,KAAK,SAAS,EAAE;gBAC3C,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;aAC5C;SACF;IACH,CAAC;CACF;AA1JD,kCA0JC","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 { ECClass, ECClassModifier, Mixin, parseClassModifier, SchemaItemKey, schemaItemTypeToString, SchemaKey } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaItemEditResults } from \"../Editing/Editor\";\r\nimport { MutableClass } from \"../Editing/Mutable/MutableClass\";\r\nimport { SchemaMergeContext } from \"./SchemaMerger\";\r\nimport { BaseClassDelta, ChangeType, ClassChanges, EntityMixinChanges, PropertyValueChange } from \"../Validation/SchemaChanges\";\r\nimport { ClassPropertyMerger } from \"./ClassPropertyMerger\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class ClassMerger<TClass extends ECClass> {\r\n protected readonly context: SchemaMergeContext;\r\n\r\n constructor(context: SchemaMergeContext) {\r\n this.context = context;\r\n }\r\n\r\n protected async create(_schemaKey: SchemaKey, ecClass: TClass): Promise<SchemaItemEditResults> {\r\n return { errorMessage: `${schemaItemTypeToString(ecClass.schemaItemType)} class type is not implemented.`};\r\n }\r\n\r\n protected async addMixin(itemKey: SchemaItemKey, mixin: Mixin): Promise<SchemaItemEditResults> {\r\n return { errorMessage: `Adding mixin '${mixin.name}' to '${itemKey.name}' class is not implemented.` };\r\n }\r\n\r\n protected async mergeAttributes(ecClass: TClass, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<SchemaItemEditResults | boolean> {\r\n const mutableClass = ecClass as unknown as MutableClass;\r\n switch(attributeName) {\r\n case \"schemaItemType\":\r\n if (attributeOldValue !== undefined && attributeOldValue !== attributeNewValue) {\r\n return { errorMessage: `Changing the class '${ecClass.name}' type is not supported.` };\r\n }\r\n return true;\r\n\r\n case \"label\":\r\n mutableClass.setDisplayLabel(attributeNewValue);\r\n return true;\r\n\r\n case \"description\":\r\n mutableClass.setDescription(attributeNewValue);\r\n return true;\r\n\r\n case \"modifier\":\r\n const modifier = parseClassModifier(attributeNewValue);\r\n if (modifier === undefined) {\r\n return { errorMessage: \"An invalid class modifier has been provided.\" };\r\n }\r\n\r\n if (attributeOldValue === undefined || modifier === ECClassModifier.None) {\r\n mutableClass.setModifier(modifier);\r\n return true;\r\n }\r\n return { errorMessage: `Changing the class '${ecClass.name}' modifier is not supported.` };\r\n }\r\n return false;\r\n }\r\n\r\n protected isSchemaItemEditResults(obj: any): obj is SchemaItemEditResults {\r\n return typeof obj === \"object\" && \"errorMessage\" in obj;\r\n }\r\n\r\n private async setBaseClass(itemKey: SchemaItemKey, baseClassDelta: BaseClassDelta, changeType?: ChangeType): Promise<SchemaItemEditResults> {\r\n const [sourceBaseClass, targetBaseClass] = baseClassDelta.diagnostic.messageArgs! as [ECClass, ECClass];\r\n if (sourceBaseClass !== undefined) {\r\n const baseClassKey = new SchemaItemKey(sourceBaseClass.name, sourceBaseClass.schema.schemaKey.matches(this.context.sourceSchema.schemaKey)\r\n ? this.context.targetSchema.schemaKey\r\n : sourceBaseClass.schema.schemaKey);\r\n\r\n if (changeType === ChangeType.Missing && targetBaseClass === undefined) {\r\n return this.context.editor.entities.setBaseClass(itemKey, baseClassKey);\r\n }\r\n\r\n if (targetBaseClass !== undefined) {\r\n const baseClass = await this.context.targetSchema.lookupItem<ECClass>(baseClassKey);\r\n if (baseClass === undefined) {\r\n return { errorMessage: `'${baseClassKey.name}' class could not be located in the merged schema.`};\r\n }\r\n if (await baseClass.is(targetBaseClass)) {\r\n return this.context.editor.entities.setBaseClass(itemKey, baseClassKey);\r\n }\r\n }\r\n }\r\n return { errorMessage: `Changing the class '${itemKey.name}' baseClass is not supported.`};\r\n }\r\n\r\n private async addMixins(itemKey: SchemaItemKey, entityMixinChanges: Iterable<EntityMixinChanges>, changeType?: ChangeType): Promise<SchemaItemEditResults> {\r\n if (changeType === ChangeType.Missing) {\r\n for (const entityMixinChange of entityMixinChanges) {\r\n for (const change of entityMixinChange.entityMixinChange) {\r\n const mixins = change.diagnostic.messageArgs! as unknown as [Mixin];\r\n for (const mixin of mixins) {\r\n const result = await this.addMixin(itemKey, mixin);\r\n if (result.errorMessage !== undefined) {\r\n return result;\r\n }\r\n }\r\n }\r\n }\r\n return {};\r\n }\r\n return { errorMessage: `Changing the class '${itemKey.name}' mixins is not supported.`};\r\n }\r\n\r\n private async mergeAttributeValueChanges(itemKey: SchemaItemKey, propertyValueChanges: PropertyValueChange[]) {\r\n if (propertyValueChanges.length === 0) {\r\n return;\r\n }\r\n\r\n const targetItem = await this.context.targetSchema.lookupItem<TClass>(itemKey);\r\n if (targetItem === undefined) {\r\n throw new Error(`'${itemKey.name}' class could not be located in the merged schema.`);\r\n }\r\n\r\n for (const change of propertyValueChanges) {\r\n const [attributeName, attributeNewValue, attributeOldValue] = change.diagnostic.messageArgs!;\r\n const results = await this.mergeAttributes(targetItem, attributeName, attributeNewValue, attributeOldValue);\r\n if (this.isSchemaItemEditResults(results) && results.errorMessage !== undefined) {\r\n throw new Error(results.errorMessage);\r\n }\r\n }\r\n }\r\n\r\n public static async mergeChanges(context: SchemaMergeContext, classChanges: Iterable<ClassChanges>) {\r\n const merger = new this(context);\r\n\r\n for (const change of classChanges) {\r\n const sourceItem = (await change.schema.getItem<ECClass>(change.ecTypeName))!;\r\n let targetItemKey = new SchemaItemKey(change.ecTypeName, context.targetSchema.schemaKey);\r\n const changeType = change.schemaItemMissing?.changeType;\r\n\r\n if (changeType === ChangeType.Missing) {\r\n\r\n if (await context.targetSchema.lookupItem<ECClass>(targetItemKey) !== undefined) {\r\n throw new Error(`Merged schema already contains a class '${change.ecTypeName}'.`);\r\n }\r\n\r\n const results = await merger.create(context.targetSchema.schemaKey, sourceItem);\r\n if (results.errorMessage !== undefined) {\r\n throw new Error(results.errorMessage);\r\n }\r\n targetItemKey = results.itemKey!;\r\n }\r\n\r\n if (change.baseClassDelta !== undefined) {\r\n const results = await merger.setBaseClass(targetItemKey, change.baseClassDelta, changeType);\r\n if (results.errorMessage !== undefined) {\r\n throw new Error(results.errorMessage);\r\n }\r\n }\r\n\r\n if (change.entityMixinChanges.size > 0) {\r\n const results = await merger.addMixins(targetItemKey, change.entityMixinChanges.values(), changeType);\r\n if (results.errorMessage !== undefined) {\r\n throw new Error(results.errorMessage);\r\n }\r\n }\r\n\r\n await merger.mergeAttributeValueChanges(targetItemKey, change.propertyValueChanges);\r\n const mergeResults = await ClassPropertyMerger.mergeChanges(context, targetItemKey, change.propertyChanges.values());\r\n if (mergeResults.errorMessage !== undefined) {\r\n throw new Error(mergeResults.errorMessage);\r\n }\r\n }\r\n }\r\n}\r\n"]}
@@ -0,0 +1,16 @@
1
+ import { SchemaItemKey } from "@itwin/ecschema-metadata";
2
+ import { PropertyEditResults, SchemaItemEditResults } from "../Editing/Editor";
3
+ import { PropertyChanges } from "../Validation/SchemaChanges";
4
+ import { SchemaMergeContext } from "./SchemaMerger";
5
+ /**
6
+ * @internal
7
+ */
8
+ export declare class ClassPropertyMerger {
9
+ protected readonly context: SchemaMergeContext;
10
+ constructor(context: SchemaMergeContext);
11
+ private getPropertyMerger;
12
+ protected isPropertyEditResults(obj: any): obj is PropertyEditResults;
13
+ private mergeAttributeValueChanges;
14
+ static mergeChanges(context: SchemaMergeContext, classKey: SchemaItemKey, propertyChanges: Iterable<PropertyChanges>): Promise<SchemaItemEditResults>;
15
+ }
16
+ //# sourceMappingURL=ClassPropertyMerger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClassPropertyMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/ClassPropertyMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAA2C,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAClG,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAc,eAAe,EAAuB,MAAM,6BAA6B,CAAC;AAC/F,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAMpD;;GAEG;AACH,qBAAa,mBAAmB;IAC9B,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;gBAEnC,OAAO,EAAE,kBAAkB;IAIvC,OAAO,CAAC,iBAAiB;IAsBzB,SAAS,CAAC,qBAAqB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,mBAAmB;YAIvD,0BAA0B;WAepB,YAAY,CAAC,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,aAAa,EAAE,eAAe,EAAE,QAAQ,CAAC,eAAe,CAAC,GAAG,OAAO,CAAC,qBAAqB,CAAC;CA2BnK"}
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClassPropertyMerger = void 0;
4
+ /*---------------------------------------------------------------------------------------------
5
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
+ * See LICENSE.md in the project root for license terms and full copyright notice.
7
+ *--------------------------------------------------------------------------------------------*/
8
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
9
+ const SchemaChanges_1 = require("../Validation/SchemaChanges");
10
+ const StructPropertyMerger_1 = require("./StructPropertyMerger");
11
+ const ArrayPropertyMerger_1 = require("./ArrayPropertyMerger");
12
+ const PrimitiveOrEnumPropertyMerger_1 = require("./PrimitiveOrEnumPropertyMerger");
13
+ /**
14
+ * @internal
15
+ */
16
+ class ClassPropertyMerger {
17
+ constructor(context) {
18
+ this.context = context;
19
+ }
20
+ getPropertyMerger(property) {
21
+ if (property.isEnumeration()) {
22
+ if (property.isArray()) {
23
+ return new ArrayPropertyMerger_1.EnumerationArrayPropertyMerger(this.context);
24
+ }
25
+ return new PrimitiveOrEnumPropertyMerger_1.EnumerationPropertyMerger(this.context);
26
+ }
27
+ if (property.isPrimitive()) {
28
+ if (property.isArray()) {
29
+ return new ArrayPropertyMerger_1.PrimitiveArraPropertyMerger(this.context);
30
+ }
31
+ return new PrimitiveOrEnumPropertyMerger_1.PrimitivePropertyMerger(this.context);
32
+ }
33
+ if (property.isStruct()) {
34
+ if (property.isArray()) {
35
+ return new ArrayPropertyMerger_1.StructArrayPropertyMerger(this.context);
36
+ }
37
+ return new StructPropertyMerger_1.StructPropertyMerger(this.context);
38
+ }
39
+ throw new Error(`Unsupported Property Type: ${(0, ecschema_metadata_1.propertyTypeToString)(property.propertyType)}`);
40
+ }
41
+ isPropertyEditResults(obj) {
42
+ return typeof obj === "object" && "errorMessage" in obj;
43
+ }
44
+ async mergeAttributeValueChanges(targetProperty, propertyValueChanges) {
45
+ if (propertyValueChanges.length === 0)
46
+ return;
47
+ const merger = this.getPropertyMerger(targetProperty);
48
+ for (const change of propertyValueChanges) {
49
+ const [attributeName, attributeNewValue, attributeOldValue] = change.diagnostic.messageArgs;
50
+ const results = await merger.mergeAttributes(targetProperty, attributeName, attributeNewValue, attributeOldValue);
51
+ if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {
52
+ throw new Error(results.errorMessage);
53
+ }
54
+ }
55
+ }
56
+ static async mergeChanges(context, classKey, propertyChanges) {
57
+ const merger = new this(context);
58
+ for (const change of propertyChanges) {
59
+ const targetItem = await context.targetSchema.lookupItem(classKey);
60
+ if (targetItem === undefined) {
61
+ return { errorMessage: `'${classKey.name}' class could not be located in the merged schema.` };
62
+ }
63
+ if (change.propertyMissing?.changeType === SchemaChanges_1.ChangeType.Missing) {
64
+ const sourceProperty = change.propertyMissing.diagnostic.ecDefinition;
65
+ if (await targetItem.getProperty(change.ecTypeName) !== undefined) {
66
+ return { errorMessage: `Merged schema already contains a class '${classKey.name}' property '${change.ecTypeName}'.` };
67
+ }
68
+ const propertyMerger = merger.getPropertyMerger(sourceProperty);
69
+ const results = await propertyMerger.createFromProps(classKey, sourceProperty);
70
+ if (results.errorMessage !== undefined) {
71
+ return { errorMessage: results.errorMessage };
72
+ }
73
+ }
74
+ else {
75
+ const targetProperty = (await targetItem.getProperty(change.ecTypeName));
76
+ await merger.mergeAttributeValueChanges(targetProperty, change.propertyValueChanges);
77
+ }
78
+ }
79
+ return {};
80
+ }
81
+ }
82
+ exports.ClassPropertyMerger = ClassPropertyMerger;
83
+ //# sourceMappingURL=ClassPropertyMerger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClassPropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/ClassPropertyMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAkG;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,MAAM,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;gBACjE,MAAM,OAAO,GAAI,MAAM,cAAc,CAAC,eAAe,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;gBAChF,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;oBACtC,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAC,CAAC;iBAC9C;aACF;iBAAM;gBACL,MAAM,cAAc,GAAG,CAAC,MAAM,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,CAAE,CAAC;gBAC1E,MAAM,MAAM,CAAC,0BAA0B,CAAC,cAAc,EAAE,MAAM,CAAC,oBAAoB,CAAC,CAAC;aACtF;SACF;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AA3ED,kDA2EC","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 { ECClass, Property, propertyTypeToString, SchemaItemKey } from \"@itwin/ecschema-metadata\";\r\nimport { PropertyEditResults, SchemaItemEditResults } from \"../Editing/Editor\";\r\nimport { ChangeType, PropertyChanges, PropertyValueChange } from \"../Validation/SchemaChanges\";\r\nimport { SchemaMergeContext } from \"./SchemaMerger\";\r\nimport { StructPropertyMerger } from \"./StructPropertyMerger\";\r\nimport { EnumerationArrayPropertyMerger, PrimitiveArraPropertyMerger, StructArrayPropertyMerger } from \"./ArrayPropertyMerger\";\r\nimport { AnyPropertyMerger } from \"./AnyPropertyMerger\";\r\nimport { EnumerationPropertyMerger, PrimitivePropertyMerger } from \"./PrimitiveOrEnumPropertyMerger\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class ClassPropertyMerger {\r\n protected readonly context: SchemaMergeContext;\r\n\r\n constructor(context: SchemaMergeContext) {\r\n this.context = context;\r\n }\r\n\r\n private getPropertyMerger(property: Property): AnyPropertyMerger<Property> {\r\n if (property.isEnumeration()) {\r\n if (property.isArray()) {\r\n return new EnumerationArrayPropertyMerger(this.context);\r\n }\r\n return new EnumerationPropertyMerger(this.context);\r\n }\r\n if (property.isPrimitive()) {\r\n if (property.isArray()) {\r\n return new PrimitiveArraPropertyMerger(this.context);\r\n }\r\n return new PrimitivePropertyMerger(this.context);\r\n }\r\n if (property.isStruct()) {\r\n if (property.isArray()) {\r\n return new StructArrayPropertyMerger(this.context);\r\n }\r\n return new StructPropertyMerger(this.context);\r\n }\r\n throw new Error(`Unsupported Property Type: ${propertyTypeToString(property.propertyType)}`);\r\n }\r\n\r\n protected isPropertyEditResults(obj: any): obj is PropertyEditResults {\r\n return typeof obj === \"object\" && \"errorMessage\" in obj;\r\n }\r\n\r\n private async mergeAttributeValueChanges(targetProperty: Property, propertyValueChanges: PropertyValueChange[]) {\r\n if (propertyValueChanges.length === 0)\r\n return;\r\n\r\n const merger = this.getPropertyMerger(targetProperty);\r\n\r\n for (const change of propertyValueChanges) {\r\n const [attributeName, attributeNewValue, attributeOldValue] = change.diagnostic.messageArgs!;\r\n const results = await merger.mergeAttributes(targetProperty, attributeName, attributeNewValue, attributeOldValue);\r\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n throw new Error(results.errorMessage);\r\n }\r\n }\r\n }\r\n\r\n public static async mergeChanges(context: SchemaMergeContext, classKey: SchemaItemKey, propertyChanges: Iterable<PropertyChanges>): Promise<SchemaItemEditResults> {\r\n const merger = new this(context);\r\n\r\n for (const change of propertyChanges) {\r\n const targetItem = await context.targetSchema.lookupItem<ECClass>(classKey);\r\n if (targetItem === undefined) {\r\n return { errorMessage: `'${classKey.name}' class could not be located in the merged schema.`};\r\n }\r\n\r\n if (change.propertyMissing?.changeType === ChangeType.Missing) {\r\n const sourceProperty = change.propertyMissing.diagnostic.ecDefinition as unknown as Property;\r\n if (await targetItem.getProperty(change.ecTypeName) !== undefined) {\r\n return { errorMessage: `Merged schema already contains a class '${classKey.name}' property '${change.ecTypeName}'.`};\r\n }\r\n\r\n const propertyMerger = merger.getPropertyMerger(sourceProperty);\r\n const results = await propertyMerger.createFromProps(classKey, sourceProperty);\r\n if (results.errorMessage !== undefined) {\r\n return { errorMessage: results.errorMessage};\r\n }\r\n } else {\r\n const targetProperty = (await targetItem.getProperty(change.ecTypeName))!;\r\n await merger.mergeAttributeValueChanges(targetProperty, change.propertyValueChanges);\r\n }\r\n }\r\n return {};\r\n }\r\n}\r\n"]}
@@ -0,0 +1,24 @@
1
+ import { EnumerationProperty, PrimitiveOrEnumPropertyBase, PrimitiveProperty, SchemaItemKey } from "@itwin/ecschema-metadata";
2
+ import { AnyPropertyMerger } from "./AnyPropertyMerger";
3
+ import { PropertyEditResults } from "../Editing/Editor";
4
+ /**
5
+ * @internal
6
+ */
7
+ declare abstract class PrimitiveOrEnumPropertyMerger<TPrimitiveOrEnumPropertyBase extends PrimitiveOrEnumPropertyBase> extends AnyPropertyMerger<TPrimitiveOrEnumPropertyBase> {
8
+ mergeAttributes(property: TPrimitiveOrEnumPropertyBase, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean>;
9
+ }
10
+ /**
11
+ * @internal
12
+ */
13
+ export declare class PrimitivePropertyMerger extends PrimitiveOrEnumPropertyMerger<PrimitiveProperty> {
14
+ createFromProps(classKey: SchemaItemKey, property: PrimitiveProperty): Promise<PropertyEditResults>;
15
+ }
16
+ /**
17
+ * @internal
18
+ */
19
+ export declare class EnumerationPropertyMerger extends PrimitiveOrEnumPropertyMerger<EnumerationProperty> {
20
+ mergeAttributes(property: EnumerationProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean>;
21
+ createFromProps(classKey: SchemaItemKey, property: EnumerationProperty): Promise<PropertyEditResults>;
22
+ }
23
+ export {};
24
+ //# sourceMappingURL=PrimitiveOrEnumPropertyMerger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrimitiveOrEnumPropertyMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/PrimitiveOrEnumPropertyMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAe,mBAAmB,EAA4B,2BAA2B,EAAE,iBAAiB,EAA0B,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC7L,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAGxD;;GAEG;AACH,uBAAe,6BAA6B,CAAC,4BAA4B,SAAS,2BAA2B,CAAE,SAAQ,iBAAiB,CAAC,4BAA4B,CAAC;IAC9I,eAAe,CAAC,QAAQ,EAAE,4BAA4B,EAAE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,EAAE,GAAG,GAAG,OAAO,CAAC,mBAAmB,GAAG,OAAO,CAAC;CA+B7L;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,6BAA6B,CAAC,iBAAiB,CAAC;IACrE,eAAe,CAAC,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAY1H;AAED;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,6BAA6B,CAAC,mBAAmB,CAAC;IACzE,eAAe,CAAC,QAAQ,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,EAAE,GAAG,GAAG,OAAO,CAAC,mBAAmB,GAAG,OAAO,CAAC;IAiB7J,eAAe,CAAC,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC;CA2B5H"}
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EnumerationPropertyMerger = exports.PrimitivePropertyMerger = void 0;
4
+ /*---------------------------------------------------------------------------------------------
5
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
+ * See LICENSE.md in the project root for license terms and full copyright notice.
7
+ *--------------------------------------------------------------------------------------------*/
8
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
9
+ const AnyPropertyMerger_1 = require("./AnyPropertyMerger");
10
+ /**
11
+ * @internal
12
+ */
13
+ class PrimitiveOrEnumPropertyMerger extends AnyPropertyMerger_1.AnyPropertyMerger {
14
+ async mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue) {
15
+ const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);
16
+ if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {
17
+ return results;
18
+ }
19
+ const mutableProperty = property;
20
+ switch (attributeName) {
21
+ case "extendedTypeName": {
22
+ mutableProperty.setExtendedTypeName(attributeNewValue);
23
+ return true;
24
+ }
25
+ case "minLength": {
26
+ mutableProperty.setMinLength(attributeNewValue);
27
+ return true;
28
+ }
29
+ case "maxLength": {
30
+ mutableProperty.setMaxLength(attributeNewValue);
31
+ return true;
32
+ }
33
+ case "minValue": {
34
+ mutableProperty.setMinValue(attributeNewValue);
35
+ return true;
36
+ }
37
+ case "maxValue": {
38
+ mutableProperty.setMaxValue(attributeNewValue);
39
+ return true;
40
+ }
41
+ }
42
+ return false;
43
+ }
44
+ }
45
+ /**
46
+ * @internal
47
+ */
48
+ class PrimitivePropertyMerger extends PrimitiveOrEnumPropertyMerger {
49
+ async createFromProps(classKey, property) {
50
+ const results = await super.getPropertyProps(property);
51
+ if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {
52
+ return results;
53
+ }
54
+ const props = {
55
+ ...property.toJSON(),
56
+ ...results,
57
+ };
58
+ return this.context.editor.entities.createPrimitivePropertyFromProps(classKey, property.name, property.primitiveType, props);
59
+ }
60
+ }
61
+ exports.PrimitivePropertyMerger = PrimitivePropertyMerger;
62
+ /**
63
+ * @internal
64
+ */
65
+ class EnumerationPropertyMerger extends PrimitiveOrEnumPropertyMerger {
66
+ async mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue) {
67
+ const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);
68
+ if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {
69
+ return results;
70
+ }
71
+ switch (attributeName) {
72
+ case "enumeration": {
73
+ if (attributeOldValue !== undefined) {
74
+ return { errorMessage: `Changing the property '${property.name}' enumeration is not supported.` };
75
+ }
76
+ return true;
77
+ }
78
+ }
79
+ return false;
80
+ }
81
+ async createFromProps(classKey, property) {
82
+ const results = await super.getPropertyProps(property);
83
+ if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {
84
+ return results;
85
+ }
86
+ if (property.enumeration === undefined) {
87
+ return { errorMessage: `Property ${property.fullName} is missing the required 'enumeration' attribute.` };
88
+ }
89
+ const enumeration = await property.enumeration;
90
+ const itemKey = new ecschema_metadata_1.SchemaItemKey(enumeration.name, this.context.sourceSchema.schemaKey.matches(enumeration.schema.schemaKey)
91
+ ? this.context.targetSchema.schemaKey
92
+ : enumeration.schema.schemaKey);
93
+ const type = await this.context.targetSchema.lookupItem(itemKey);
94
+ if (type === undefined) {
95
+ return { errorMessage: `Unable to locate the enumeration class ${enumeration.name} in the merged schema.` };
96
+ }
97
+ const props = {
98
+ ...property.toJSON(),
99
+ ...results,
100
+ typeName: type.fullName,
101
+ };
102
+ return this.context.editor.entities.createEnumerationPropertyFromProps(classKey, property.name, type, props);
103
+ }
104
+ }
105
+ exports.EnumerationPropertyMerger = EnumerationPropertyMerger;
106
+ //# sourceMappingURL=PrimitiveOrEnumPropertyMerger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrimitiveOrEnumPropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/PrimitiveOrEnumPropertyMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAA6L;AAC7L,2DAAwD;AAIxD;;GAEG;AACH,MAAe,6BAAgG,SAAQ,qCAA+C;IACpJ,KAAK,CAAC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I,QAAQ,CAAC,WAAW,KAAK,SAAS,EAAE;YACtC,OAAO,EAAE,YAAY,EAAE,YAAY,QAAQ,CAAC,QAAQ,mDAAmD,EAAE,CAAC;SAC3G;QAED,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,WAAW,CAAC;QAC/C,MAAM,OAAO,GAAG,IAAI,iCAAa,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC;YAC3H,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS;YACrC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAC/B,CAAC;QACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAc,OAAO,CAAC,CAAC;QAC9E,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,OAAO,EAAE,YAAY,EAAE,0CAA0C,WAAW,CAAC,IAAI,wBAAwB,EAAE,CAAC;SAC7G;QAED,MAAM,KAAK,GAA6B;YACtC,GAAG,QAAQ,CAAC,MAAM,EAAE;YACpB,GAAG,OAAO;YACV,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC;QACF,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kCAAkC,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAC/G,CAAC;CACF;AA7CD,8DA6CC","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 { Enumeration, EnumerationProperty, EnumerationPropertyProps, PrimitiveOrEnumPropertyBase, PrimitiveProperty, PrimitivePropertyProps, SchemaItemKey } from \"@itwin/ecschema-metadata\";\r\nimport { AnyPropertyMerger } from \"./AnyPropertyMerger\";\r\nimport { PropertyEditResults } from \"../Editing/Editor\";\r\nimport { MutablePrimitiveOrEnumPropertyBase } from \"../Editing/Mutable/MutablePrimitiveOrEnumProperty\";\r\n\r\n/**\r\n * @internal\r\n */\r\nabstract class PrimitiveOrEnumPropertyMerger<TPrimitiveOrEnumPropertyBase extends PrimitiveOrEnumPropertyBase> extends AnyPropertyMerger<TPrimitiveOrEnumPropertyBase> {\r\n public override async mergeAttributes(property: TPrimitiveOrEnumPropertyBase, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\r\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n const mutableProperty = property as unknown as MutablePrimitiveOrEnumPropertyBase;\r\n switch (attributeName) {\r\n case \"extendedTypeName\": {\r\n mutableProperty.setExtendedTypeName(attributeNewValue);\r\n return true;\r\n }\r\n case \"minLength\": {\r\n mutableProperty.setMinLength(attributeNewValue);\r\n return true;\r\n }\r\n case \"maxLength\": {\r\n mutableProperty.setMaxLength(attributeNewValue);\r\n return true;\r\n }\r\n case \"minValue\": {\r\n mutableProperty.setMinValue(attributeNewValue);\r\n return true;\r\n }\r\n case \"maxValue\": {\r\n mutableProperty.setMaxValue(attributeNewValue);\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class PrimitivePropertyMerger extends PrimitiveOrEnumPropertyMerger<PrimitiveProperty> {\r\n public override async createFromProps(classKey: SchemaItemKey, property: PrimitiveProperty): Promise<PropertyEditResults> {\r\n const results = await super.getPropertyProps(property);\r\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n const props: PrimitivePropertyProps = {\r\n ...property.toJSON(),\r\n ...results,\r\n };\r\n return this.context.editor.entities.createPrimitivePropertyFromProps(classKey, property.name, property.primitiveType, props);\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class EnumerationPropertyMerger extends PrimitiveOrEnumPropertyMerger<EnumerationProperty> {\r\n public override async mergeAttributes(property: EnumerationProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\r\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n switch (attributeName) {\r\n case \"enumeration\": {\r\n if (attributeOldValue !== undefined) {\r\n return { errorMessage: `Changing the property '${property.name}' enumeration is not supported.` };\r\n }\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n public override async createFromProps(classKey: SchemaItemKey, property: EnumerationProperty): Promise<PropertyEditResults> {\r\n const results = await super.getPropertyProps(property);\r\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n if (property.enumeration === undefined) {\r\n return { errorMessage: `Property ${property.fullName} is missing the required 'enumeration' attribute.` };\r\n }\r\n\r\n const enumeration = await property.enumeration;\r\n const itemKey = new SchemaItemKey(enumeration.name, this.context.sourceSchema.schemaKey.matches(enumeration.schema.schemaKey)\r\n ? this.context.targetSchema.schemaKey\r\n : enumeration.schema.schemaKey,\r\n );\r\n const type = await this.context.targetSchema.lookupItem<Enumeration>(itemKey);\r\n if (type === undefined) {\r\n return { errorMessage: `Unable to locate the enumeration class ${enumeration.name} in the merged schema.` };\r\n }\r\n\r\n const props: EnumerationPropertyProps = {\r\n ...property.toJSON(),\r\n ...results,\r\n typeName: type.fullName,\r\n };\r\n return this.context.editor.entities.createEnumerationPropertyFromProps(classKey, property.name, type, props);\r\n }\r\n}\r\n"]}
@@ -0,0 +1,11 @@
1
+ import { SchemaItemKey, StructProperty } from "@itwin/ecschema-metadata";
2
+ import { AnyPropertyMerger } from "./AnyPropertyMerger";
3
+ import { PropertyEditResults } from "../Editing/Editor";
4
+ /**
5
+ * @internal
6
+ */
7
+ export declare class StructPropertyMerger extends AnyPropertyMerger<StructProperty> {
8
+ mergeAttributes(property: StructProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean>;
9
+ createFromProps(classKey: SchemaItemKey, property: StructProperty): Promise<PropertyEditResults>;
10
+ }
11
+ //# sourceMappingURL=StructPropertyMerger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StructPropertyMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/StructPropertyMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAe,cAAc,EAAuB,MAAM,0BAA0B,CAAC;AAC3G,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,iBAAiB,CAAC,cAAc,CAAC;IACnD,eAAe,CAAC,QAAQ,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,EAAE,GAAG,GAAG,OAAO,CAAC,mBAAmB,GAAG,OAAO,CAAC;IAcxJ,eAAe,CAAC,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAsBvH"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StructPropertyMerger = void 0;
4
+ /*---------------------------------------------------------------------------------------------
5
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
+ * See LICENSE.md in the project root for license terms and full copyright notice.
7
+ *--------------------------------------------------------------------------------------------*/
8
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
9
+ const AnyPropertyMerger_1 = require("./AnyPropertyMerger");
10
+ /**
11
+ * @internal
12
+ */
13
+ class StructPropertyMerger extends AnyPropertyMerger_1.AnyPropertyMerger {
14
+ async mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue) {
15
+ const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);
16
+ if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {
17
+ return results;
18
+ }
19
+ switch (attributeName) {
20
+ case "structClass": {
21
+ return { errorMessage: `Changing the property '${property.name}' structClass is not supported.` };
22
+ }
23
+ }
24
+ return false;
25
+ }
26
+ async createFromProps(classKey, property) {
27
+ const results = await super.getPropertyProps(property);
28
+ if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {
29
+ return results;
30
+ }
31
+ const itemKey = new ecschema_metadata_1.SchemaItemKey(property.structClass.name, this.context.sourceSchema.schemaKey.matches(property.structClass.schema.schemaKey)
32
+ ? this.context.targetSchema.schemaKey
33
+ : property.structClass.schema.schemaKey);
34
+ const type = await this.context.targetSchema.lookupItem(itemKey);
35
+ if (type === undefined) {
36
+ return { errorMessage: `Unable to locate the struct class ${property.structClass.name} in the merged schema.` };
37
+ }
38
+ const props = {
39
+ ...property.toJSON(),
40
+ ...results,
41
+ typeName: type.fullName,
42
+ };
43
+ return this.context.editor.entities.createStructPropertyFromProps(classKey, property.name, type, props);
44
+ }
45
+ }
46
+ exports.StructPropertyMerger = StructPropertyMerger;
47
+ //# sourceMappingURL=StructPropertyMerger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StructPropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/StructPropertyMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAA2G;AAC3G,2DAAwD;AAGxD;;GAEG;AACH,MAAa,oBAAqB,SAAQ,qCAAiC;IACzD,KAAK,CAAC,eAAe,CAAC,QAAwB,EAAE,aAAqB,EAAE,iBAAsB,EAAE,iBAAsB;QACnI,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,eAAe,CAAC,QAAQ,EAAE,aA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E;YACpB,GAAG,OAAO;YACV,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC;QACF,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,6BAA6B,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAC1G,CAAC;CACF;AArCD,oDAqCC","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 { SchemaItemKey, StructClass, StructProperty, StructPropertyProps } from \"@itwin/ecschema-metadata\";\r\nimport { AnyPropertyMerger } from \"./AnyPropertyMerger\";\r\nimport { PropertyEditResults } from \"../Editing/Editor\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class StructPropertyMerger extends AnyPropertyMerger<StructProperty> {\r\n public override async mergeAttributes(property: StructProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\r\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n switch (attributeName) {\r\n case \"structClass\": {\r\n return { errorMessage: `Changing the property '${property.name}' structClass is not supported.` };\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n public override async createFromProps(classKey: SchemaItemKey, property: StructProperty): Promise<PropertyEditResults> {\r\n const results = await super.getPropertyProps(property);\r\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n const itemKey = new SchemaItemKey(property.structClass.name, this.context.sourceSchema.schemaKey.matches(property.structClass.schema.schemaKey)\r\n ? this.context.targetSchema.schemaKey\r\n : property.structClass.schema.schemaKey,\r\n );\r\n const type = await this.context.targetSchema.lookupItem<StructClass>(itemKey);\r\n if (type === undefined) {\r\n return { errorMessage: `Unable to locate the struct class ${property.structClass.name} in the merged schema.` };\r\n }\r\n\r\n const props: StructPropertyProps = {\r\n ...property.toJSON(),\r\n ...results,\r\n typeName: type.fullName,\r\n };\r\n return this.context.editor.entities.createStructPropertyFromProps(classKey, property.name, type, props);\r\n }\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/ecschema-editing",
3
- "version": "4.4.0-dev.4",
3
+ "version": "4.4.0-dev.6",
4
4
  "description": "ECSchema editing and validation API",
5
5
  "license": "MIT",
6
6
  "main": "lib/cjs/ecschema-editing.js",
@@ -22,36 +22,36 @@
22
22
  "url": "http://www.bentley.com"
23
23
  },
24
24
  "devDependencies": {
25
- "@bentley/units-schema": "^1.0.5",
25
+ "@bentley/units-schema": "^1.0.7",
26
26
  "@itwin/eslint-plugin": "4.0.0-dev.44",
27
27
  "@types/almost-equal": "1.1.0",
28
28
  "@types/benchmark": "^2.1.0",
29
29
  "@types/chai": "4.3.1",
30
30
  "@types/chai-as-promised": "^7",
31
- "@types/mocha": "^8.2.2",
31
+ "@types/mocha": "^10.0.6",
32
32
  "@types/node": "~18.16.20",
33
- "@types/sinon": "^10.0.15",
33
+ "@types/sinon": "^17.0.2",
34
34
  "@xmldom/xmldom": "~0.8.5",
35
35
  "benchmark": "^2.1.4",
36
36
  "chai": "^4.3.10",
37
- "chai-as-promised": "^7",
37
+ "chai-as-promised": "^7.1.1",
38
38
  "cpx2": "^3.0.0",
39
39
  "eslint": "^8.44.0",
40
- "mocha": "^10.0.0",
40
+ "mocha": "^10.2.0",
41
41
  "nyc": "^15.1.0",
42
42
  "rimraf": "^3.0.2",
43
- "sinon": "^15.0.4",
43
+ "sinon": "^17.0.1",
44
44
  "typescript": "~5.0.2",
45
- "@itwin/core-common": "4.4.0-dev.4",
46
- "@itwin/core-bentley": "4.4.0-dev.4",
47
- "@itwin/build-tools": "4.4.0-dev.4",
48
- "@itwin/core-quantity": "4.4.0-dev.4",
49
- "@itwin/ecschema-metadata": "4.4.0-dev.4"
45
+ "@itwin/build-tools": "4.4.0-dev.6",
46
+ "@itwin/core-quantity": "4.4.0-dev.6",
47
+ "@itwin/core-bentley": "4.4.0-dev.6",
48
+ "@itwin/core-common": "4.4.0-dev.6",
49
+ "@itwin/ecschema-metadata": "4.4.0-dev.6"
50
50
  },
51
51
  "peerDependencies": {
52
- "@itwin/core-bentley": "^4.4.0-dev.4",
53
- "@itwin/core-quantity": "^4.4.0-dev.4",
54
- "@itwin/ecschema-metadata": "^4.4.0-dev.4"
52
+ "@itwin/core-bentley": "^4.4.0-dev.6",
53
+ "@itwin/core-quantity": "^4.4.0-dev.6",
54
+ "@itwin/ecschema-metadata": "^4.4.0-dev.6"
55
55
  },
56
56
  "nyc": {
57
57
  "extends": "./node_modules/@itwin/build-tools/.nycrc"