@itwin/ecschema-editing 4.6.0-dev.9 → 4.6.1
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.
- package/CHANGELOG.md +27 -1
- package/lib/cjs/Differencing/SchemaConflicts.d.ts +14 -0
- package/lib/cjs/Differencing/SchemaConflicts.d.ts.map +1 -1
- package/lib/cjs/Differencing/SchemaConflicts.js +15 -2
- package/lib/cjs/Differencing/SchemaConflicts.js.map +1 -1
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.d.ts.map +1 -1
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js +0 -52
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js.map +1 -1
- package/lib/cjs/Differencing/SchemaDifference.d.ts +2 -2
- package/lib/cjs/Differencing/SchemaDifference.d.ts.map +1 -1
- package/lib/cjs/Differencing/SchemaDifference.js +3 -3
- package/lib/cjs/Differencing/SchemaDifference.js.map +1 -1
- package/lib/cjs/Editing/Constants.js.map +1 -1
- package/lib/cjs/Editing/CustomAttributes.d.ts +1 -1
- package/lib/cjs/Editing/CustomAttributes.d.ts.map +1 -1
- package/lib/cjs/Editing/CustomAttributes.js +2 -2
- package/lib/cjs/Editing/CustomAttributes.js.map +1 -1
- package/lib/cjs/Editing/ECClasses.d.ts +29 -23
- package/lib/cjs/Editing/ECClasses.d.ts.map +1 -1
- package/lib/cjs/Editing/ECClasses.js +51 -95
- package/lib/cjs/Editing/ECClasses.js.map +1 -1
- package/lib/cjs/Editing/Editor.js.map +1 -1
- package/lib/cjs/Editing/Entities.d.ts +6 -7
- package/lib/cjs/Editing/Entities.d.ts.map +1 -1
- package/lib/cjs/Editing/Entities.js +7 -27
- package/lib/cjs/Editing/Entities.js.map +1 -1
- package/lib/cjs/Editing/Formats.js.map +1 -1
- package/lib/cjs/Editing/KindOfQuantities.js.map +1 -1
- package/lib/cjs/Editing/Mixins.d.ts +6 -2
- package/lib/cjs/Editing/Mixins.d.ts.map +1 -1
- package/lib/cjs/Editing/Mixins.js +7 -22
- package/lib/cjs/Editing/Mixins.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableEntityClass.js +2 -2
- package/lib/cjs/Editing/Mutable/MutableEntityClass.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableNavigationProperty.d.ts +8 -0
- package/lib/cjs/Editing/Mutable/MutableNavigationProperty.d.ts.map +1 -0
- package/lib/cjs/Editing/Mutable/MutableNavigationProperty.js +16 -0
- package/lib/cjs/Editing/Mutable/MutableNavigationProperty.js.map +1 -0
- package/lib/cjs/Editing/Mutable/MutableStructProperty.d.ts +8 -0
- package/lib/cjs/Editing/Mutable/MutableStructProperty.d.ts.map +1 -0
- package/lib/cjs/Editing/Mutable/MutableStructProperty.js +16 -0
- package/lib/cjs/Editing/Mutable/MutableStructProperty.js.map +1 -0
- package/lib/cjs/Editing/Properties.d.ts +201 -0
- package/lib/cjs/Editing/Properties.d.ts.map +1 -0
- package/lib/cjs/Editing/Properties.js +349 -0
- package/lib/cjs/Editing/Properties.js.map +1 -0
- package/lib/cjs/Editing/RelationshipClasses.d.ts +12 -1
- package/lib/cjs/Editing/RelationshipClasses.d.ts.map +1 -1
- package/lib/cjs/Editing/RelationshipClasses.js +26 -3
- package/lib/cjs/Editing/RelationshipClasses.js.map +1 -1
- package/lib/cjs/Editing/Structs.d.ts +1 -1
- package/lib/cjs/Editing/Structs.d.ts.map +1 -1
- package/lib/cjs/Editing/Structs.js +2 -2
- package/lib/cjs/Editing/Structs.js.map +1 -1
- package/lib/cjs/Merging/CAClassMerger.js.map +1 -1
- package/lib/cjs/Merging/ClassMerger.js +7 -16
- package/lib/cjs/Merging/ClassMerger.js.map +1 -1
- package/lib/cjs/Merging/ConstantMerger.js.map +1 -1
- package/lib/cjs/Merging/CustomAttributeMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/CustomAttributeMerger.js +6 -1
- package/lib/cjs/Merging/CustomAttributeMerger.js.map +1 -1
- package/lib/cjs/Merging/EntityClassMerger.js.map +1 -1
- package/lib/cjs/Merging/EnumerationMerger.js.map +1 -1
- package/lib/cjs/Merging/KindOfQuantityMerger.js.map +1 -1
- package/lib/cjs/Merging/MixinMerger.js.map +1 -1
- package/lib/cjs/Merging/PhenomenonMerger.js.map +1 -1
- package/lib/cjs/Merging/PropertyCategoryMerger.js.map +1 -1
- package/lib/cjs/Merging/PropertyMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/PropertyMerger.js +54 -23
- package/lib/cjs/Merging/PropertyMerger.js.map +1 -1
- package/lib/cjs/Merging/RelationshipClassMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaItemMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.d.ts +1 -1
- package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.js +12 -8
- package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaReferenceMerger.js.map +1 -1
- package/lib/cjs/Merging/UnitSystemMerger.js.map +1 -1
- package/lib/cjs/Validation/Diagnostic.d.ts +2 -2
- package/lib/cjs/Validation/Diagnostic.d.ts.map +1 -1
- package/lib/cjs/Validation/Diagnostic.js +4 -4
- package/lib/cjs/Validation/Diagnostic.js.map +1 -1
- package/lib/cjs/Validation/DiagnosticReporter.js.map +1 -1
- package/lib/cjs/Validation/ECRules.d.ts +35 -35
- package/lib/cjs/Validation/ECRules.d.ts.map +1 -1
- package/lib/cjs/Validation/ECRules.js.map +1 -1
- package/lib/cjs/Validation/LoggingDiagnosticReporter.js.map +1 -1
- package/lib/cjs/Validation/SchemaChanges.d.ts +38 -6
- package/lib/cjs/Validation/SchemaChanges.d.ts.map +1 -1
- package/lib/cjs/Validation/SchemaChanges.js +97 -27
- package/lib/cjs/Validation/SchemaChanges.js.map +1 -1
- package/lib/cjs/Validation/SchemaCompareResultDelegate.js.map +1 -1
- package/lib/cjs/Validation/SchemaCompareVisitor.js +4 -3
- package/lib/cjs/Validation/SchemaCompareVisitor.js.map +1 -1
- package/lib/cjs/Validation/SchemaComparer.d.ts +1 -0
- package/lib/cjs/Validation/SchemaComparer.d.ts.map +1 -1
- package/lib/cjs/Validation/SchemaComparer.js +238 -260
- package/lib/cjs/Validation/SchemaComparer.js.map +1 -1
- package/lib/cjs/Validation/SchemaValidationVisitor.js.map +1 -1
- package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
- package/lib/cjs/ecschema-editing.d.ts +2 -0
- package/lib/cjs/ecschema-editing.d.ts.map +1 -1
- package/lib/cjs/ecschema-editing.js +2 -0
- package/lib/cjs/ecschema-editing.js.map +1 -1
- package/package.json +11 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ECClasses.js","sourceRoot":"","sources":["../../../src/Editing/ECClasses.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAOkC;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,KAAK,MAAM;YACf,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;QAEnE,MAAM,YAAY,GAAG,GAAG,MAAM,IAAI,IAAI,EAAE,CAAC;QAEzC,IAAI;YACF,YAAY,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC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BAChC,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;AAnbD,8BAmbC","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 DelayedPromiseWithProps,\r\n ECClass, ECName, ECObjectsError, ECObjectsStatus, Enumeration, EnumerationPropertyProps, PrimitiveArrayPropertyProps,\r\n PrimitivePropertyProps, PrimitiveType, PropertyCategory, 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 if (schema === undefined) {\r\n return { errorMessage: `Schema Key ${classKey.schemaKey.toString(true)} not found in context` };\r\n }\r\n\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 /**\r\n * Sets the Category to the Property.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param propertyName The name of the property.\r\n * @param categoryKey The SchemaItemKey of the PropertyCategory assigned to the property.\r\n */\r\n public async setPropertyCategory(classKey: SchemaItemKey, propertyName: string, categoryKey: SchemaItemKey): 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 === undefined) {\r\n return { errorMessage: `An ECProperty with the name ${propertyName} could not be found in the class ${classKey.fullName}.` };\r\n }\r\n\r\n const category = await mutableClass.schema.lookupItem<PropertyCategory>(categoryKey);\r\n if (category === undefined) {\r\n return { errorMessage: `Can't locate the Property Category ${categoryKey.fullName} in the schema ${mutableClass.schema.fullName}.` };\r\n }\r\n\r\n property.setCategory(new DelayedPromiseWithProps<SchemaItemKey, PropertyCategory>(categoryKey, async () => category));\r\n return { itemKey: classKey, propertyName };\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 if (schema === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema,`Schema Key ${classKey.schemaKey.toString(true)} not found in context`);\r\n\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 protected 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,gEAOkC;AAClC,sDAA6C;AAG7C,+CAA+C;AAC/C,6CAAyH;AAIzH;;;GAGG;AACH,MAAa,SAAS;IAEpB,YAAgC,cAAkC,EAAY,aAAkC;QAAhF,mBAAc,GAAd,cAAc,CAAoB;QAAY,kBAAa,GAAb,aAAa,CAAqB;QAEhH;;WAEG;QACa,eAAU,GAAG,IAAI,uBAAU,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QACrF;;WAEG;QACa,oBAAe,GAAG,IAAI,4BAAe,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAC/F;;WAEG;QACa,wBAAmB,GAAG,IAAI,gCAAmB,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QACvG;;WAEG;QACa,0BAAqB,GAAG,IAAI,kCAAqB,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAC3G;;WAEG;QACa,qBAAgB,GAAG,IAAI,6BAAgB,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,C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qB,CAAC,SAAwC,EAAE,eAAgC;QACxG,IAAA,qBAAM,EAAC,SAAS,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,CAAC;YACb,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC;gBACjC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;oBACzC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC7B,CAAC;YACH,CAAC;YACD,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;QACzC,CAAC;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;CACF;AA/XD,8BA+XC","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 DelayedPromiseWithProps,\r\n ECClass, 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 { ArrayProperties, EnumerationProperties, PrimitiveProperties, Properties, StructProperties } from \"./Properties\";\r\n\r\nexport type ECClassSchemaItems = SchemaItemType.EntityClass | SchemaItemType.StructClass | SchemaItemType.RelationshipClass | SchemaItemType.Mixin | SchemaItemType.CustomAttributeClass;\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 schemaItemType: ECClassSchemaItems, protected _schemaEditor: SchemaContextEditor) { }\r\n\r\n /**\r\n * Allows access for editing of base Property attributes.\r\n */\r\n public readonly properties = new Properties(this.schemaItemType, this._schemaEditor);\r\n /**\r\n * Allows access for editing of ArrayProperty attributes.\r\n */\r\n public readonly arrayProperties = new ArrayProperties(this.schemaItemType, this._schemaEditor);\r\n /**\r\n * Allows access for editing of PrimitiveProperty attributes.\r\n */\r\n public readonly primitiveProperties = new PrimitiveProperties(this.schemaItemType, this._schemaEditor);\r\n /**\r\n * Allows access for editing of EnumerationProperty attributes.\r\n */\r\n public readonly enumerationProperties = new EnumerationProperties(this.schemaItemType, this._schemaEditor);\r\n /**\r\n * Allows access for editing of StructProperty attributes.\r\n */\r\n public readonly structProperties = new StructProperties(this.schemaItemType, this._schemaEditor);\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 * 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 if (schema === undefined) {\r\n return { errorMessage: `Schema Key ${classKey.schemaKey.toString(true)} not found in context` };\r\n }\r\n\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\r\n const existingName = classKey.name;\r\n mutableClass.setName(name);\r\n\r\n // Must reset in schema item map\r\n await schema.deleteClass(existingName);\r\n schema.addItem(mutableClass);\r\n\r\n return {};\r\n }\r\n\r\n /**\r\n * Sets the base class of a SchemaItem.\r\n * @param itemKey The SchemaItemKey of the Item.\r\n * @param baseClassKey The SchemaItemKey of the base class. Specifying 'undefined' removes the base class.\r\n */\r\n public async setBaseClass(itemKey: SchemaItemKey, baseClassKey?: SchemaItemKey): Promise<SchemaItemEditResults> {\r\n const classItem = await this._schemaEditor.schemaContext.getSchemaItem<MutableClass>(itemKey);\r\n\r\n if (classItem === undefined)\r\n return { itemKey, errorMessage: `Class ${itemKey.fullName} not found in schema context.` };\r\n\r\n if (baseClassKey === undefined) {\r\n classItem.baseClass = undefined;\r\n return { itemKey };\r\n }\r\n\r\n const baseClassSchema = !baseClassKey.schemaKey.matches(itemKey.schemaKey) ? await this._schemaEditor.getSchema(baseClassKey.schemaKey) : classItem.schema;\r\n if (baseClassSchema === undefined) {\r\n return { itemKey, errorMessage: `Schema Key ${baseClassKey.schemaKey.toString(true)} not found in context` };\r\n }\r\n\r\n const baseClassItem = await baseClassSchema.lookupItem<ECClass>(baseClassKey);\r\n if (baseClassItem === undefined)\r\n return { itemKey, errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };\r\n\r\n if (baseClassItem.schemaItemType !== classItem.schemaItemType)\r\n return { itemKey, errorMessage: `${baseClassItem.fullName} is not of type ${classItem.schemaItemType}.` };\r\n\r\n if (classItem.baseClass !== undefined && !await baseClassItem.is(await classItem.baseClass))\r\n return { itemKey, errorMessage: `Baseclass ${baseClassItem.fullName} must derive from ${classItem.baseClass.fullName}.`};\r\n\r\n classItem.baseClass = new DelayedPromiseWithProps<SchemaItemKey, ECClass>(baseClassKey, async () => baseClassItem);\r\n return { itemKey };\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 if (schema === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema,`Schema Key ${classKey.schemaKey.toString(true)} not found in context`);\r\n\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 protected 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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Editor.js","sourceRoot":"","sources":["../../../src/Editing/Editor.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+CAA+C;AAC/C,gEAA6H;AAE7H,sDAA6C;AAC7C,2CAAwC;AACxC,yDAAsD;AACtD,yCAAsC;AACtC,iDAA8C;AAC9C,uCAAoC;AACpC,mDAAgD;AAChD,yDAAsD;AACtD,qCAAkC;AAClC,2CAAwC;AACxC,6DAA0D;AAC1D,+DAA4D;AAC5D,uCAAoC;AACpC,mCAAgC;AAChC,+CAA4C;AAC5C,+CAA4C;AA6B5C;;;GAGG;AACH,MAAa,mBAAmB;IAoB9B;;;OAGG;IACH,YAAY,aAA4B;QAtBxB,aAAQ,GAAG,IAAI,mBAAQ,CAAC,IAAI,CAAC,CAAC;QAC9B,WAAM,GAAG,IAAI,eAAM,CAAC,IAAI,CAAC,CAAC;QAC1B,YAAO,GAAG,IAAI,iBAAO,CAAC,IAAI,CAAC,CAAC;QAC5B,qBAAgB,GAAG,IAAI,mCAAgB,CAAC,IAAI,CAAC,CAAC;QAC9C,kBAAa,GAAG,IAAI,yCAAmB,CAAC,IAAI,CAAC,CAAC;QAC9C,cAAS,GAAG,IAAI,qBAAS,CAAC,IAAI,CAAC,CAAC;QAChC,iBAAY,GAAG,IAAI,2BAAY,CAAC,IAAI,CAAC,CAAC;QACtC,YAAO,GAAG,IAAI,iBAAO,CAAC,IAAI,CAAC,CAAC;QAC5B,qBAAgB,GAAG,IAAI,mCAAgB,CAAC,IAAI,CAAC,CAAC;QAC9C,UAAK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AC,CAAC;QAC7F,IAAI,MAAM,KAAK,SAAS;YACtB,OAAO,EAAE,YAAY,EAAE,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAEzF,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;QACpF,OAAO,EAAE,CAAC;IACZ,CAAC;IAEO,eAAe,CAAC,MAAc,EAAE,SAAiB;QACvD,MAAM,KAAK,GAAW,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC3D,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;YAChB,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;SACpC;IACH,CAAC;IAEO,qBAAqB,CAAC,MAAc,EAAE,eAAgC;QAC5E,IAAA,qBAAM,EAAC,MAAM,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC;QAC9C,MAAM,GAAG,GAAG,MAAM,CAAC,gBAAgD,CAAC;QACpE,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;CACF;AAhKD,kDAgKC","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 * as Rules from \"../Validation/ECRules\";\r\nimport { CustomAttribute, Schema, SchemaContext, SchemaItemKey, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\r\nimport { MutableSchema } from \"./Mutable/MutableSchema\";\r\nimport { assert } from \"@itwin/core-bentley\";\r\nimport { Constants } from \"./Constants\";\r\nimport { CustomAttributes } from \"./CustomAttributes\";\r\nimport { Entities } from \"./Entities\";\r\nimport { Enumerations } from \"./Enumerations\";\r\nimport { Formats } from \"./Formats\";\r\nimport { InvertedUnits } from \"./InvertedUnits\";\r\nimport { KindOfQuantities } from \"./KindOfQuantities\";\r\nimport { Mixins } from \"./Mixins\";\r\nimport { Phenomena } from \"./Phenomena\";\r\nimport { PropertyCategories } from \"./PropertyCategories\";\r\nimport { RelationshipClasses } from \"./RelationshipClasses\";\r\nimport { Structs } from \"./Structs\";\r\nimport { Units } from \"./Units\";\r\nimport { UnitSystems } from \"./UnitSystems\";\r\nimport { SchemaItems } from \"./SchemaItems\";\r\n\r\n// We can either add validation in Editor, or in the protected methods of Schema.\r\n// TODO: Add an error code so we can do something programmatic with the error.\r\n/**\r\n * @alpha\r\n */\r\nexport interface SchemaEditResults {\r\n schemaKey?: SchemaKey;\r\n errorMessage?: string;\r\n}\r\n\r\n/**\r\n * @alpha\r\n */\r\nexport interface SchemaItemEditResults {\r\n itemKey?: SchemaItemKey;\r\n errorMessage?: string;\r\n}\r\n\r\n/**\r\n * @alpha\r\n */\r\nexport interface PropertyEditResults {\r\n itemKey?: SchemaItemKey;\r\n propertyName?: string;\r\n errorMessage?: string;\r\n}\r\n\r\n/**\r\n * A class that allows you to edit and create schemas, classes, and items from the SchemaContext level.\r\n * @alpha\r\n */\r\nexport class SchemaContextEditor {\r\n private _schemaContext: SchemaContext;\r\n public readonly entities = new Entities(this);\r\n public readonly mixins = new Mixins(this);\r\n public readonly structs = new Structs(this);\r\n public readonly customAttributes = new CustomAttributes(this);\r\n public readonly relationships = new RelationshipClasses(this);\r\n public readonly constants = new Constants(this);\r\n public readonly enumerations = new Enumerations(this);\r\n public readonly formats = new Formats(this);\r\n public readonly kindOfQuantities = new KindOfQuantities(this);\r\n public readonly units = new Units(this);\r\n public readonly phenomenons = new Phenomena(this);\r\n public readonly unitSystems = new UnitSystems(this);\r\n public readonly propertyCategories = new PropertyCategories(this);\r\n public readonly invertedUnits = new InvertedUnits(this);\r\n\r\n /** @internal */\r\n public readonly schemaItems = new SchemaItems(this);\r\n\r\n /**\r\n * Creates a new SchemaContextEditor instance.\r\n * @param schemaContext The SchemaContext the Editor will use to edit in.\r\n */\r\n constructor(schemaContext: SchemaContext) {\r\n // TODO: Make copy\r\n this._schemaContext = schemaContext;\r\n }\r\n\r\n /** Allows you to get schema classes and items through regular SchemaContext methods. */\r\n public get schemaContext(): SchemaContext { return this._schemaContext; }\r\n\r\n public async finish(): Promise<SchemaContext> {\r\n return this._schemaContext;\r\n }\r\n\r\n /**\r\n * Helper method for retrieving a schema, previously added, from the SchemaContext.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n */\r\n public async getSchema(schemaKey: SchemaKey): Promise<MutableSchema | undefined> {\r\n const schema = (await this.schemaContext.getCachedSchema<MutableSchema>(schemaKey, SchemaMatchType.Latest));\r\n if (schema === undefined)\r\n return undefined;\r\n\r\n return schema;\r\n }\r\n /**\r\n * Creates a Schema with the given properties and adds it to the current schema context.\r\n * @param name The name given to the new schema.\r\n * @param alias The alias of the new schema.\r\n * @param readVersion The read version number of the schema.\r\n * @param writeVersion The write version number of the schema.\r\n * @param minorVersion The minor version number of the schema.\r\n * @returns Resolves to a SchemaEditResults object.\r\n */\r\n public async createSchema(name: string, alias: string, readVersion: number, writeVersion: number, minorVersion: number): Promise<SchemaEditResults> {\r\n const newSchema = new Schema(this._schemaContext, name, alias, readVersion, writeVersion, minorVersion);\r\n await this._schemaContext.addSchema(newSchema);\r\n return { schemaKey: newSchema.schemaKey };\r\n }\r\n\r\n /**\r\n * Adds a referenced schema to the schema identified by the given SchemaKey.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @param refSchema The referenced schema to add.\r\n */\r\n public async addSchemaReference(schemaKey: SchemaKey, refSchema: Schema): Promise<SchemaEditResults> {\r\n const schema = (await this.schemaContext.getCachedSchema<MutableSchema>(schemaKey, SchemaMatchType.Exact));\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n await schema.addReference(refSchema);\r\n const diagnostics = Rules.validateSchemaReferences(schema);\r\n\r\n const result: SchemaEditResults = { 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.removeReference(schema, refSchema);\r\n return result;\r\n }\r\n\r\n if (!await this.schemaContext.getCachedSchema(refSchema.schemaKey)) {\r\n await this.schemaContext.addSchema(refSchema);\r\n }\r\n\r\n return {};\r\n }\r\n\r\n /**\r\n * Adds a CustomAttribute instance to the schema identified by the given SchemaKey\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @param customAttribute The CustomAttribute instance to add.\r\n */\r\n public async addCustomAttribute(schemaKey: SchemaKey, customAttribute: CustomAttribute): Promise<SchemaEditResults> {\r\n const schema = (await this.schemaContext.getCachedSchema<MutableSchema>(schemaKey, SchemaMatchType.Latest));\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n schema.addCustomAttribute(customAttribute);\r\n\r\n const diagnostics = Rules.validateCustomAttributeInstance(schema, customAttribute);\r\n\r\n const result: SchemaEditResults = { 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(schema, customAttribute);\r\n return result;\r\n }\r\n\r\n return {};\r\n }\r\n\r\n /**\r\n * Sets the schema version.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @param readVersion The read version of the schema. If not specified, the existing read version will be maintained.\r\n * @param writeVersion The write version of the schema. If not specified, the existing write version will be maintained.\r\n * @param minorVersion The minor version of the schema. If not specified, the existing minor version will be maintained.\r\n */\r\n public async setVersion(schemaKey: SchemaKey, readVersion?: number, writeVersion?: number, minorVersion?: number): Promise<SchemaEditResults> {\r\n const schema = (await this.schemaContext.getCachedSchema(schemaKey, SchemaMatchType.Latest));\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n schema.setVersion(readVersion || schema.readVersion, writeVersion || schema.writeVersion, minorVersion || schema.minorVersion);\r\n return {};\r\n }\r\n\r\n /**\r\n * Increments the minor version of a schema.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n */\r\n public async incrementMinorVersion(schemaKey: SchemaKey): Promise<SchemaEditResults> {\r\n const schema = (await this.schemaContext.getCachedSchema(schemaKey, SchemaMatchType.Latest));\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n schema.setVersion(schema.readVersion, schema.writeVersion, schema.minorVersion + 1);\r\n return {};\r\n }\r\n\r\n private removeReference(schema: Schema, refSchema: Schema) {\r\n const index: number = schema.references.indexOf(refSchema);\r\n if (index !== -1) {\r\n schema.references.splice(index, 1);\r\n }\r\n }\r\n\r\n private removeCustomAttribute(schema: Schema, customAttribute: CustomAttribute) {\r\n assert(schema.customAttributes !== undefined);\r\n const map = schema.customAttributes as Map<string, CustomAttribute>;\r\n map.delete(customAttribute.className);\r\n }\r\n}\r\n\r\n"]}
|
|
1
|
+
{"version":3,"file":"Editor.js","sourceRoot":"","sources":["../../../src/Editing/Editor.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+CAA+C;AAC/C,gEAA6H;AAE7H,sDAA6C;AAC7C,2CAAwC;AACxC,yDAAsD;AACtD,yCAAsC;AACtC,iDAA8C;AAC9C,uCAAoC;AACpC,mDAAgD;AAChD,yDAAsD;AACtD,qCAAkC;AAClC,2CAAwC;AACxC,6DAA0D;AAC1D,+DAA4D;AAC5D,uCAAoC;AACpC,mCAAgC;AAChC,+CAA4C;AAC5C,+CAA4C;AA6B5C;;;GAGG;AACH,MAAa,mBAAmB;IAoB9B;;;OAGG;IACH,YAAY,aAA4B;QAtBxB,aAAQ,GAAG,IAAI,mBAA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AAM,GAAG,GAAG,MAAM,CAAC,gBAAgD,CAAC;QACpE,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;CACF;AAhKD,kDAgKC","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 * as Rules from \"../Validation/ECRules\";\r\nimport { CustomAttribute, Schema, SchemaContext, SchemaItemKey, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\r\nimport { MutableSchema } from \"./Mutable/MutableSchema\";\r\nimport { assert } from \"@itwin/core-bentley\";\r\nimport { Constants } from \"./Constants\";\r\nimport { CustomAttributes } from \"./CustomAttributes\";\r\nimport { Entities } from \"./Entities\";\r\nimport { Enumerations } from \"./Enumerations\";\r\nimport { Formats } from \"./Formats\";\r\nimport { InvertedUnits } from \"./InvertedUnits\";\r\nimport { KindOfQuantities } from \"./KindOfQuantities\";\r\nimport { Mixins } from \"./Mixins\";\r\nimport { Phenomena } from \"./Phenomena\";\r\nimport { PropertyCategories } from \"./PropertyCategories\";\r\nimport { RelationshipClasses } from \"./RelationshipClasses\";\r\nimport { Structs } from \"./Structs\";\r\nimport { Units } from \"./Units\";\r\nimport { UnitSystems } from \"./UnitSystems\";\r\nimport { SchemaItems } from \"./SchemaItems\";\r\n\r\n// We can either add validation in Editor, or in the protected methods of Schema.\r\n// TODO: Add an error code so we can do something programmatic with the error.\r\n/**\r\n * @alpha\r\n */\r\nexport interface SchemaEditResults {\r\n schemaKey?: SchemaKey;\r\n errorMessage?: string;\r\n}\r\n\r\n/**\r\n * @alpha\r\n */\r\nexport interface SchemaItemEditResults {\r\n itemKey?: SchemaItemKey;\r\n errorMessage?: string;\r\n}\r\n\r\n/**\r\n * @alpha\r\n */\r\nexport interface PropertyEditResults {\r\n itemKey?: SchemaItemKey;\r\n propertyName?: string;\r\n errorMessage?: string;\r\n}\r\n\r\n/**\r\n * A class that allows you to edit and create schemas, classes, and items from the SchemaContext level.\r\n * @alpha\r\n */\r\nexport class SchemaContextEditor {\r\n private _schemaContext: SchemaContext;\r\n public readonly entities = new Entities(this);\r\n public readonly mixins = new Mixins(this);\r\n public readonly structs = new Structs(this);\r\n public readonly customAttributes = new CustomAttributes(this);\r\n public readonly relationships = new RelationshipClasses(this);\r\n public readonly constants = new Constants(this);\r\n public readonly enumerations = new Enumerations(this);\r\n public readonly formats = new Formats(this);\r\n public readonly kindOfQuantities = new KindOfQuantities(this);\r\n public readonly units = new Units(this);\r\n public readonly phenomenons = new Phenomena(this);\r\n public readonly unitSystems = new UnitSystems(this);\r\n public readonly propertyCategories = new PropertyCategories(this);\r\n public readonly invertedUnits = new InvertedUnits(this);\r\n\r\n /** @internal */\r\n public readonly schemaItems = new SchemaItems(this);\r\n\r\n /**\r\n * Creates a new SchemaContextEditor instance.\r\n * @param schemaContext The SchemaContext the Editor will use to edit in.\r\n */\r\n constructor(schemaContext: SchemaContext) {\r\n // TODO: Make copy\r\n this._schemaContext = schemaContext;\r\n }\r\n\r\n /** Allows you to get schema classes and items through regular SchemaContext methods. */\r\n public get schemaContext(): SchemaContext { return this._schemaContext; }\r\n\r\n public async finish(): Promise<SchemaContext> {\r\n return this._schemaContext;\r\n }\r\n\r\n /**\r\n * Helper method for retrieving a schema, previously added, from the SchemaContext.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n */\r\n public async getSchema(schemaKey: SchemaKey): Promise<MutableSchema | undefined> {\r\n const schema = (await this.schemaContext.getCachedSchema<MutableSchema>(schemaKey, SchemaMatchType.Latest));\r\n if (schema === undefined)\r\n return undefined;\r\n\r\n return schema;\r\n }\r\n /**\r\n * Creates a Schema with the given properties and adds it to the current schema context.\r\n * @param name The name given to the new schema.\r\n * @param alias The alias of the new schema.\r\n * @param readVersion The read version number of the schema.\r\n * @param writeVersion The write version number of the schema.\r\n * @param minorVersion The minor version number of the schema.\r\n * @returns Resolves to a SchemaEditResults object.\r\n */\r\n public async createSchema(name: string, alias: string, readVersion: number, writeVersion: number, minorVersion: number): Promise<SchemaEditResults> {\r\n const newSchema = new Schema(this._schemaContext, name, alias, readVersion, writeVersion, minorVersion);\r\n await this._schemaContext.addSchema(newSchema);\r\n return { schemaKey: newSchema.schemaKey };\r\n }\r\n\r\n /**\r\n * Adds a referenced schema to the schema identified by the given SchemaKey.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @param refSchema The referenced schema to add.\r\n */\r\n public async addSchemaReference(schemaKey: SchemaKey, refSchema: Schema): Promise<SchemaEditResults> {\r\n const schema = (await this.schemaContext.getCachedSchema<MutableSchema>(schemaKey, SchemaMatchType.Exact));\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n await schema.addReference(refSchema);\r\n const diagnostics = Rules.validateSchemaReferences(schema);\r\n\r\n const result: SchemaEditResults = { 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.removeReference(schema, refSchema);\r\n return result;\r\n }\r\n\r\n if (!await this.schemaContext.getCachedSchema(refSchema.schemaKey)) {\r\n await this.schemaContext.addSchema(refSchema);\r\n }\r\n\r\n return {};\r\n }\r\n\r\n /**\r\n * Adds a CustomAttribute instance to the schema identified by the given SchemaKey\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @param customAttribute The CustomAttribute instance to add.\r\n */\r\n public async addCustomAttribute(schemaKey: SchemaKey, customAttribute: CustomAttribute): Promise<SchemaEditResults> {\r\n const schema = (await this.schemaContext.getCachedSchema<MutableSchema>(schemaKey, SchemaMatchType.Latest));\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n schema.addCustomAttribute(customAttribute);\r\n\r\n const diagnostics = Rules.validateCustomAttributeInstance(schema, customAttribute);\r\n\r\n const result: SchemaEditResults = { 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(schema, customAttribute);\r\n return result;\r\n }\r\n\r\n return {};\r\n }\r\n\r\n /**\r\n * Sets the schema version.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @param readVersion The read version of the schema. If not specified, the existing read version will be maintained.\r\n * @param writeVersion The write version of the schema. If not specified, the existing write version will be maintained.\r\n * @param minorVersion The minor version of the schema. If not specified, the existing minor version will be maintained.\r\n */\r\n public async setVersion(schemaKey: SchemaKey, readVersion?: number, writeVersion?: number, minorVersion?: number): Promise<SchemaEditResults> {\r\n const schema = (await this.schemaContext.getCachedSchema(schemaKey, SchemaMatchType.Latest));\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n schema.setVersion(readVersion || schema.readVersion, writeVersion || schema.writeVersion, minorVersion || schema.minorVersion);\r\n return {};\r\n }\r\n\r\n /**\r\n * Increments the minor version of a schema.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n */\r\n public async incrementMinorVersion(schemaKey: SchemaKey): Promise<SchemaEditResults> {\r\n const schema = (await this.schemaContext.getCachedSchema(schemaKey, SchemaMatchType.Latest));\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n schema.setVersion(schema.readVersion, schema.writeVersion, schema.minorVersion + 1);\r\n return {};\r\n }\r\n\r\n private removeReference(schema: Schema, refSchema: Schema) {\r\n const index: number = schema.references.indexOf(refSchema);\r\n if (index !== -1) {\r\n schema.references.splice(index, 1);\r\n }\r\n }\r\n\r\n private removeCustomAttribute(schema: Schema, customAttribute: CustomAttribute) {\r\n assert(schema.customAttributes !== undefined);\r\n const map = schema.customAttributes as Map<string, CustomAttribute>;\r\n map.delete(customAttribute.className);\r\n }\r\n}\r\n\r\n"]}
|
|
@@ -4,12 +4,17 @@
|
|
|
4
4
|
import { ECClassModifier, EntityClassProps, Mixin, NavigationPropertyProps, RelationshipClass, SchemaItemKey, SchemaKey, StrengthDirection } from "@itwin/ecschema-metadata";
|
|
5
5
|
import { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from "./Editor";
|
|
6
6
|
import { ECClasses } from "./ECClasses";
|
|
7
|
+
import { NavigationProperties } from "./Properties";
|
|
7
8
|
/**
|
|
8
9
|
* @alpha
|
|
9
10
|
* A class extending ECClasses allowing you to create schema items of type EntityClass.
|
|
10
11
|
*/
|
|
11
12
|
export declare class Entities extends ECClasses {
|
|
12
|
-
constructor(
|
|
13
|
+
constructor(schemaEditor: SchemaContextEditor);
|
|
14
|
+
/**
|
|
15
|
+
* Allows access for editing of NavigationProperty attributes.
|
|
16
|
+
*/
|
|
17
|
+
readonly navigationProperties: NavigationProperties;
|
|
13
18
|
createElement(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemEditResults>;
|
|
14
19
|
createElementUniqueAspect(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemEditResults>;
|
|
15
20
|
createElementMultiAspect(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemEditResults>;
|
|
@@ -28,11 +33,5 @@ export declare class Entities extends ECClasses {
|
|
|
28
33
|
* @param navigationProps a json object that will be used to populate the new Navigation Property.
|
|
29
34
|
*/
|
|
30
35
|
createNavigationPropertyFromProps(classKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<PropertyEditResults>;
|
|
31
|
-
/**
|
|
32
|
-
* Sets the base class of an Entity.
|
|
33
|
-
* @param entityKey The SchemaItemKey of the Entity.
|
|
34
|
-
* @param baseClassKey The SchemaItemKey of the base class. Specifying 'undefined' removes the base class.
|
|
35
|
-
*/
|
|
36
|
-
setBaseClass(entityKey: SchemaItemKey, baseClassKey?: SchemaItemKey): Promise<SchemaItemEditResults>;
|
|
37
36
|
}
|
|
38
37
|
//# sourceMappingURL=Entities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Entities.d.ts","sourceRoot":"","sources":["../../../src/Editing/Entities.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EACoB,eAAe,EAAgD,gBAAgB,EACxG,KAAK,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,aAAa,EAAkB,SAAS,EAAE,iBAAiB,EAC/G,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAC3F,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Entities.d.ts","sourceRoot":"","sources":["../../../src/Editing/Entities.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EACoB,eAAe,EAAgD,gBAAgB,EACxG,KAAK,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,aAAa,EAAkB,SAAS,EAAE,iBAAiB,EAC/G,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAC3F,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD;;;GAGG;AACH,qBAAa,QAAS,SAAQ,SAAS;gBAClB,YAAY,EAAE,mBAAmB;IAIpD;;OAEG;IACH,SAAgB,oBAAoB,uBAAqE;IAE5F,aAAa,CAAC,SAAS,EAAE,SAAS,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AQ,EAAE,aAAa,EAAE,eAAe,EAAE,uBAAuB,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAahJ"}
|
|
@@ -10,13 +10,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
exports.Entities = void 0;
|
|
11
11
|
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
12
12
|
const ECClasses_1 = require("./ECClasses");
|
|
13
|
+
const Properties_1 = require("./Properties");
|
|
13
14
|
/**
|
|
14
15
|
* @alpha
|
|
15
16
|
* A class extending ECClasses allowing you to create schema items of type EntityClass.
|
|
16
17
|
*/
|
|
17
18
|
class Entities extends ECClasses_1.ECClasses {
|
|
18
|
-
constructor(
|
|
19
|
-
super(
|
|
19
|
+
constructor(schemaEditor) {
|
|
20
|
+
super(ecschema_metadata_1.SchemaItemType.EntityClass, schemaEditor);
|
|
21
|
+
/**
|
|
22
|
+
* Allows access for editing of NavigationProperty attributes.
|
|
23
|
+
*/
|
|
24
|
+
this.navigationProperties = new Properties_1.NavigationProperties(this.schemaItemType, this._schemaEditor);
|
|
20
25
|
}
|
|
21
26
|
async createElement(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
|
|
22
27
|
const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);
|
|
@@ -136,31 +141,6 @@ class Entities extends ECClasses_1.ECClasses {
|
|
|
136
141
|
await navigationProperty.fromJSON(navigationProps);
|
|
137
142
|
return { itemKey: classKey, propertyName: navigationProps.name };
|
|
138
143
|
}
|
|
139
|
-
/**
|
|
140
|
-
* Sets the base class of an Entity.
|
|
141
|
-
* @param entityKey The SchemaItemKey of the Entity.
|
|
142
|
-
* @param baseClassKey The SchemaItemKey of the base class. Specifying 'undefined' removes the base class.
|
|
143
|
-
*/
|
|
144
|
-
async setBaseClass(entityKey, baseClassKey) {
|
|
145
|
-
const entity = (await this._schemaEditor.schemaContext.getSchemaItem(entityKey));
|
|
146
|
-
if (entity === undefined)
|
|
147
|
-
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.ClassNotFound, `Entity Class ${entityKey.fullName} not found in schema context.`);
|
|
148
|
-
if (baseClassKey === undefined) {
|
|
149
|
-
entity.baseClass = undefined;
|
|
150
|
-
return { itemKey: entityKey };
|
|
151
|
-
}
|
|
152
|
-
const baseClassSchema = !baseClassKey.schemaKey.matches(entityKey.schemaKey) ? await this._schemaEditor.getSchema(baseClassKey.schemaKey) : entity.schema;
|
|
153
|
-
if (baseClassSchema === undefined) {
|
|
154
|
-
return { errorMessage: `Schema Key ${baseClassKey.schemaKey.toString(true)} not found in context` };
|
|
155
|
-
}
|
|
156
|
-
const baseClassItem = await baseClassSchema.lookupItem(baseClassKey);
|
|
157
|
-
if (baseClassItem === undefined)
|
|
158
|
-
return { errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };
|
|
159
|
-
if (baseClassItem.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
|
|
160
|
-
return { errorMessage: `${baseClassItem.fullName} is not of type Entity Class.` };
|
|
161
|
-
entity.baseClass = new ecschema_metadata_1.DelayedPromiseWithProps(baseClassKey, async () => baseClassItem);
|
|
162
|
-
return { itemKey: entityKey };
|
|
163
|
-
}
|
|
164
144
|
}
|
|
165
145
|
exports.Entities = Entities;
|
|
166
146
|
//# sourceMappingURL=Entities.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Entities.js","sourceRoot":"","sources":["../../../src/Editing/Entities.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAGkC;AAElC,2CAAwC;AAGxC;;;GAGG;AACH,MAAa,QAAS,SAAQ,qBAAS;IACrC,YAAmB,aAAkC;QACnD,KAAK,CAAC,aAAa,CAAC,CAAC;IACvB,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,SAAoB,EAAE,IAAY,EAAE,QAAyB,EAAE,YAA2B,EAAE,YAAqB,EAAE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,IAAI,YAAY,KAAK,SAAS,EAAE;YAC9B,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;YAC7B,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;SAC/B;QAED,MAAM,eAAe,GAAG,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;QAC1J,IAAI,eAAe,KAAK,SAAS,EAAE;YACjC,OAAO,EAAE,YAAY,EAAE,cAAc,YAAY,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC;SACrG;QAED,MAAM,aAAa,GAAG,MAAM,eAAe,CAAC,UAAU,CAAc,YAAY,CAAC,CAAC;QAClF,IAAI,aAAa,KAAK,SAAS;YAC7B,OAAO,EAAE,YAAY,EAAE,+BAA+B,YAAY,CAAC,QAAQ,cAAc,eAAe,CAAC,QAAQ,GAAG,EAAE,CAAC;QAEzH,IAAI,aAAa,CAAC,cAAc,KAAK,kCAAc,CAAC,WAAW;YAC7D,OAAO,EAAE,YAAY,EAAE,GAAG,aAAa,CAAC,QAAQ,+BAA+B,EAAE,CAAC;QAEpF,MAAM,CAAC,SAAS,GAAG,IAAI,2CAAuB,CAA6B,YAAY,EAAE,KAAK,IAAI,EAAE,CAAC,aAAa,CAAC,CAAC;QACpH,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;IAChC,CAAC;CACF;AA/LD,4BA+LC","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 DelayedPromiseWithProps, ECClassModifier, ECObjectsError, ECObjectsStatus, EntityClass, EntityClassProps,\r\n Mixin, NavigationPropertyProps, RelationshipClass, SchemaItemKey, SchemaItemType, SchemaKey, StrengthDirection,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\r\nimport { ECClasses } from \"./ECClasses\";\r\nimport { MutableEntityClass } from \"./Mutable/MutableEntityClass\";\r\n\r\n/**\r\n * @alpha\r\n * A class extending ECClasses allowing you to create schema items of type EntityClass.\r\n */\r\nexport class Entities extends ECClasses {\r\n public constructor(_schemaEditor: SchemaContextEditor) {\r\n super(_schemaEditor);\r\n }\r\n\r\n public async createElement(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemEditResults> {\r\n const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);\r\n if (!baseClass)\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could not be found.`);\r\n\r\n if (baseClass?.schemaItemType !== SchemaItemType.EntityClass)\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);\r\n\r\n if (!(await (baseClass as EntityClass).is(\"Element\", \"BisCore\"))) {\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an Element.`);\r\n }\r\n\r\n return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);\r\n }\r\n\r\n public async createElementUniqueAspect(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemEditResults> {\r\n const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);\r\n if (!baseClass)\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could not be found.`);\r\n\r\n if (baseClass?.schemaItemType !== SchemaItemType.EntityClass)\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);\r\n\r\n if (!(await (baseClass as EntityClass).is(\"ElementUniqueAspect\", \"BisCore\"))) {\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an ElementUniqueAspect.`);\r\n }\r\n\r\n return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);\r\n }\r\n\r\n public async createElementMultiAspect(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemEditResults> {\r\n const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);\r\n if (!baseClass)\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could be found.`);\r\n\r\n if (baseClass?.schemaItemType !== SchemaItemType.EntityClass)\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);\r\n\r\n if (!(await (baseClass as EntityClass).is(\"ElementMultiAspect\", \"BisCore\"))) {\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an ElementMultiAspect.`);\r\n }\r\n\r\n return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);\r\n }\r\n\r\n public async create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, displayLabel?: string, baseClassKey?: SchemaItemKey, mixins?: Mixin[]): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n const newClass = (await schema.createEntityClass(name, modifier)) as MutableEntityClass;\r\n if (newClass === undefined)\r\n return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };\r\n\r\n // Add a deserializing method.\r\n if (baseClassKey !== undefined) {\r\n const baseClassSchema = !baseClassKey.schemaKey.matches(schema.schemaKey) ? await this._schemaEditor.getSchema(baseClassKey.schemaKey) : schema;\r\n if (baseClassSchema === undefined) {\r\n return { errorMessage: `Schema Key ${baseClassKey.schemaKey.toString(true)} not found in context` };\r\n }\r\n\r\n const baseClassItem = await baseClassSchema.lookupItem<EntityClass>(baseClassKey);\r\n if (baseClassItem === undefined)\r\n return { errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };\r\n\r\n if (baseClassItem.schemaItemType !== SchemaItemType.EntityClass)\r\n return { errorMessage: `${baseClassItem.fullName} is not of type Entity Class.` };\r\n\r\n newClass.baseClass = new DelayedPromiseWithProps<SchemaItemKey, EntityClass>(baseClassKey, async () => baseClassItem);\r\n }\r\n\r\n if (mixins !== undefined)\r\n mixins.forEach((m) => newClass.addMixin(m));\r\n\r\n if (displayLabel)\r\n newClass.setDisplayLabel(displayLabel);\r\n\r\n return { itemKey: newClass.key };\r\n }\r\n\r\n /**\r\n * Creates an EntityClass through an EntityClassProps.\r\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\r\n * @param entityProps a json object that will be used to populate the new EntityClass. Needs a name value passed in.\r\n */\r\n public async createFromProps(schemaKey: SchemaKey, entityProps: EntityClassProps): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n if (entityProps.name === undefined)\r\n return { errorMessage: `No name was supplied within props.` };\r\n\r\n const newClass = (await schema.createEntityClass(entityProps.name)) as MutableEntityClass;\r\n if (newClass === undefined)\r\n return { errorMessage: `Failed to create class ${entityProps.name} in schema ${schemaKey.toString(true)}.` };\r\n\r\n await newClass.fromJSON(entityProps);\r\n\r\n return { itemKey: newClass.key };\r\n }\r\n\r\n public async addMixin(entityKey: SchemaItemKey, mixinKey: SchemaItemKey): Promise<SchemaItemEditResults> {\r\n const entity = (await this._schemaEditor.schemaContext.getSchemaItem<MutableEntityClass>(entityKey));\r\n if (entity === undefined) {\r\n return { errorMessage: `Entity Class ${entityKey.fullName} not found in schema context.` };\r\n }\r\n if (entity.schemaItemType !== SchemaItemType.EntityClass) {\r\n return { errorMessage: `Expected ${entityKey.fullName} to be of type Entity Class.` };\r\n }\r\n\r\n const mixin = (await this._schemaEditor.schemaContext.getSchemaItem<Mixin>(mixinKey));\r\n if (mixin === undefined) {\r\n return { errorMessage: `Mixin Class ${mixinKey.fullName} not found in schema context.` };\r\n }\r\n if (mixin.schemaItemType !== SchemaItemType.Mixin) {\r\n return { errorMessage: `Expected ${mixinKey.fullName} to be of type Mixin.`};\r\n }\r\n\r\n entity.addMixin(mixin);\r\n return { itemKey: entityKey };\r\n }\r\n\r\n public async createNavigationProperty(entityKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<PropertyEditResults> {\r\n const entity = await this._schemaEditor.schemaContext.getSchemaItem<MutableEntityClass>(entityKey);\r\n\r\n if (entity === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Entity Class ${entityKey.fullName} not found in schema context.`);\r\n\r\n if (entity.schemaItemType !== SchemaItemType.EntityClass)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected ${entityKey.fullName} to be of type Entity Class.`);\r\n\r\n await entity.createNavigationProperty(name, relationship, direction);\r\n return { itemKey: entityKey, propertyName: name };\r\n }\r\n\r\n /**\r\n * Creates a Navigation Property through a NavigationPropertyProps.\r\n * @param classKey a SchemaItemKey of the Entity Class that will house the new property.\r\n * @param navigationProps a json object that will be used to populate the new Navigation Property.\r\n */\r\n public async createNavigationPropertyFromProps(classKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<PropertyEditResults> {\r\n const entity = await this._schemaEditor.schemaContext.getSchemaItem<MutableEntityClass>(classKey);\r\n if (entity === undefined)\r\n return { itemKey: classKey, propertyName: navigationProps.name, errorMessage: `Entity Class ${classKey.fullName} not found in schema context.`};\r\n\r\n if (entity.schemaItemType !== SchemaItemType.EntityClass)\r\n return { itemKey: classKey, propertyName: navigationProps.name, errorMessage: `Expected ${classKey.fullName} to be of type EntityClass.` };\r\n\r\n const navigationProperty = await entity.createNavigationProperty(navigationProps.name, navigationProps.relationshipName, navigationProps.direction);\r\n await navigationProperty.fromJSON(navigationProps);\r\n\r\n return { itemKey: classKey, propertyName: navigationProps.name };\r\n }\r\n\r\n /**\r\n * Sets the base class of an Entity.\r\n * @param entityKey The SchemaItemKey of the Entity.\r\n * @param baseClassKey The SchemaItemKey of the base class. Specifying 'undefined' removes the base class.\r\n */\r\n public async setBaseClass(entityKey: SchemaItemKey, baseClassKey?: SchemaItemKey): Promise<SchemaItemEditResults> {\r\n const entity = (await this._schemaEditor.schemaContext.getSchemaItem<MutableEntityClass>(entityKey));\r\n\r\n if (entity === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Entity Class ${entityKey.fullName} not found in schema context.`);\r\n\r\n if (baseClassKey === undefined) {\r\n entity.baseClass = undefined;\r\n return { itemKey: entityKey };\r\n }\r\n\r\n const baseClassSchema = !baseClassKey.schemaKey.matches(entityKey.schemaKey) ? await this._schemaEditor.getSchema(baseClassKey.schemaKey) : entity.schema;\r\n if (baseClassSchema === undefined) {\r\n return { errorMessage: `Schema Key ${baseClassKey.schemaKey.toString(true)} not found in context` };\r\n }\r\n\r\n const baseClassItem = await baseClassSchema.lookupItem<EntityClass>(baseClassKey);\r\n if (baseClassItem === undefined)\r\n return { errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };\r\n\r\n if (baseClassItem.schemaItemType !== SchemaItemType.EntityClass)\r\n return { errorMessage: `${baseClassItem.fullName} is not of type Entity Class.` };\r\n\r\n entity.baseClass = new DelayedPromiseWithProps<SchemaItemKey, EntityClass>(baseClassKey, async () => baseClassItem);\r\n return { itemKey: entityKey };\r\n }\r\n}\r\n\r\n"]}
|
|
1
|
+
{"version":3,"file":"Entities.js","sourceRoot":"","sources":["../../../src/Editing/Entities.ts"],"names":[],"mappings":";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AAe,CAAC,gBAAgB,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;QACrJ,MAAM,kBAAkB,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;QAEnD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,CAAC,IAAI,EAAE,CAAC;IACnE,CAAC;CACF;AApKD,4BAoKC","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 DelayedPromiseWithProps, ECClassModifier, ECObjectsError, ECObjectsStatus, EntityClass, EntityClassProps,\r\n Mixin, NavigationPropertyProps, RelationshipClass, SchemaItemKey, SchemaItemType, SchemaKey, StrengthDirection,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\r\nimport { ECClasses } from \"./ECClasses\";\r\nimport { MutableEntityClass } from \"./Mutable/MutableEntityClass\";\r\nimport { NavigationProperties } from \"./Properties\";\r\n\r\n/**\r\n * @alpha\r\n * A class extending ECClasses allowing you to create schema items of type EntityClass.\r\n */\r\nexport class Entities extends ECClasses {\r\n public constructor(schemaEditor: SchemaContextEditor) {\r\n super(SchemaItemType.EntityClass, schemaEditor);\r\n }\r\n\r\n /**\r\n * Allows access for editing of NavigationProperty attributes.\r\n */\r\n public readonly navigationProperties = new NavigationProperties(this.schemaItemType, this._schemaEditor);\r\n\r\n public async createElement(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemEditResults> {\r\n const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);\r\n if (!baseClass)\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could not be found.`);\r\n\r\n if (baseClass?.schemaItemType !== SchemaItemType.EntityClass)\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);\r\n\r\n if (!(await (baseClass as EntityClass).is(\"Element\", \"BisCore\"))) {\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an Element.`);\r\n }\r\n\r\n return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);\r\n }\r\n\r\n public async createElementUniqueAspect(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemEditResults> {\r\n const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);\r\n if (!baseClass)\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could not be found.`);\r\n\r\n if (baseClass?.schemaItemType !== SchemaItemType.EntityClass)\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);\r\n\r\n if (!(await (baseClass as EntityClass).is(\"ElementUniqueAspect\", \"BisCore\"))) {\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an ElementUniqueAspect.`);\r\n }\r\n\r\n return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);\r\n }\r\n\r\n public async createElementMultiAspect(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemEditResults> {\r\n const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);\r\n if (!baseClass)\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could be found.`);\r\n\r\n if (baseClass?.schemaItemType !== SchemaItemType.EntityClass)\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);\r\n\r\n if (!(await (baseClass as EntityClass).is(\"ElementMultiAspect\", \"BisCore\"))) {\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an ElementMultiAspect.`);\r\n }\r\n\r\n return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);\r\n }\r\n\r\n public async create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, displayLabel?: string, baseClassKey?: SchemaItemKey, mixins?: Mixin[]): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n const newClass = (await schema.createEntityClass(name, modifier)) as MutableEntityClass;\r\n if (newClass === undefined)\r\n return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };\r\n\r\n // Add a deserializing method.\r\n if (baseClassKey !== undefined) {\r\n const baseClassSchema = !baseClassKey.schemaKey.matches(schema.schemaKey) ? await this._schemaEditor.getSchema(baseClassKey.schemaKey) : schema;\r\n if (baseClassSchema === undefined) {\r\n return { errorMessage: `Schema Key ${baseClassKey.schemaKey.toString(true)} not found in context` };\r\n }\r\n\r\n const baseClassItem = await baseClassSchema.lookupItem<EntityClass>(baseClassKey);\r\n if (baseClassItem === undefined)\r\n return { errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };\r\n\r\n if (baseClassItem.schemaItemType !== SchemaItemType.EntityClass)\r\n return { errorMessage: `${baseClassItem.fullName} is not of type Entity Class.` };\r\n\r\n newClass.baseClass = new DelayedPromiseWithProps<SchemaItemKey, EntityClass>(baseClassKey, async () => baseClassItem);\r\n }\r\n\r\n if (mixins !== undefined)\r\n mixins.forEach((m) => newClass.addMixin(m));\r\n\r\n if (displayLabel)\r\n newClass.setDisplayLabel(displayLabel);\r\n\r\n return { itemKey: newClass.key };\r\n }\r\n\r\n /**\r\n * Creates an EntityClass through an EntityClassProps.\r\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\r\n * @param entityProps a json object that will be used to populate the new EntityClass. Needs a name value passed in.\r\n */\r\n public async createFromProps(schemaKey: SchemaKey, entityProps: EntityClassProps): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n if (entityProps.name === undefined)\r\n return { errorMessage: `No name was supplied within props.` };\r\n\r\n const newClass = (await schema.createEntityClass(entityProps.name)) as MutableEntityClass;\r\n if (newClass === undefined)\r\n return { errorMessage: `Failed to create class ${entityProps.name} in schema ${schemaKey.toString(true)}.` };\r\n\r\n await newClass.fromJSON(entityProps);\r\n\r\n return { itemKey: newClass.key };\r\n }\r\n\r\n public async addMixin(entityKey: SchemaItemKey, mixinKey: SchemaItemKey): Promise<SchemaItemEditResults> {\r\n const entity = (await this._schemaEditor.schemaContext.getSchemaItem<MutableEntityClass>(entityKey));\r\n if (entity === undefined) {\r\n return { errorMessage: `Entity Class ${entityKey.fullName} not found in schema context.` };\r\n }\r\n if (entity.schemaItemType !== SchemaItemType.EntityClass) {\r\n return { errorMessage: `Expected ${entityKey.fullName} to be of type Entity Class.` };\r\n }\r\n\r\n const mixin = (await this._schemaEditor.schemaContext.getSchemaItem<Mixin>(mixinKey));\r\n if (mixin === undefined) {\r\n return { errorMessage: `Mixin Class ${mixinKey.fullName} not found in schema context.` };\r\n }\r\n if (mixin.schemaItemType !== SchemaItemType.Mixin) {\r\n return { errorMessage: `Expected ${mixinKey.fullName} to be of type Mixin.`};\r\n }\r\n\r\n entity.addMixin(mixin);\r\n return { itemKey: entityKey };\r\n }\r\n\r\n public async createNavigationProperty(entityKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<PropertyEditResults> {\r\n const entity = await this._schemaEditor.schemaContext.getSchemaItem<MutableEntityClass>(entityKey);\r\n\r\n if (entity === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Entity Class ${entityKey.fullName} not found in schema context.`);\r\n\r\n if (entity.schemaItemType !== SchemaItemType.EntityClass)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected ${entityKey.fullName} to be of type Entity Class.`);\r\n\r\n await entity.createNavigationProperty(name, relationship, direction);\r\n return { itemKey: entityKey, propertyName: name };\r\n }\r\n\r\n /**\r\n * Creates a Navigation Property through a NavigationPropertyProps.\r\n * @param classKey a SchemaItemKey of the Entity Class that will house the new property.\r\n * @param navigationProps a json object that will be used to populate the new Navigation Property.\r\n */\r\n public async createNavigationPropertyFromProps(classKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<PropertyEditResults> {\r\n const entity = await this._schemaEditor.schemaContext.getSchemaItem<MutableEntityClass>(classKey);\r\n if (entity === undefined)\r\n return { itemKey: classKey, propertyName: navigationProps.name, errorMessage: `Entity Class ${classKey.fullName} not found in schema context.`};\r\n\r\n if (entity.schemaItemType !== SchemaItemType.EntityClass)\r\n return { itemKey: classKey, propertyName: navigationProps.name, errorMessage: `Expected ${classKey.fullName} to be of type EntityClass.` };\r\n\r\n const navigationProperty = await entity.createNavigationProperty(navigationProps.name, navigationProps.relationshipName, navigationProps.direction);\r\n await navigationProperty.fromJSON(navigationProps);\r\n\r\n return { itemKey: classKey, propertyName: navigationProps.name };\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Formats.js","sourceRoot":"","sources":["../../../src/Editing/Formats.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAA2I;AAK3I;;;GAGG;AACH,MAAa,OAAO;IAClB,YAA6B,aAAkC;QAAlC,kBAAa,GAAb,aAAa,CAAqB;IAAI,CAAC;IAC7D,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,IAAY,EAAE,UAAsB,EAAE,YAAqB,EAAE,KAAuB;QAC5H,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC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W,CAAC,CAAC;QACtC,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,GAAG,EAAE,CAAC;IACpC,CAAC;CACF;AApDD,0BAoDC","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 { InvertedUnit, SchemaItem, SchemaItemFormatProps, SchemaItemKey, SchemaItemType, SchemaKey, Unit } from \"@itwin/ecschema-metadata\";\r\nimport { FormatType } from \"@itwin/core-quantity\";\r\nimport { SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\r\nimport { MutableFormat } from \"./Mutable/MutableFormat\";\r\n\r\n/**\r\n * @alpha\r\n * A class allowing you to create schema items of type Format.\r\n */\r\nexport class Formats {\r\n public constructor(protected _schemaEditor: SchemaContextEditor) { }\r\n public async create(schemaKey: SchemaKey, name: string, formatType: FormatType, displayLabel?: string, units?: SchemaItemKey[]): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n const newFormat = (await schema.createFormat(name)) as MutableFormat;\r\n if (newFormat === undefined) {\r\n return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };\r\n }\r\n\r\n if (units !== undefined) {\r\n for (const unit of units) {\r\n const unitItem = await this._schemaEditor.schemaContext.getSchemaItem<Unit | InvertedUnit>(unit);\r\n if (unitItem === undefined) {\r\n return { errorMessage: `Failed to locate unit ${unit.name} in Schema Context.` };\r\n }\r\n\r\n if (unitItem.schemaItemType !== SchemaItemType.Unit && unitItem.schemaItemType !== SchemaItemType.InvertedUnit)\r\n return { errorMessage: `${(unitItem as SchemaItem).fullName} is not of type Unit or InvertedUnit.` };\r\n newFormat.addUnit(unitItem);\r\n }\r\n }\r\n if (displayLabel)\r\n newFormat.setDisplayLabel(displayLabel);\r\n\r\n // TODO: Handle the setting of format traits, separators, etc....\r\n newFormat.setFormatType(formatType);\r\n return { itemKey: newFormat.key };\r\n }\r\n\r\n /**\r\n * Creates a format through a SchemaItemFormatProps.\r\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\r\n * @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.\r\n */\r\n public async createFromProps(schemaKey: SchemaKey, formatProps: SchemaItemFormatProps): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n if (formatProps.name === undefined)\r\n return { errorMessage: `No name was supplied within props.` };\r\n\r\n const newFormat = (await schema.createFormat(formatProps.name)) as MutableFormat;\r\n if (newFormat === undefined)\r\n return { errorMessage: `Failed to create class ${formatProps.name} in schema ${schemaKey.toString(true)}.` };\r\n\r\n await newFormat.fromJSON(formatProps);\r\n return { itemKey: newFormat.key };\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KindOfQuantities.js","sourceRoot":"","sources":["../../../src/Editing/KindOfQuantities.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAIkC;AAIlC;;;GAGG;AACH,MAAa,gBAAgB;IAC3B,YAA6B,aAAkC;QAAlC,kBAAa,GAAb,aAAa,CAAqB;IAAI,CAAC;IAE7D,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,IAAY,EAAE,kBAAiC,EAAE,YAAqB;QAC9G,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC7D,IAAI,MAAM,KAAK,SAAS;YACtB,OAAO,EAAE,YAAY,EAAE,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,uBAAuB,EAA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AC,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,aAAa,CAAS,MAAM,CAAC,CAAC,CAAC;QAC5F,IAAI,SAAS,KAAK,YAAY;YAC5B,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,aAAa,EAAE,4BAA4B,MAAM,CAAC,QAAQ,iDAAiD,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC;QAE1K,IAAI,YAAY,CAAC,cAAc,KAAK,kCAAc,CAAC,MAAM;YACvD,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,qBAAqB,EAAE,YAAY,YAAY,CAAC,QAAQ,wBAAwB,CAAC,CAAC;QAE7H,OAAO,IAAI,kCAAc,CAAC,YAAY,EAAE,SAAS,EAAE,kBAAkB,CAAC,CAAC;IACzE,CAAC;CACF;AA1GD,4CA0GC","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 DelayedPromiseWithProps,\r\n ECObjectsError, ECObjectsStatus, Format, InvertedUnit, KindOfQuantityProps, OverrideFormat,\r\n SchemaItemKey, SchemaItemType, SchemaKey, Unit,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\r\nimport { MutableKindOfQuantity } from \"./Mutable/MutableKindOfQuantity\";\r\n\r\n/**\r\n * @alpha\r\n * A class allowing you to create schema items of type KindOfQuantity.\r\n */\r\nexport class KindOfQuantities {\r\n public constructor(protected _schemaEditor: SchemaContextEditor) { }\r\n\r\n public async create(schemaKey: SchemaKey, name: string, persistenceUnitKey: SchemaItemKey, displayLabel?: string): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n const koqItem = (await schema.createKindOfQuantity(name)) as MutableKindOfQuantity;\r\n\r\n const persistenceUnit = await schema.lookupItem<Unit | InvertedUnit>(persistenceUnitKey);\r\n if (persistenceUnit === undefined) {\r\n return { errorMessage: `Unable to locate unit ${persistenceUnitKey.fullName} in schema ${schema.fullName}.` };\r\n }\r\n\r\n if (persistenceUnit.schemaItemType === SchemaItemType.Unit) {\r\n koqItem.persistenceUnit = new DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);\r\n }\r\n\r\n if (persistenceUnit.schemaItemType === SchemaItemType.InvertedUnit) {\r\n koqItem.persistenceUnit = new DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);\r\n }\r\n\r\n if (displayLabel !== undefined) {\r\n koqItem.setDisplayLabel(displayLabel);\r\n }\r\n\r\n return { itemKey: koqItem.key };\r\n }\r\n\r\n public async createFromProps(schemaKey: SchemaKey, koqProps: KindOfQuantityProps): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n if (koqProps.name === undefined)\r\n return { errorMessage: `No name was supplied within props.` };\r\n\r\n const newKoQ = (await schema.createKindOfQuantity(koqProps.name)) as MutableKindOfQuantity;\r\n if (newKoQ === undefined)\r\n return { errorMessage: `Failed to create class ${koqProps.name} in schema ${schemaKey.toString(true)}.` };\r\n\r\n await newKoQ.fromJSON(koqProps);\r\n return { itemKey: newKoQ.key };\r\n }\r\n\r\n /**\r\n *\r\n * @param koqKey A schemaItemKey of the editing KindOfQuantity.\r\n * @param format A schemaItemKey of a Format.\r\n * @param isDefault .is set to false when not explicitly passed.\r\n */\r\n public async addPresentationFormat(koqKey: SchemaItemKey, format: SchemaItemKey, isDefault: boolean = false): Promise<void> {\r\n const kindOfQuantity = (await this._schemaEditor.schemaContext.getSchemaItem<MutableKindOfQuantity>(koqKey));\r\n\r\n if (kindOfQuantity === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Entity Class ${koqKey.fullName} not found in schema context.`);\r\n\r\n if (kindOfQuantity.schemaItemType !== SchemaItemType.KindOfQuantity)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected ${koqKey.fullName} to be of type Kind Of Quantity.`);\r\n\r\n const presentationFormat = await (this._schemaEditor.schemaContext.getSchemaItem<Format>(format));\r\n if (undefined === presentationFormat)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate format '${format.fullName}' for the presentation unit on KindOfQuantity ${koqKey.fullName}.`);\r\n\r\n if (presentationFormat.schemaItemType !== SchemaItemType.Format)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected ${presentationFormat.fullName} to be of type Format.`);\r\n\r\n kindOfQuantity.addPresentationFormat(presentationFormat, isDefault);\r\n }\r\n\r\n public async addPresentationOverrideFormat(koqKey: SchemaItemKey, overrideFormat: OverrideFormat, isDefault: boolean = false): Promise<void> {\r\n const kindOfQuantity = (await this._schemaEditor.schemaContext.getSchemaItem<MutableKindOfQuantity>(koqKey));\r\n\r\n if (kindOfQuantity === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Entity Class ${koqKey.fullName} not found in schema context.`);\r\n\r\n if (kindOfQuantity.schemaItemType !== SchemaItemType.KindOfQuantity)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected ${koqKey.fullName} to be of type Kind Of Quantity.`);\r\n\r\n kindOfQuantity.addPresentationFormat(overrideFormat, isDefault);\r\n }\r\n\r\n /**\r\n * @param koqKey A schemaItemKey of the editing KindOfQuantity.\r\n * @param parent A SchemaItemKey of the parent Format.\r\n * @param unitLabelOverrides The list of Unit (or InvertedUnit) and label overrides. The length of list should be equal to the number of units in the parent Format.\r\n */\r\n public async createFormatOverride(koqKey: SchemaItemKey, parent: SchemaItemKey, precision?: number, unitLabelOverrides?: Array<[Unit | InvertedUnit, string | undefined]>): Promise<OverrideFormat> {\r\n const kindOfQuantity = (await this._schemaEditor.schemaContext.getSchemaItem<MutableKindOfQuantity>(koqKey));\r\n\r\n if (kindOfQuantity === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Entity Class ${koqKey.fullName} not found in schema context.`);\r\n\r\n if (kindOfQuantity.schemaItemType !== SchemaItemType.KindOfQuantity)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected ${koqKey.fullName} to be of type Kind Of Quantity.`);\r\n\r\n const parentFormat = await (this._schemaEditor.schemaContext.getSchemaItem<Format>(parent));\r\n if (undefined === parentFormat)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate format '${parent.fullName}' for the presentation unit on KindOfQuantity ${koqKey.fullName}.`);\r\n\r\n if (parentFormat.schemaItemType !== SchemaItemType.Format)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected ${parentFormat.fullName} to be of type Format.`);\r\n\r\n return new OverrideFormat(parentFormat, precision, unitLabelOverrides);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"KindOfQuantities.js","sourceRoot":"","sources":["../../../src/Editing/KindOfQuantities.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAIkC;AAIlC;;;GAGG;AACH,MAAa,gBAAgB;IAC3B,YAA6B,aAAkC;QAAlC,kBAAa,GAAb,aAAa,CAAqB;IAAI,CAAC;IAE7D,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,IAAY,EAAE,kBAAiC,EAAE,YAAqB;QAC9G,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC7D,IAAI,MAAM,KAAK,SAAS;YACtB,OAAO,EAAE,YAAY,EAAE,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAEzF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;QAEjI,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,aAAa,CAAS,MAAM,CAAC,CAAC,CAAC;QAC5F,IAAI,SAAS,KAAK,YAAY;YAC5B,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,aAAa,EAAE,4BAA4B,MAAM,CAAC,QAAQ,iDAAiD,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC;QAE1K,IAAI,YAAY,CAAC,cAAc,KAAK,kCAAc,CAAC,MAAM;YACvD,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,qBAAqB,EAAE,YAAY,YAAY,CAAC,QAAQ,wBAAwB,CAAC,CAAC;QAE7H,OAAO,IAAI,kCAAc,CAAC,YAAY,EAAE,SAAS,EAAE,kBAAkB,CAAC,CAAC;IACzE,CAAC;CACF;AA1GD,4CA0GC","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 DelayedPromiseWithProps,\r\n ECObjectsError, ECObjectsStatus, Format, InvertedUnit, KindOfQuantityProps, OverrideFormat,\r\n SchemaItemKey, SchemaItemType, SchemaKey, Unit,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\r\nimport { MutableKindOfQuantity } from \"./Mutable/MutableKindOfQuantity\";\r\n\r\n/**\r\n * @alpha\r\n * A class allowing you to create schema items of type KindOfQuantity.\r\n */\r\nexport class KindOfQuantities {\r\n public constructor(protected _schemaEditor: SchemaContextEditor) { }\r\n\r\n public async create(schemaKey: SchemaKey, name: string, persistenceUnitKey: SchemaItemKey, displayLabel?: string): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n const koqItem = (await schema.createKindOfQuantity(name)) as MutableKindOfQuantity;\r\n\r\n const persistenceUnit = await schema.lookupItem<Unit | InvertedUnit>(persistenceUnitKey);\r\n if (persistenceUnit === undefined) {\r\n return { errorMessage: `Unable to locate unit ${persistenceUnitKey.fullName} in schema ${schema.fullName}.` };\r\n }\r\n\r\n if (persistenceUnit.schemaItemType === SchemaItemType.Unit) {\r\n koqItem.persistenceUnit = new DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);\r\n }\r\n\r\n if (persistenceUnit.schemaItemType === SchemaItemType.InvertedUnit) {\r\n koqItem.persistenceUnit = new DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);\r\n }\r\n\r\n if (displayLabel !== undefined) {\r\n koqItem.setDisplayLabel(displayLabel);\r\n }\r\n\r\n return { itemKey: koqItem.key };\r\n }\r\n\r\n public async createFromProps(schemaKey: SchemaKey, koqProps: KindOfQuantityProps): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n if (koqProps.name === undefined)\r\n return { errorMessage: `No name was supplied within props.` };\r\n\r\n const newKoQ = (await schema.createKindOfQuantity(koqProps.name)) as MutableKindOfQuantity;\r\n if (newKoQ === undefined)\r\n return { errorMessage: `Failed to create class ${koqProps.name} in schema ${schemaKey.toString(true)}.` };\r\n\r\n await newKoQ.fromJSON(koqProps);\r\n return { itemKey: newKoQ.key };\r\n }\r\n\r\n /**\r\n *\r\n * @param koqKey A schemaItemKey of the editing KindOfQuantity.\r\n * @param format A schemaItemKey of a Format.\r\n * @param isDefault .is set to false when not explicitly passed.\r\n */\r\n public async addPresentationFormat(koqKey: SchemaItemKey, format: SchemaItemKey, isDefault: boolean = false): Promise<void> {\r\n const kindOfQuantity = (await this._schemaEditor.schemaContext.getSchemaItem<MutableKindOfQuantity>(koqKey));\r\n\r\n if (kindOfQuantity === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Entity Class ${koqKey.fullName} not found in schema context.`);\r\n\r\n if (kindOfQuantity.schemaItemType !== SchemaItemType.KindOfQuantity)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected ${koqKey.fullName} to be of type Kind Of Quantity.`);\r\n\r\n const presentationFormat = await (this._schemaEditor.schemaContext.getSchemaItem<Format>(format));\r\n if (undefined === presentationFormat)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate format '${format.fullName}' for the presentation unit on KindOfQuantity ${koqKey.fullName}.`);\r\n\r\n if (presentationFormat.schemaItemType !== SchemaItemType.Format)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected ${presentationFormat.fullName} to be of type Format.`);\r\n\r\n kindOfQuantity.addPresentationFormat(presentationFormat, isDefault);\r\n }\r\n\r\n public async addPresentationOverrideFormat(koqKey: SchemaItemKey, overrideFormat: OverrideFormat, isDefault: boolean = false): Promise<void> {\r\n const kindOfQuantity = (await this._schemaEditor.schemaContext.getSchemaItem<MutableKindOfQuantity>(koqKey));\r\n\r\n if (kindOfQuantity === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Entity Class ${koqKey.fullName} not found in schema context.`);\r\n\r\n if (kindOfQuantity.schemaItemType !== SchemaItemType.KindOfQuantity)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected ${koqKey.fullName} to be of type Kind Of Quantity.`);\r\n\r\n kindOfQuantity.addPresentationFormat(overrideFormat, isDefault);\r\n }\r\n\r\n /**\r\n * @param koqKey A schemaItemKey of the editing KindOfQuantity.\r\n * @param parent A SchemaItemKey of the parent Format.\r\n * @param unitLabelOverrides The list of Unit (or InvertedUnit) and label overrides. The length of list should be equal to the number of units in the parent Format.\r\n */\r\n public async createFormatOverride(koqKey: SchemaItemKey, parent: SchemaItemKey, precision?: number, unitLabelOverrides?: Array<[Unit | InvertedUnit, string | undefined]>): Promise<OverrideFormat> {\r\n const kindOfQuantity = (await this._schemaEditor.schemaContext.getSchemaItem<MutableKindOfQuantity>(koqKey));\r\n\r\n if (kindOfQuantity === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Entity Class ${koqKey.fullName} not found in schema context.`);\r\n\r\n if (kindOfQuantity.schemaItemType !== SchemaItemType.KindOfQuantity)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected ${koqKey.fullName} to be of type Kind Of Quantity.`);\r\n\r\n const parentFormat = await (this._schemaEditor.schemaContext.getSchemaItem<Format>(parent));\r\n if (undefined === parentFormat)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate format '${parent.fullName}' for the presentation unit on KindOfQuantity ${koqKey.fullName}.`);\r\n\r\n if (parentFormat.schemaItemType !== SchemaItemType.Format)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected ${parentFormat.fullName} to be of type Format.`);\r\n\r\n return new OverrideFormat(parentFormat, precision, unitLabelOverrides);\r\n }\r\n}\r\n"]}
|
|
@@ -4,12 +4,17 @@
|
|
|
4
4
|
import { MixinProps, NavigationPropertyProps, RelationshipClass, SchemaItemKey, SchemaKey, StrengthDirection } from "@itwin/ecschema-metadata";
|
|
5
5
|
import { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from "./Editor";
|
|
6
6
|
import { ECClasses } from "./ECClasses";
|
|
7
|
+
import { NavigationProperties } from "./Properties";
|
|
7
8
|
/**
|
|
8
9
|
* @alpha
|
|
9
10
|
* A class extending ECClasses allowing you to create schema items of type Mixin.
|
|
10
11
|
*/
|
|
11
12
|
export declare class Mixins extends ECClasses {
|
|
12
|
-
constructor(
|
|
13
|
+
constructor(schemaEditor: SchemaContextEditor);
|
|
14
|
+
/**
|
|
15
|
+
* Allows access for editing of NavigationProperty attributes.
|
|
16
|
+
*/
|
|
17
|
+
readonly navigationProperties: NavigationProperties;
|
|
13
18
|
create(schemaKey: SchemaKey, name: string, appliesTo: SchemaItemKey, displayLabel?: string, baseClass?: SchemaItemKey): Promise<SchemaItemEditResults>;
|
|
14
19
|
/**
|
|
15
20
|
* Creates a MixinClass through a MixinProps.
|
|
@@ -25,6 +30,5 @@ export declare class Mixins extends ECClasses {
|
|
|
25
30
|
* @param navigationProps a json object that will be used to populate the new Navigation Property.
|
|
26
31
|
*/
|
|
27
32
|
createNavigationPropertyFromProps(classKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<PropertyEditResults>;
|
|
28
|
-
setMixinBaseClass(mixinKey: SchemaItemKey, baseClassKey?: SchemaItemKey): Promise<SchemaItemEditResults>;
|
|
29
33
|
}
|
|
30
34
|
//# sourceMappingURL=Mixins.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mixins.d.ts","sourceRoot":"","sources":["../../../src/Editing/Mixins.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EACyE,UAAU,EAAE,uBAAuB,EAAE,iBAAiB,EACpI,aAAa,EAAkB,SAAS,EAAE,iBAAiB,EAC5D,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAC3F,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Mixins.d.ts","sourceRoot":"","sources":["../../../src/Editing/Mixins.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EACyE,UAAU,EAAE,uBAAuB,EAAE,iBAAiB,EACpI,aAAa,EAAkB,SAAS,EAAE,iBAAiB,EAC5D,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAC3F,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD;;;GAGG;AACH,qBAAa,MAAO,SAAQ,SAAS;gBAChB,YAAY,EAAE,mBAAmB;IAIpD;;OAEG;IACH,SAAgB,oBAAoB,uBAAqE;IAE5F,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAgCnK;;;;OAIG;IACU,eAAe,CAAC,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAgB7F,QAAQ,CAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAmB1E,wBAAwB,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,iBAAiB,EAAE,SAAS,EAAE,MAAM,GAAG,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAa3L;;;;OAIG;IACU,iCAAiC,CAAC,QAAQ,EAAE,aAAa,EAAE,eAAe,EAAE,uBAAuB,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAahJ"}
|
|
@@ -10,13 +10,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
exports.Mixins = void 0;
|
|
11
11
|
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
12
12
|
const ECClasses_1 = require("./ECClasses");
|
|
13
|
+
const Properties_1 = require("./Properties");
|
|
13
14
|
/**
|
|
14
15
|
* @alpha
|
|
15
16
|
* A class extending ECClasses allowing you to create schema items of type Mixin.
|
|
16
17
|
*/
|
|
17
18
|
class Mixins extends ECClasses_1.ECClasses {
|
|
18
|
-
constructor(
|
|
19
|
-
super(
|
|
19
|
+
constructor(schemaEditor) {
|
|
20
|
+
super(ecschema_metadata_1.SchemaItemType.Mixin, schemaEditor);
|
|
21
|
+
/**
|
|
22
|
+
* Allows access for editing of NavigationProperty attributes.
|
|
23
|
+
*/
|
|
24
|
+
this.navigationProperties = new Properties_1.NavigationProperties(this.schemaItemType, this._schemaEditor);
|
|
20
25
|
}
|
|
21
26
|
async create(schemaKey, name, appliesTo, displayLabel, baseClass) {
|
|
22
27
|
const schema = await this._schemaEditor.getSchema(schemaKey);
|
|
@@ -95,26 +100,6 @@ class Mixins extends ECClasses_1.ECClasses {
|
|
|
95
100
|
await navigationProperty.fromJSON(navigationProps);
|
|
96
101
|
return { itemKey: classKey, propertyName: navigationProps.name };
|
|
97
102
|
}
|
|
98
|
-
async setMixinBaseClass(mixinKey, baseClassKey) {
|
|
99
|
-
const mixin = (await this._schemaEditor.schemaContext.getSchemaItem(mixinKey));
|
|
100
|
-
if (mixin === undefined)
|
|
101
|
-
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.ClassNotFound, `Mixin Class ${mixinKey.fullName} not found in schema context.`);
|
|
102
|
-
if (baseClassKey === undefined) {
|
|
103
|
-
mixin.baseClass = undefined;
|
|
104
|
-
return { itemKey: mixinKey };
|
|
105
|
-
}
|
|
106
|
-
const baseClassSchema = !baseClassKey.schemaKey.matches(mixinKey.schemaKey) ? await this._schemaEditor.getSchema(baseClassKey.schemaKey) : mixin.schema;
|
|
107
|
-
if (baseClassSchema === undefined) {
|
|
108
|
-
return { errorMessage: `Schema Key ${baseClassKey.schemaKey.toString(true)} not found in context` };
|
|
109
|
-
}
|
|
110
|
-
const baseClassItem = await baseClassSchema.lookupItem(baseClassKey);
|
|
111
|
-
if (baseClassItem === undefined)
|
|
112
|
-
return { errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };
|
|
113
|
-
if (baseClassItem.schemaItemType !== ecschema_metadata_1.SchemaItemType.Mixin)
|
|
114
|
-
return { errorMessage: `${baseClassItem.fullName} is not of type Mixin Class.` };
|
|
115
|
-
mixin.baseClass = new ecschema_metadata_1.DelayedPromiseWithProps(baseClassKey, async () => baseClassItem);
|
|
116
|
-
return { itemKey: mixinKey };
|
|
117
|
-
}
|
|
118
103
|
}
|
|
119
104
|
exports.Mixins = Mixins;
|
|
120
105
|
//# sourceMappingURL=Mixins.js.map
|