@itwin/ecschema-editing 4.5.0-dev.9 → 4.6.0-dev.0
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 +46 -1
- package/LICENSE.md +1 -1
- package/lib/cjs/Differencing/SchemaConflicts.d.ts +76 -0
- package/lib/cjs/Differencing/SchemaConflicts.d.ts.map +1 -0
- package/lib/cjs/Differencing/SchemaConflicts.js +56 -0
- package/lib/cjs/Differencing/SchemaConflicts.js.map +1 -0
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.d.ts +43 -0
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.d.ts.map +1 -0
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js +501 -0
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js.map +1 -0
- package/lib/cjs/Differencing/SchemaDifference.d.ts +150 -0
- package/lib/cjs/Differencing/SchemaDifference.d.ts.map +1 -0
- package/lib/cjs/Differencing/SchemaDifference.js +54 -0
- package/lib/cjs/Differencing/SchemaDifference.js.map +1 -0
- package/lib/cjs/Editing/Constants.js.map +1 -1
- package/lib/cjs/Editing/CustomAttributes.js.map +1 -1
- package/lib/cjs/Editing/ECClasses.d.ts +9 -2
- package/lib/cjs/Editing/ECClasses.d.ts.map +1 -1
- package/lib/cjs/Editing/ECClasses.js +25 -0
- 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 +8 -2
- package/lib/cjs/Editing/Entities.d.ts.map +1 -1
- package/lib/cjs/Editing/Entities.js +29 -6
- package/lib/cjs/Editing/Entities.js.map +1 -1
- package/lib/cjs/Editing/Enumerations.js.map +1 -1
- package/lib/cjs/Editing/Formats.js.map +1 -1
- package/lib/cjs/Editing/InvertedUnits.js.map +1 -1
- package/lib/cjs/Editing/KindOfQuantities.js.map +1 -1
- package/lib/cjs/Editing/Mixins.d.ts +7 -1
- package/lib/cjs/Editing/Mixins.d.ts.map +1 -1
- package/lib/cjs/Editing/Mixins.js +15 -0
- package/lib/cjs/Editing/Mixins.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableArrayProperty.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableCAClass.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableClass.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableConstant.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableEntityClass.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableEnumeration.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableFormat.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableInvertedUnit.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableMixin.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutablePhenomenon.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutablePrimitiveOrEnumProperty.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableProperty.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutablePropertyCategory.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableRelationshipClass.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableSchema.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableUnit.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableUnitSystem.js.map +1 -1
- package/lib/cjs/Editing/Phenomena.js.map +1 -1
- package/lib/cjs/Editing/PropertyCategories.js.map +1 -1
- package/lib/cjs/Editing/RelationshipClasses.d.ts +7 -1
- package/lib/cjs/Editing/RelationshipClasses.d.ts.map +1 -1
- package/lib/cjs/Editing/RelationshipClasses.js +20 -1
- package/lib/cjs/Editing/RelationshipClasses.js.map +1 -1
- package/lib/cjs/Editing/SchemaItems.js.map +1 -1
- package/lib/cjs/Editing/Structs.js.map +1 -1
- package/lib/cjs/Editing/UnitSystems.js.map +1 -1
- package/lib/cjs/Editing/Units.js.map +1 -1
- package/lib/cjs/Merging/CAClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/CAClassMerger.js +1 -5
- package/lib/cjs/Merging/CAClassMerger.js.map +1 -1
- package/lib/cjs/Merging/ClassMerger.d.ts +4 -3
- package/lib/cjs/Merging/ClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/ClassMerger.js +57 -49
- package/lib/cjs/Merging/ClassMerger.js.map +1 -1
- package/lib/cjs/Merging/ConstantMerger.js.map +1 -1
- package/lib/cjs/Merging/CustomAttributeMerger.js.map +1 -1
- package/lib/cjs/Merging/EntityClassMerger.d.ts +3 -2
- package/lib/cjs/Merging/EntityClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/EntityClassMerger.js +22 -7
- 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.d.ts.map +1 -1
- package/lib/cjs/Merging/MixinMerger.js +1 -5
- package/lib/cjs/Merging/MixinMerger.js.map +1 -1
- package/lib/cjs/Merging/PropertyMerger.d.ts +21 -0
- package/lib/cjs/Merging/PropertyMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/PropertyMerger.js +315 -0
- package/lib/cjs/Merging/PropertyMerger.js.map +1 -0
- package/lib/cjs/Merging/RelationshipClassMerger.d.ts +15 -0
- package/lib/cjs/Merging/RelationshipClassMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/RelationshipClassMerger.js +132 -0
- package/lib/cjs/Merging/RelationshipClassMerger.js.map +1 -0
- package/lib/cjs/Merging/SchemaItemFactory.js.map +1 -1
- package/lib/cjs/Merging/SchemaItemMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.js +7 -3
- package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaReferenceMerger.js.map +1 -1
- package/lib/cjs/Merging/StructClassMerger.js.map +1 -1
- package/lib/cjs/Validation/Diagnostic.js.map +1 -1
- package/lib/cjs/Validation/DiagnosticReporter.js.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/RuleSuppressionSet.js.map +1 -1
- package/lib/cjs/Validation/Rules.js.map +1 -1
- package/lib/cjs/Validation/SchemaChanges.js.map +1 -1
- package/lib/cjs/Validation/SchemaCompareDiagnostics.js.map +1 -1
- package/lib/cjs/Validation/SchemaCompareReporter.js.map +1 -1
- package/lib/cjs/Validation/SchemaCompareResultDelegate.js.map +1 -1
- package/lib/cjs/Validation/SchemaCompareVisitor.js.map +1 -1
- package/lib/cjs/Validation/SchemaComparer.js.map +1 -1
- package/lib/cjs/Validation/SchemaValidater.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 +4 -0
- package/lib/cjs/ecschema-editing.d.ts.map +1 -1
- package/lib/cjs/ecschema-editing.js +4 -0
- package/lib/cjs/ecschema-editing.js.map +1 -1
- package/package.json +10 -10
- package/public/locales/en/ECSchemaEditing.json +26 -26
- package/lib/cjs/Merging/AnyPropertyMerger.d.ts +0 -15
- package/lib/cjs/Merging/AnyPropertyMerger.d.ts.map +0 -1
- package/lib/cjs/Merging/AnyPropertyMerger.js +0 -71
- package/lib/cjs/Merging/AnyPropertyMerger.js.map +0 -1
- package/lib/cjs/Merging/ArrayPropertyMerger.d.ts +0 -32
- package/lib/cjs/Merging/ArrayPropertyMerger.d.ts.map +0 -1
- package/lib/cjs/Merging/ArrayPropertyMerger.js +0 -143
- package/lib/cjs/Merging/ArrayPropertyMerger.js.map +0 -1
- package/lib/cjs/Merging/ClassPropertyMerger.d.ts +0 -16
- package/lib/cjs/Merging/ClassPropertyMerger.d.ts.map +0 -1
- package/lib/cjs/Merging/ClassPropertyMerger.js +0 -90
- package/lib/cjs/Merging/ClassPropertyMerger.js.map +0 -1
- package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.d.ts +0 -24
- package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.d.ts.map +0 -1
- package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.js +0 -106
- package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.js.map +0 -1
- package/lib/cjs/Merging/StructPropertyMerger.d.ts +0 -11
- package/lib/cjs/Merging/StructPropertyMerger.d.ts.map +0 -1
- package/lib/cjs/Merging/StructPropertyMerger.js +0 -47
- package/lib/cjs/Merging/StructPropertyMerger.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaItemMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaItemMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAqE;AACrE,+DAAiG;AACjG,2DAAwD;AAkBxD;;;;;;GAMG;AACH,MAAa,gBAAgB;IAI3B;;;;OAIG;IACH,YAAY,OAA2B;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;;;OAKG;IACO,KAAK,CAAC,2BAA2B;QACzC,sDAAsD;QACtD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED;;;;;OAKG;IACO,KAAK,CAAC,KAAK,CAAC,QAAuB,EAAE,OAAc,EAAE,OAA0B;QACvF,uCAAuC;IACzC,CAAC;IAES,KAAK,CAAC,MAAM,CAAuB,UAAa;QACxD,MAAM,OAAO,GAAG,IAAI,iCAAa,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC;YACzH,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC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AK,CAAC,uBAAuB,CAAC,aAA4B,EAAE,OAA8B;QAChG,uDAAuD;QACvD,IAAG,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;YACvB,OAAO;SACR;QAED,MAAM,UAAU,GAAG,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAa,aAAa,CAAC,CAAC,CAAC;QAC3F,MAAM,SAAS,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,CAAkC,CAAC;QAChF,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,2BAA2B,EAAE,CAAC;QAElE,KAAI,MAAM,MAAM,IAAI,OAAO,EAAE;YAC3B,MAAM,CAAC,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,WAAkD,CAAC;YAChI,MAAM,QAAQ,GAAG,gBAAgB,CAAC,YAAY,CAAC,CAAC;YAChD,SAAS,CAAC,YAAY,CAAC,GAAG,QAAQ,KAAK,SAAS;gBAC9C,CAAC,CAAC,QAAQ,CAAC,gBAAgB,EAAE,aAAa,EAAE,gBAAgB,CAAC;gBAC7D,CAAC,CAAC,gBAAgB,CAAC;SACtB;QAED,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IAC7E,CAAC;CACF;AAjGD,4CAiGC","sourcesContent":["/*---------------------------------------------------------------------------------------------\
|
|
1
|
+
{"version":3,"file":"SchemaItemMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaItemMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAqE;AACrE,+DAAiG;AACjG,2DAAwD;AAkBxD;;;;;;GAMG;AACH,MAAa,gBAAgB;IAI3B;;;;OAIG;IACH,YAAY,OAA2B;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;;;OAKG;IACO,KAAK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aAAa,EAAE,SAAS,CAAC,CAAC;IAC7E,CAAC;CACF;AAjGD,4CAiGC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { SchemaItem, SchemaItemKey } from \"@itwin/ecschema-metadata\";\nimport { ChangeType, PropertyValueChange, SchemaItemChanges } from \"../Validation/SchemaChanges\";\nimport { SchemaItemFactory } from \"./SchemaItemFactory\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\n\n/**\n * Defines a type-safe interface of Property Value resolver.\n * @internal\n */\nexport type PropertyValueResolver<T extends SchemaItem, TProps=MutableSchemaItemProps<T>> = {\n [P in keyof TProps]?: (newValue: any, item: SchemaItemKey, oldValue?: any) => any;\n};\n\n/**\n * Defines a Mutable Schema Props interface.\n */\ntype MutableSchemaItemProps<T extends SchemaItem> = {\n -readonly [key in keyof ReturnType<T[\"toJSON\"]>]: ReturnType<T[\"toJSON\"]>[key];\n};\n\n/**\n * The SchemaItemMerger is an base class for several other mergers with the actual logic\n * to perform merging for a certain schema item type. The class provides the shared logics\n * that is shared for all schema item mergers and custom logic can be applied by overriding\n * the protected class members.\n * @internal\n */\nexport class SchemaItemMerger<TItem extends SchemaItem> {\n\n protected readonly context: SchemaMergeContext;\n\n /**\n * Constructor of the SchemaItemMerger class. This should not be overriden or extended\n * by sub-implementations.\n * @param context The current merging context.\n */\n constructor(context: SchemaMergeContext) {\n this.context = context;\n }\n\n /**\n * This overridable method allows to create a property value resolver that gets defines\n * a handler function for every possible property change. This allows adding complex handing\n * if a property value requires complicated merging.\n * @returns A resolver map with resolvers for the property.\n */\n protected async createPropertyValueResolver(): Promise<PropertyValueResolver<TItem>> {\n // Can be overriden for complex property value merging\n return {};\n }\n\n /**\n * This overridable method gets called for more complex merging.\n * @param _itemKey The key of the current schema item.\n * @param _source The source item that shall gets merged into.\n * @param _change The schema item change to be applied.\n */\n protected async merge(_itemKey: SchemaItemKey, _source: TItem, _change: SchemaItemChanges) {\n // Can be overriden for complex merging\n }\n\n protected async lookup<T extends SchemaItem>(schemaItem: T): Promise<T | undefined>{\n const itemKey = new SchemaItemKey(schemaItem.name, this.context.sourceSchema.schemaKey.matches(schemaItem.schema.schemaKey)\n ? this.context.targetSchema.schemaKey\n : schemaItem.schema.schemaKey,\n );\n return this.context.targetSchema.lookupItem<T>(itemKey);\n }\n\n /**\n * Merges the given schema item changes in the current context.\n * @param context The merging context\n * @param schemaItemChanges An iterable of item changes.\n */\n public static async mergeChanges<TChange extends SchemaItemChanges>(context: SchemaMergeContext, schemaItemChanges: Iterable<TChange>) {\n const merger = new this(context);\n for(const change of schemaItemChanges) {\n\n // Gets the source and the target item. The target item could be undefined at that point.\n const sourceItem = (await context.sourceSchema.getItem<SchemaItem>(change.ecTypeName))!;\n let targetItemKey = new SchemaItemKey(change.ecTypeName, context.targetSchema.schemaKey);\n\n // In case the schema item does not exists in the target schema, an instance for\n // this schema item is created. It's properties get set by the merger then.\n if(change.schemaItemMissing?.changeType === ChangeType.Missing) {\n // Check for name to make sure there is no collision for items with the same name\n // but different type.\n if(await context.targetSchema.lookupItem(targetItemKey) !== undefined) {\n throw new Error(`Schema ${context.targetSchema.name} already contains a Schema Item ${change.ecTypeName}.`);\n }\n\n // TODO: Think about renaming the Schema Item. This could be controlled though a flag.\n targetItemKey = await SchemaItemFactory.create(context, sourceItem);\n }\n\n await merger.mergeItemPropertyValues(targetItemKey, change.propertyValueChanges);\n await merger.merge(targetItemKey, sourceItem, change);\n }\n }\n /**\n * Merges the property values.\n * @param targetItem The current schema item\n * @param changes The property changes.\n */\n private async mergeItemPropertyValues(targetItemKey: SchemaItemKey, changes: PropertyValueChange[]) {\n // No need to process anything if no properties differ.\n if(changes.length === 0) {\n return;\n }\n\n const targetItem = (await this.context.targetSchema.lookupItem<SchemaItem>(targetItemKey));\n const jsonProps = (targetItem?.toJSON() ?? {}) as MutableSchemaItemProps<TItem>;\n const propertyResolver = await this.createPropertyValueResolver();\n\n for(const change of changes) {\n const [propertyName, propertyNewValue, propertyOldValue] = change.diagnostic.messageArgs! as [keyof typeof jsonProps, any, any];\n const resolver = propertyResolver[propertyName];\n jsonProps[propertyName] = resolver !== undefined\n ? resolver(propertyNewValue, targetItemKey, propertyOldValue)\n : propertyNewValue;\n }\n\n await this.context.editor.schemaItems.applyProps(targetItemKey, jsonProps);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAkB,MAAM,0BAA0B,CAAC;AAGlE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"SchemaMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAkB,MAAM,0BAA0B,CAAC;AAGlE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAcxD;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC;CACtC;AAED;;;;GAIG;AACH,qBAAa,YAAY;IACvB;;;;;;;OAOG;YACW,gBAAgB;IAW9B;;;;;OAKG;IACU,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CA0ChF"}
|
|
@@ -21,6 +21,7 @@ const StructClassMerger_1 = require("./StructClassMerger");
|
|
|
21
21
|
const MixinMerger_1 = require("./MixinMerger");
|
|
22
22
|
const CustomAttributeMerger_1 = require("./CustomAttributeMerger");
|
|
23
23
|
const KindOfQuantityMerger_1 = require("./KindOfQuantityMerger");
|
|
24
|
+
const RelationshipClassMerger_1 = require("./RelationshipClassMerger");
|
|
24
25
|
/**
|
|
25
26
|
* Class to merge two schemas together.
|
|
26
27
|
* @see [[merge]] to merge the schemas.
|
|
@@ -70,11 +71,13 @@ class SchemaMerger {
|
|
|
70
71
|
await StructClassMerger_1.default.mergeItemStubChanges(mergeContext, itemChanges.structClasses);
|
|
71
72
|
await EntityClassMerger_1.default.mergeItemStubChanges(mergeContext, itemChanges.entityClasses);
|
|
72
73
|
await MixinMerger_1.default.mergeItemStubChanges(mergeContext, itemChanges.mixins);
|
|
74
|
+
await RelationshipClassMerger_1.default.mergeItemStubChanges(mergeContext, itemChanges.relationships);
|
|
73
75
|
// 2nd pass to complete merge changes such as properties, baseClasses and mixins.
|
|
74
76
|
await CAClassMerger_1.default.mergeItemContentChanges(mergeContext, itemChanges.customAttributeClasses);
|
|
75
77
|
await StructClassMerger_1.default.mergeItemContentChanges(mergeContext, itemChanges.structClasses);
|
|
76
78
|
await EntityClassMerger_1.default.mergeItemContentChanges(mergeContext, itemChanges.entityClasses);
|
|
77
79
|
await MixinMerger_1.default.mergeItemContentChanges(mergeContext, itemChanges.mixins);
|
|
80
|
+
await RelationshipClassMerger_1.default.mergeItemContentChanges(mergeContext, itemChanges.relationships);
|
|
78
81
|
await (0, CustomAttributeMerger_1.mergeCustomAttributes)(mergeContext, schemaChanges.customAttributeChanges.values(), async (ca) => {
|
|
79
82
|
return mergeContext.editor.addCustomAttribute(mergeContext.targetSchema.schemaKey, ca);
|
|
80
83
|
});
|
|
@@ -90,16 +93,17 @@ exports.SchemaMerger = SchemaMerger;
|
|
|
90
93
|
*/
|
|
91
94
|
function getSchemaItemChanges(schemaChanges) {
|
|
92
95
|
return {
|
|
93
|
-
get entityClasses() { return filterChangesByItemType(schemaChanges.classChanges, ecschema_metadata_1.SchemaItemType.EntityClass); },
|
|
94
96
|
get constants() { return filterChangesByItemType(schemaChanges.schemaItemChanges, ecschema_metadata_1.SchemaItemType.Constant); },
|
|
95
97
|
get customAttributeClasses() { return filterChangesByItemType(schemaChanges.classChanges, ecschema_metadata_1.SchemaItemType.CustomAttributeClass); },
|
|
98
|
+
get entityClasses() { return filterChangesByItemType(schemaChanges.classChanges, ecschema_metadata_1.SchemaItemType.EntityClass); },
|
|
96
99
|
get enumeratations() { return schemaChanges.enumerationChanges.values(); },
|
|
97
100
|
get kindOfQuantities() { return schemaChanges.kindOfQuantityChanges.values(); },
|
|
101
|
+
get mixins() { return filterChangesByItemType(schemaChanges.classChanges, ecschema_metadata_1.SchemaItemType.Mixin); },
|
|
98
102
|
get phenomenons() { return filterChangesByItemType(schemaChanges.schemaItemChanges, ecschema_metadata_1.SchemaItemType.Phenomenon); },
|
|
99
103
|
get propertyCategories() { return filterChangesByItemType(schemaChanges.schemaItemChanges, ecschema_metadata_1.SchemaItemType.PropertyCategory); },
|
|
100
|
-
get
|
|
104
|
+
get relationships() { return filterChangesByItemType(schemaChanges.classChanges, ecschema_metadata_1.SchemaItemType.RelationshipClass); },
|
|
101
105
|
get structClasses() { return filterChangesByItemType(schemaChanges.classChanges, ecschema_metadata_1.SchemaItemType.StructClass); },
|
|
102
|
-
get
|
|
106
|
+
get unitSystems() { return filterChangesByItemType(schemaChanges.schemaItemChanges, ecschema_metadata_1.SchemaItemType.UnitSystem); },
|
|
103
107
|
};
|
|
104
108
|
}
|
|
105
109
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAkE;AAElE,iEAA8D;AAC9D,8CAAwD;AACxD,yDAAsD;AAEtD,mEAA4D;AAC5D,mDAA4C;AAC5C,2DAAoD;AACpD,qDAA+C;AAC/C,2DAAoD;AACpD,2DAAoD;AACpD,+CAAwC;AACxC,mEAAgE;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,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE;YACzC,MAAM,MAAM,CAAC;SACd;KACF;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Merging\r\n */\r\n\r\nimport { Schema, SchemaItemType } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaChanges, SchemaItemChanges } from \"../Validation/SchemaChanges\";\r\nimport { SchemaComparer } from \"../Validation/SchemaComparer\";\r\nimport { SchemaContextEditor } from \"../Editing/Editor\";\r\nimport { SchemaItemMerger } from \"./SchemaItemMerger\";\r\n\r\nimport mergeSchemaReferences from \"./SchemaReferenceMerger\";\r\nimport CAClassMerger from \"./CAClassMerger\";\r\nimport EnumerationMerger from \"./EnumerationMerger\";\r\nimport ConstantsMerger from \"./ConstantMerger\";\r\nimport EntityClassMerger from \"./EntityClassMerger\";\r\nimport StructClassMerger from \"./StructClassMerger\";\r\nimport MixinMerger from \"./MixinMerger\";\r\nimport { mergeCustomAttributes } from \"./CustomAttributeMerger\";\r\nimport KindOfQuantityMerger from \"./KindOfQuantityMerger\";\r\n\r\n/**\r\n * Defines the context of a Schema merging run.\r\n * @beta\r\n */\r\nexport interface SchemaMergeContext {\r\n readonly targetSchema: Schema;\r\n readonly sourceSchema: Schema;\r\n readonly editor: SchemaContextEditor;\r\n}\r\n\r\n/**\r\n * Class to merge two schemas together.\r\n * @see [[merge]] to merge the schemas.\r\n * @beta\r\n */\r\nexport class SchemaMerger {\r\n /**\r\n * Gets the @see SchemaChanges between the two given Schemas from perspective of the source\r\n * to the target schema. For example if source contains a class which does not exists in the\r\n * target one, it would be listed as missing.\r\n * @param targetSchema The schema the differences gets merged into.\r\n * @param sourceSchema The schema to compare.\r\n * @returns An instance of @see SchemaChanges between the two schemas.\r\n */\r\n private async getSchemaChanges(targetSchema: Schema, sourceSchema: Schema): Promise<SchemaChanges> {\r\n const changesList: SchemaChanges[] = [];\r\n const schemaComparer = new SchemaComparer({ report: changesList.push.bind(changesList) });\r\n\r\n // It is important to compare the schema items by name, not full name as otherwise\r\n // we'd often see differences when comparing two different schemas.\r\n await schemaComparer.compareSchemas(sourceSchema, targetSchema);\r\n\r\n return changesList[0];\r\n }\r\n\r\n /**\r\n * Copy the SchemaItems of the source schemas to the target schema.\r\n * @param targetSchema The schema the SchemaItems gets merged to.\r\n * @param sourceSchema The schema the SchemaItems gets copied from.\r\n * @returns The merged target schema.\r\n */\r\n public async merge(targetSchema: Schema, sourceSchema: Schema): Promise<Schema> {\r\n const schemaChanges = await this.getSchemaChanges(targetSchema, sourceSchema);\r\n const mergeContext: SchemaMergeContext = {\r\n editor: new SchemaContextEditor(targetSchema.context),\r\n targetSchema,\r\n sourceSchema,\r\n };\r\n\r\n await mergeSchemaReferences(mergeContext, schemaChanges);\r\n\r\n const itemChanges = getSchemaItemChanges(schemaChanges);\r\n await EnumerationMerger.mergeChanges(mergeContext, itemChanges.enumeratations);\r\n await SchemaItemMerger.mergeChanges(mergeContext, itemChanges.propertyCategories);\r\n\r\n await SchemaItemMerger.mergeChanges(mergeContext, itemChanges.unitSystems);\r\n await SchemaItemMerger.mergeChanges(mergeContext, itemChanges.phenomenons);\r\n await ConstantsMerger.mergeChanges(mergeContext, itemChanges.constants);\r\n await KindOfQuantityMerger.mergeChanges(mergeContext, itemChanges.kindOfQuantities);\r\n\r\n // TODO: For now we just do simple copy and merging of properties and classes. For more complex types\r\n // with bases classes or relationships, this might need to get extended.\r\n await CAClassMerger.mergeItemStubChanges(mergeContext, itemChanges.customAttributeClasses);\r\n await StructClassMerger.mergeItemStubChanges(mergeContext, itemChanges.structClasses);\r\n await EntityClassMerger.mergeItemStubChanges(mergeContext, itemChanges.entityClasses);\r\n await MixinMerger.mergeItemStubChanges(mergeContext, itemChanges.mixins);\r\n\r\n // 2nd pass to complete merge changes such as properties, baseClasses and mixins.\r\n await CAClassMerger.mergeItemContentChanges(mergeContext, itemChanges.customAttributeClasses);\r\n await StructClassMerger.mergeItemContentChanges(mergeContext, itemChanges.structClasses);\r\n await EntityClassMerger.mergeItemContentChanges(mergeContext, itemChanges.entityClasses);\r\n await MixinMerger.mergeItemContentChanges(mergeContext, itemChanges.mixins);\r\n\r\n await mergeCustomAttributes(mergeContext, schemaChanges.customAttributeChanges.values(), async (ca) => {\r\n return mergeContext.editor.addCustomAttribute(mergeContext.targetSchema.schemaKey, ca);\r\n });\r\n\r\n // TODO: For now we directly manipulate the target schema. For error handing purposes, we should first\r\n // merge into a temporary schema and eventually swap that with the given instance.\r\n return targetSchema;\r\n }\r\n}\r\n\r\n/**\r\n * This helper method composes the different schema change objects to a single easier\r\n * to use object that should improve readability when the methods get called.\r\n */\r\nfunction getSchemaItemChanges(schemaChanges: SchemaChanges) {\r\n return {\r\n get entityClasses() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.EntityClass); },\r\n get constants() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.Constant); },\r\n get customAttributeClasses() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.CustomAttributeClass); },\r\n get enumeratations() { return schemaChanges.enumerationChanges.values(); },\r\n get kindOfQuantities() { return schemaChanges.kindOfQuantityChanges.values(); },\r\n get phenomenons() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.Phenomenon); },\r\n get propertyCategories() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.PropertyCategory); },\r\n get unitSystems() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.UnitSystem); },\r\n get structClasses() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.StructClass); },\r\n get mixins() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.Mixin); },\r\n };\r\n}\r\n\r\n/**\r\n * Filters and returns the changed items by its schema item type.\r\n * @param changes A map of changed schema items.\r\n * @param types A list of schema item types to filter.\r\n * @returns An Iterable with the filtered schema items.\r\n */\r\nfunction * filterChangesByItemType<TChange extends SchemaItemChanges>(changes: Map<string, TChange>, ...types: SchemaItemType[]): Iterable<TChange> {\r\n for(const change of changes.values()) {\r\n if (types.includes(change.schemaItemType)) {\r\n yield change;\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"SchemaMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAkE;AAElE,iEAA8D;AAC9D,8CAAwD;AACxD,yDAAsD;AAEtD,mEAA4D;AAC5D,mDAA4C;AAC5C,2DAAoD;AACpD,qDAA+C;AAC/C,2DAAoD;AACpD,2DAAoD;AACpD,+CAAwC;AACxC,mEAAgE;AAChE,iEAA0D;AAC1D,uEAAgE;AAYhE;;;;GAIG;AACH,MAAa,YAAY;IACvB;;;;;;;OAOG;IACK,KAAK,CAAC,gBAAgB,CAAC,YAAoB,EAAE,YAAoB;QACvE,MAAM,WAAW,GAAoB,EAAE,CAAC;QACxC,MAAM,cAAc,GAAG,IAAI,+BAAc,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QAE1F,kFAAkF;QAClF,mEAAmE;QACnE,MAAM,cAAc,CAAC,cAAc,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;QAEhE,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,KAAK,CAAC,YAAoB,EAAE,YAAoB;QAC3D,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;QAC9E,MAAM,YAAY,GAAuB;YACvC,MAAM,EAAE,IAAI,4BAAmB,CAAC,YAAY,CAAC,OAAO,CAAC;YACr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O,uBAAuB,CAAC,aAAa,CAAC,YAAY,EAAE,kCAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAClG,IAAI,WAAW,KAAK,OAAO,uBAAuB,CAAC,aAAa,CAAC,iBAAiB,EAAE,kCAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACjH,IAAI,kBAAkB,KAAK,OAAO,uBAAuB,CAAC,aAAa,CAAC,iBAAiB,EAAE,kCAAc,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;QAC9H,IAAI,aAAa,KAAK,OAAO,uBAAuB,CAAC,aAAa,CAAC,YAAY,EAAE,kCAAc,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;QACrH,IAAI,aAAa,KAAK,OAAO,uBAAuB,CAAC,aAAa,CAAC,YAAY,EAAE,kCAAc,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QAC/G,IAAI,WAAW,KAAK,OAAO,uBAAuB,CAAC,aAAa,CAAC,iBAAiB,EAAE,kCAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;KAClH,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,QAAS,CAAC,CAAC,uBAAuB,CAAoC,OAA6B,EAAE,GAAG,KAAuB;IAC7H,KAAI,MAAM,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE;QACpC,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE;YACzC,MAAM,MAAM,CAAC;SACd;KACF;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Merging\n */\n\nimport { Schema, SchemaItemType } from \"@itwin/ecschema-metadata\";\nimport { SchemaChanges, SchemaItemChanges } from \"../Validation/SchemaChanges\";\nimport { SchemaComparer } from \"../Validation/SchemaComparer\";\nimport { SchemaContextEditor } from \"../Editing/Editor\";\nimport { SchemaItemMerger } from \"./SchemaItemMerger\";\n\nimport mergeSchemaReferences from \"./SchemaReferenceMerger\";\nimport CAClassMerger from \"./CAClassMerger\";\nimport EnumerationMerger from \"./EnumerationMerger\";\nimport ConstantsMerger from \"./ConstantMerger\";\nimport EntityClassMerger from \"./EntityClassMerger\";\nimport StructClassMerger from \"./StructClassMerger\";\nimport MixinMerger from \"./MixinMerger\";\nimport { mergeCustomAttributes } from \"./CustomAttributeMerger\";\nimport KindOfQuantityMerger from \"./KindOfQuantityMerger\";\nimport RelationshipClassMerger from \"./RelationshipClassMerger\";\n\n/**\n * Defines the context of a Schema merging run.\n * @beta\n */\nexport interface SchemaMergeContext {\n readonly targetSchema: Schema;\n readonly sourceSchema: Schema;\n readonly editor: SchemaContextEditor;\n}\n\n/**\n * Class to merge two schemas together.\n * @see [[merge]] to merge the schemas.\n * @beta\n */\nexport class SchemaMerger {\n /**\n * Gets the @see SchemaChanges between the two given Schemas from perspective of the source\n * to the target schema. For example if source contains a class which does not exists in the\n * target one, it would be listed as missing.\n * @param targetSchema The schema the differences gets merged into.\n * @param sourceSchema The schema to compare.\n * @returns An instance of @see SchemaChanges between the two schemas.\n */\n private async getSchemaChanges(targetSchema: Schema, sourceSchema: Schema): Promise<SchemaChanges> {\n const changesList: SchemaChanges[] = [];\n const schemaComparer = new SchemaComparer({ report: changesList.push.bind(changesList) });\n\n // It is important to compare the schema items by name, not full name as otherwise\n // we'd often see differences when comparing two different schemas.\n await schemaComparer.compareSchemas(sourceSchema, targetSchema);\n\n return changesList[0];\n }\n\n /**\n * Copy the SchemaItems of the source schemas to the target schema.\n * @param targetSchema The schema the SchemaItems gets merged to.\n * @param sourceSchema The schema the SchemaItems gets copied from.\n * @returns The merged target schema.\n */\n public async merge(targetSchema: Schema, sourceSchema: Schema): Promise<Schema> {\n const schemaChanges = await this.getSchemaChanges(targetSchema, sourceSchema);\n const mergeContext: SchemaMergeContext = {\n editor: new SchemaContextEditor(targetSchema.context),\n targetSchema,\n sourceSchema,\n };\n\n await mergeSchemaReferences(mergeContext, schemaChanges);\n\n const itemChanges = getSchemaItemChanges(schemaChanges);\n await EnumerationMerger.mergeChanges(mergeContext, itemChanges.enumeratations);\n await SchemaItemMerger.mergeChanges(mergeContext, itemChanges.propertyCategories);\n\n await SchemaItemMerger.mergeChanges(mergeContext, itemChanges.unitSystems);\n await SchemaItemMerger.mergeChanges(mergeContext, itemChanges.phenomenons);\n await ConstantsMerger.mergeChanges(mergeContext, itemChanges.constants);\n await KindOfQuantityMerger.mergeChanges(mergeContext, itemChanges.kindOfQuantities);\n\n // TODO: For now we just do simple copy and merging of properties and classes. For more complex types\n // with bases classes or relationships, this might need to get extended.\n await CAClassMerger.mergeItemStubChanges(mergeContext, itemChanges.customAttributeClasses);\n await StructClassMerger.mergeItemStubChanges(mergeContext, itemChanges.structClasses);\n await EntityClassMerger.mergeItemStubChanges(mergeContext, itemChanges.entityClasses);\n await MixinMerger.mergeItemStubChanges(mergeContext, itemChanges.mixins);\n await RelationshipClassMerger.mergeItemStubChanges(mergeContext, itemChanges.relationships);\n\n // 2nd pass to complete merge changes such as properties, baseClasses and mixins.\n await CAClassMerger.mergeItemContentChanges(mergeContext, itemChanges.customAttributeClasses);\n await StructClassMerger.mergeItemContentChanges(mergeContext, itemChanges.structClasses);\n await EntityClassMerger.mergeItemContentChanges(mergeContext, itemChanges.entityClasses);\n await MixinMerger.mergeItemContentChanges(mergeContext, itemChanges.mixins);\n await RelationshipClassMerger.mergeItemContentChanges(mergeContext, itemChanges.relationships);\n\n await mergeCustomAttributes(mergeContext, schemaChanges.customAttributeChanges.values(), async (ca) => {\n return mergeContext.editor.addCustomAttribute(mergeContext.targetSchema.schemaKey, ca);\n });\n\n // TODO: For now we directly manipulate the target schema. For error handing purposes, we should first\n // merge into a temporary schema and eventually swap that with the given instance.\n return targetSchema;\n }\n}\n\n/**\n * This helper method composes the different schema change objects to a single easier\n * to use object that should improve readability when the methods get called.\n */\nfunction getSchemaItemChanges(schemaChanges: SchemaChanges) {\n return {\n get constants() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.Constant); },\n get customAttributeClasses() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.CustomAttributeClass); },\n get entityClasses() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.EntityClass); },\n get enumeratations() { return schemaChanges.enumerationChanges.values(); },\n get kindOfQuantities() { return schemaChanges.kindOfQuantityChanges.values(); },\n get mixins() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.Mixin); },\n get phenomenons() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.Phenomenon); },\n get propertyCategories() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.PropertyCategory); },\n get relationships() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.RelationshipClass); },\n get structClasses() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.StructClass); },\n get unitSystems() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.UnitSystem); },\n };\n}\n\n/**\n * Filters and returns the changed items by its schema item type.\n * @param changes A map of changed schema items.\n * @param types A list of schema item types to filter.\n * @returns An Iterable with the filtered schema items.\n */\nfunction * filterChangesByItemType<TChange extends SchemaItemChanges>(changes: Map<string, TChange>, ...types: SchemaItemType[]): Iterable<TChange> {\n for(const change of changes.values()) {\n if (types.includes(change.schemaItemType)) {\n yield change;\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaReferenceMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaReferenceMerger.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,gEAAmE;AAInE;;;;;GAKG;AACY,KAAK,UAAU,qBAAqB,CAAC,YAAgC,EAAE,OAAsB;IAC1G,MAAM,YAAY,GAAG,YAAY,CAAC,YAAY,CAAC;IAE/C,kFAAkF;IAClF,4FAA4F;IAC5F,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;KACxF;AACH,CAAC;AA/BD,wCA+BC;AAED;;;;;GAKG;AACH,SAAS,cAAc,CAAC,IAAY,EAAE,KAAa;IACjD,OAAO,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC;QACzD,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC;QACf,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACpB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\
|
|
1
|
+
{"version":3,"file":"SchemaReferenceMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaReferenceMerger.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,gEAAmE;AAInE;;;;;GAKG;AACY,KAAK,UAAU,qBAAqB,CAAC,YAAgC,EAAE,OAAsB;IAC1G,MAAM,YAAY,GAAG,YAAY,CAAC,YAAY,CAAC;IAE/C,kFAAkF;IAClF,4FAA4F;IAC5F,KAAI,MAAM,sBAAsB,IAAI,OAAO,CAAC,uBAAuB,EAAE;QACnE,MAAM,CAAC,gBAAgB,CAAC,GAAG,sBAAsB,CAAC,UAAU,CAAC,WAAwB,CAAC;QACtF,MAAM,YAAY,CAAC,MAAM,CAAC,kBAAkB,CAAC,YAAY,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;KACxF;IAED,iFAAiF;IACjF,qFAAqF;IACrF,qFAAqF;IACrF,8BAA8B;IAC9B,KAAI,MAAM,wBAAwB,IAAI,OAAO,CAAC,qBAAqB,EAAE;QACnE,MAAM,CAAC,gBAAgB,CAAC,GAAG,wBAAwB,CAAC,UAAU,CAAC,WAAwB,CAAC;QACxF,MAAM,cAAc,GAAG,CAAC,MAAM,YAAY,CAAC,YAAY,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAE,CAAC;QAEjF,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,cAAc,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;QACzE,IAAG,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,mCAAe,CAAC,qBAAqB,CAAC,EAAE;YACpF,MAAM,IAAI,KAAK,CAAC,yBAAyB,gBAAgB,CAAC,IAAI,gCAAgC,KAAK,CAAC,SAAS,CAAC,OAAO,QAAQ,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;SAC1J;QACD,IAAG,MAAM,KAAK,cAAc,EAAE;YAC5B,SAAS;SACV;QAED,MAAM,KAAK,GAAG,YAAY,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,KAAK,cAAc,CAAC,CAAC;QAC7F,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAEzC,MAAM,YAAY,CAAC,MAAM,CAAC,kBAAkB,CAAC,YAAY,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;KACxF;AACH,CAAC;AA/BD,wCA+BC;AAED;;;;;GAKG;AACH,SAAS,cAAc,CAAC,IAAY,EAAE,KAAa;IACjD,OAAO,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC;QACzD,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC;QACf,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACpB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { Schema, SchemaMatchType } from \"@itwin/ecschema-metadata\";\nimport { SchemaChanges } from \"../Validation/SchemaChanges\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\n\n/**\n * Merges the schema references of two schemas.\n * @param mergeContext current merge context\n * @param changes schema changes.\n * @internal\n */\nexport default async function mergeSchemaReferences(mergeContext: SchemaMergeContext, changes: SchemaChanges) {\n const targetSchema = mergeContext.targetSchema;\n\n // If the target schema does not have a reference to a schema yet, it can be added\n // but should be checked if it's schema references have collisions with existing references.\n for(const missingSchemaReference of changes.missingSchemaReferences) {\n const [referencedSchema] = missingSchemaReference.diagnostic.messageArgs! as [Schema];\n await mergeContext.editor.addSchemaReference(targetSchema.schemaKey, referencedSchema);\n }\n\n // If the source schema referenced a schema that is also referenced by the target\n // schema but in a different version, it is marked as delta. Here we need to check if\n // the source schema is compatible to the existing one. This is not be checked by the\n // schema instance when added.\n for(const differentSchemaReference of changes.schemaReferenceDeltas) {\n const [referencedSchema] = differentSchemaReference.diagnostic.messageArgs! as [Schema];\n const existingSchema = (await targetSchema.getReference(referencedSchema.name))!;\n\n const [older, latest] = compareSchemas(existingSchema, referencedSchema);\n if(!latest.schemaKey.matches(older.schemaKey, SchemaMatchType.LatestWriteCompatible)) {\n throw new Error(`Schemas references of ${referencedSchema.name} have incompatible versions: ${older.schemaKey.version} and ${latest.schemaKey.version}`);\n }\n if(latest === existingSchema) {\n continue;\n }\n\n const index = targetSchema.references.findIndex((reference) => reference === existingSchema);\n targetSchema.references.splice(index, 1);\n\n await mergeContext.editor.addSchemaReference(targetSchema.schemaKey, referencedSchema);\n }\n}\n\n/**\n * Compares the schemas and return them in order of their versions [older, latest].\n * @param left The first schema to be added.\n * @param right The second schema to be added.\n * @returns The schemas in order.\n */\nfunction compareSchemas(left: Schema, right: Schema): [Schema, Schema] {\n return left.schemaKey.compareByVersion(right.schemaKey) < 0\n ? [left, right]\n : [right, left];\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StructClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/StructClassMerger.ts"],"names":[],"mappings":";;AAKA,+CAA4C;AAG5C;;GAEG;AACH,MAAqB,iBAAkB,SAAQ,yBAAwB;IAElD,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,OAAoB;QACxE,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACrE,CAAC;CACF;AALD,oCAKC","sourcesContent":["/*---------------------------------------------------------------------------------------------\
|
|
1
|
+
{"version":3,"file":"StructClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/StructClassMerger.ts"],"names":[],"mappings":";;AAKA,+CAA4C;AAG5C;;GAEG;AACH,MAAqB,iBAAkB,SAAQ,yBAAwB;IAElD,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,OAAoB;QACxE,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACrE,CAAC;CACF;AALD,oCAKC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { SchemaKey, StructClass } from \"@itwin/ecschema-metadata\";\nimport { ClassMerger } from \"./ClassMerger\";\nimport { SchemaItemEditResults } from \"../Editing/Editor\";\n\n/**\n * @internal\n */\nexport default class StructClassMerger extends ClassMerger<StructClass> {\n\n protected override async create(schemaKey: SchemaKey, ecClass: StructClass): Promise<SchemaItemEditResults> {\n return this.context.editor.structs.create(schemaKey, ecClass.name);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diagnostic.js","sourceRoot":"","sources":["../../../src/Validation/Diagnostic.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAIH,iDAAiD;AAEjD,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,GAAG,IAAc,EAAE,EAAE;IACzD,OAAO,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;QACrD,OAAO,OAAO,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0BAA0B,CAAC;QACpC,KAAK,cAAc,CAAC,IAAI;YACtB,OAAO,MAAM,CAAC;QAChB,KAAK,cAAc,CAAC,QAAQ;YAC1B,OAAO,UAAU,CAAC;QACpB,KAAK,cAAc,CAAC,sBAAsB;YACxC,OAAO,wBAAwB,CAAC;QAClC,KAAK,cAAc,CAAC,MAAM;YACxB,OAAO,QAAQ,CAAC;QAClB,KAAK,cAAc,CAAC,UAAU;YAC5B,OAAO,YAAY,CAAC;KACvB;AACH,CAAC;AAfD,wDAeC;AAED,SAAS,YAAY,CAAC,IAAY;IAChC,MAAM,GAAG,GAAG,mBAAmB,IAAI,0DAA0D,CAAC;IAC9F,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;IAEvB,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Diagnostic\r\n */\r\n\r\nimport { AnyClass, AnyECType, AnyProperty, CustomAttributeContainerProps, RelationshipConstraint, Schema, SchemaItem } from \"@itwin/ecschema-metadata\";\r\n\r\n/* eslint-disable @typescript-eslint/no-shadow */\r\n\r\nconst formatString = (format: string, ...args: string[]) => {\r\n return format.replace(/{(\\d+)}/g, (match, theNumber) => {\r\n return typeof args[theNumber] !== \"undefined\"\r\n ? args[theNumber]\r\n : match;\r\n });\r\n};\r\n\r\n/**\r\n * Defines the possible diagnostic types.\r\n * @beta\r\n */\r\nexport enum DiagnosticType {\r\n None,\r\n Schema, // eslint-disable-line @typescript-eslint/no-shadow\r\n SchemaItem, // eslint-disable-line @typescript-eslint/no-shadow\r\n Property,\r\n CustomAttributeContainer,\r\n RelationshipConstraint, // eslint-disable-line @typescript-eslint/no-shadow\r\n}\r\n\r\n/**\r\n * Defines the possible diagnostic categories.\r\n * @beta\r\n */\r\nexport enum DiagnosticCategory {\r\n Warning,\r\n Error,\r\n Suggestion,\r\n Message,\r\n}\r\n\r\n/**\r\n * The interface implemented by all diagnostics used during schema validation.\r\n * @beta\r\n */\r\nexport interface IDiagnostic<TYPE extends AnyECType, ARGS extends any[]> {\r\n /** The diagnostic category (error, warning, etc...). Value is static across all instances. */\r\n category: DiagnosticCategory;\r\n /** The unique string identifier of the diagnostic in the format '<ruleSetName>:<number>. Value is static across all instances. */\r\n code: string;\r\n /** The context type of diagnostic (schema, schema item, property, etc...). Value is static across all instances. */\r\n diagnosticType: DiagnosticType;\r\n /** The unformatted message text associated with the diagnostic. Value is static across all instances. */\r\n messageText: string;\r\n /** The arguments used when formatted the diagnostic instance's message. */\r\n messageArgs?: ARGS;\r\n /** The EC object associated with the diagnostic instance. */\r\n ecDefinition: TYPE;\r\n /** The schema where the diagnostic originated. */\r\n schema: Schema;\r\n}\r\n\r\n/**\r\n * Type which encapsulates all possible diagnostics.\r\n * @beta\r\n */\r\nexport type AnyDiagnostic = IDiagnostic<AnyECType, any[]>;\r\n\r\n/**\r\n * The abstract base class for all [[IDiagnostic]] implementations.\r\n * @beta\r\n */\r\nexport abstract class BaseDiagnostic<TYPE extends AnyECType, ARGS extends any[]> implements IDiagnostic<TYPE, ARGS> {\r\n /**\r\n * Initializes a new BaseDiagnostic.\r\n * @param ecDefinition The EC object to associate with the diagnostic.\r\n * @param messageArgs The arguments used when formatting the diagnostic message.\r\n * @param category The [[DiagnosticCategory]] to associate with the diagnostic, Error by default.\r\n */\r\n constructor(ecDefinition: TYPE, messageArgs?: ARGS, category: DiagnosticCategory = DiagnosticCategory.Error) {\r\n this.ecDefinition = ecDefinition;\r\n this.messageArgs = messageArgs;\r\n this.category = category;\r\n }\r\n\r\n /** Gets the unique string identifier for the diagnostic in the format '<ruleSetName>:<number>'. */\r\n public abstract get code(): string;\r\n /** Gets the context type of the diagnostic (schema, schema item, property, etc...) */\r\n public abstract get diagnosticType(): DiagnosticType;\r\n /** Gets the message associated with the diagnostic. */\r\n public abstract get messageText(): string;\r\n /** Gets the schema where the diagnostic originated. */\r\n public abstract get schema(): Schema;\r\n\r\n /** The EC object to associate with the diagnostic. */\r\n public ecDefinition: TYPE;\r\n /** The arguments used when formatting the diagnostic message. */\r\n public messageArgs?: ARGS;\r\n /** The diagnostic category is of the type DiagnosticCategory; which is defined as an enumeration above. */\r\n public category: DiagnosticCategory;\r\n}\r\n\r\n/**\r\n * An [[IDiagnostic]] implementation used for [[Schema]] diagnostics.\r\n * @beta\r\n */\r\nexport abstract class SchemaDiagnostic<ARGS extends any[]> extends BaseDiagnostic<Schema, ARGS> {\r\n public static diagnosticType = DiagnosticType.SchemaItem;\r\n\r\n /**\r\n * Initializes a new SchemaDiagnostic.\r\n * @param ecDefinition The EC object to associate with the diagnostic.\r\n * @param messageArgs The arguments used when formatting the diagnostic message.\r\n * @param category The [[DiagnosticCategory]] to associate with the diagnostic, Error by default.\r\n */\r\n constructor(schema: Schema, messageArgs: ARGS, category: DiagnosticCategory = DiagnosticCategory.Error) {\r\n super(schema, messageArgs, category);\r\n }\r\n\r\n /** Gets the schema where the diagnostic originated. */\r\n public get schema(): Schema { return this.ecDefinition; }\r\n\r\n /** Gets the DiagnosticType. */\r\n public get diagnosticType(): DiagnosticType { return DiagnosticType.Schema; }\r\n}\r\n\r\n/**\r\n * An [[IDiagnostic]] implementation used for [[SchemaItem]] diagnostics.\r\n * @beta\r\n */\r\nexport abstract class SchemaItemDiagnostic<TYPE extends SchemaItem, ARGS extends any[]> extends BaseDiagnostic<TYPE, ARGS> {\r\n public static diagnosticType = DiagnosticType.SchemaItem;\r\n /**\r\n * Initializes a new SchemaItemDiagnostic.\r\n * @param ecDefinition The EC object to associate with the diagnostic.\r\n * @param messageArgs The arguments used when formatting the diagnostic message.\r\n * @param category The [[DiagnosticCategory]] to associate with the diagnostic, Error by default.\r\n */\r\n constructor(ecDefinition: SchemaItem, messageArgs: ARGS, category: DiagnosticCategory = DiagnosticCategory.Error) {\r\n super(ecDefinition as TYPE, messageArgs, category);\r\n }\r\n\r\n /** Gets the schema where the diagnostic originated. */\r\n public get schema(): Schema { return this.ecDefinition.schema; }\r\n\r\n /** Gets the DiagnosticType. */\r\n public get diagnosticType(): DiagnosticType { return DiagnosticType.SchemaItem; }\r\n}\r\n\r\n/**\r\n * An [[IDiagnostic]] implementation used for [[ECClass]] diagnostics.\r\n * @beta\r\n */\r\nexport abstract class ClassDiagnostic<ARGS extends any[]> extends SchemaItemDiagnostic<AnyClass, ARGS> {\r\n /**\r\n * Initializes a new ClassDiagnostic.\r\n * @param ecClass The class to associate with the diagnostic.\r\n * @param messageArgs The arguments used when formatting the diagnostic message.\r\n * @param category The [[DiagnosticCategory]] to associate with the diagnostic, Error by default.\r\n */\r\n constructor(ecClass: AnyClass, messageArgs: ARGS, category: DiagnosticCategory = DiagnosticCategory.Error) {\r\n super(ecClass, messageArgs, category);\r\n }\r\n\r\n /** Gets the schema where the diagnostic originated. */\r\n public override get schema(): Schema { return this.ecDefinition.schema; }\r\n}\r\n\r\n/**\r\n * An [[IDiagnostic]] implementation used for [[Property]] diagnostics.\r\n * @beta\r\n */\r\nexport abstract class PropertyDiagnostic<ARGS extends any[]> extends BaseDiagnostic<AnyProperty, ARGS> {\r\n /**\r\n * Initializes a new PropertyDiagnostic.\r\n * @param property The property to associate with the diagnostic.\r\n * @param messageArgs The arguments used when formatting the diagnostic message.\r\n * @param category The [[DiagnosticCategory]] to associate with the diagnostic, Error by default.\r\n */\r\n constructor(property: AnyProperty, messageArgs?: ARGS, category: DiagnosticCategory = DiagnosticCategory.Error) {\r\n super(property, messageArgs, category);\r\n }\r\n\r\n /** Gets the schema where the diagnostic originated. */\r\n public get schema(): Schema { return this.ecDefinition.schema; }\r\n\r\n /** Gets the DiagnosticType. */\r\n public get diagnosticType(): DiagnosticType { return DiagnosticType.Property; }\r\n}\r\n\r\n/**\r\n * An [[IDiagnostic]] implementation used for [[RelationshipConstraint]] diagnostics.\r\n * @beta\r\n */\r\nexport abstract class RelationshipConstraintDiagnostic<ARGS extends any[]> extends BaseDiagnostic<RelationshipConstraint, ARGS> {\r\n /**\r\n * Initializes a new RelationshipConstraintDiagnostic.\r\n * @param constraint The Relationship Constraint to associate with the diagnostic.\r\n * @param messageArgs The arguments used when formatting the diagnostic message.\r\n * @param category The [[DiagnosticCategory]] to associate with the diagnostic, Error by default.\r\n */\r\n constructor(constraint: RelationshipConstraint, messageArgs: ARGS, category: DiagnosticCategory = DiagnosticCategory.Error) {\r\n super(constraint, messageArgs, category);\r\n }\r\n\r\n /** Gets the schema where the diagnostic originated. */\r\n public get schema(): Schema { return this.ecDefinition.schema; }\r\n\r\n /** Gets the DiagnosticType. */\r\n public get diagnosticType(): DiagnosticType { return DiagnosticType.RelationshipConstraint; }\r\n}\r\n\r\n/**\r\n * An [[IDiagnostic]] implementation used for [[CustomAttributeContainerProps]] diagnostics.\r\n * @beta\r\n */\r\nexport abstract class CustomAttributeContainerDiagnostic<ARGS extends any[]> extends BaseDiagnostic<CustomAttributeContainerProps, ARGS> {\r\n /**\r\n * Initializes a new CustomAttributeContainerDiagnostic.\r\n * @param constraint The Custom Attribute Container to associate with the diagnostic.\r\n * @param messageArgs The arguments used when formatting the diagnostic message.\r\n * @param category The [[DiagnosticCategory]] to associate with the diagnostic, Error by default.\r\n */\r\n constructor(container: CustomAttributeContainerProps, messageArgs: ARGS, category: DiagnosticCategory = DiagnosticCategory.Error) {\r\n super(container, messageArgs, category);\r\n }\r\n\r\n /** Gets the schema where the diagnostic originated. */\r\n public get schema(): Schema { return this.ecDefinition.schema; }\r\n\r\n /** Gets the DiagnosticType. */\r\n public get diagnosticType(): DiagnosticType { return DiagnosticType.CustomAttributeContainer; }\r\n}\r\n\r\n/**\r\n * Helper method for creating [[SchemaDiagnostic]] child classes.\r\n * @param code The string that uniquely identifies the diagnostic in the format '<ruleSetName>:<number>'.\r\n * @param messageText The message to associate with the diagnostic class.\r\n * @beta\r\n */\r\nexport function createSchemaDiagnosticClass<ARGS extends any[]>(code: string, messageText: string) {\r\n validateCode(code);\r\n return class extends SchemaDiagnostic<ARGS> {\r\n public static code = code;\r\n public get code(): string { return code; }\r\n public get messageText(): string { return undefined === this.messageArgs ? messageText : formatString(messageText, ...this.messageArgs); }\r\n };\r\n}\r\n\r\n/**\r\n * Helper method for creating [[SchemaItemDiagnostic]] child classes.\r\n * @param code The string that uniquely identifies the diagnostic in the format '<ruleSetName>:<number>'.\r\n * @param messageText The message to associate with the diagnostic class.\r\n * @beta\r\n */\r\nexport function createSchemaItemDiagnosticClass<ITEM extends SchemaItem, ARGS extends any[]>(code: string, messageText: string) {\r\n validateCode(code);\r\n return class extends SchemaItemDiagnostic<ITEM, ARGS> {\r\n public get code(): string { return code; }\r\n public get messageText(): string { return undefined === this.messageArgs ? messageText : formatString(messageText, ...this.messageArgs); }\r\n };\r\n}\r\n\r\n/**\r\n * Helper method for creating [[ClassDiagnostic]] child classes.\r\n * @param code The string that uniquely identifies the diagnostic in the format '<ruleSetName>:<number>'.\r\n * @param messageText The message to associate with the diagnostic class.\r\n * @beta\r\n */\r\nexport function createClassDiagnosticClass<ARGS extends any[]>(code: string, messageText: string) {\r\n validateCode(code);\r\n return class extends ClassDiagnostic<ARGS> {\r\n public get code(): string { return code; }\r\n public get messageText(): string { return undefined === this.messageArgs ? messageText : formatString(messageText, ...this.messageArgs); }\r\n };\r\n}\r\n\r\n/**\r\n * Helper method for creating [[PropertyDiagnostic]] child classes.\r\n * @param code The string that uniquely identifies the diagnostic in the format '<ruleSetName>:<number>'.\r\n * @param messageText The message to associate with the diagnostic class.\r\n * @beta\r\n */\r\nexport function createPropertyDiagnosticClass<ARGS extends any[]>(code: string, messageText: string) {\r\n validateCode(code);\r\n return class extends PropertyDiagnostic<ARGS> {\r\n public static code = code;\r\n public get code(): string { return code; }\r\n public get messageText(): string { return undefined === this.messageArgs ? messageText : formatString(messageText, ...this.messageArgs); }\r\n };\r\n}\r\n\r\n/**\r\n * Helper method for creating [[RelationshipConstraintDiagnostic]] child classes.\r\n * @param code The string that uniquely identifies the type of diagnostic in the format '<ruleSetName>:<number>'.\r\n * @param messageText The message to associate with the diagnostic class.\r\n * @beta\r\n */\r\nexport function createRelationshipConstraintDiagnosticClass<ARGS extends any[]>(code: string, messageText: string) {\r\n validateCode(code);\r\n return class extends RelationshipConstraintDiagnostic<ARGS> {\r\n public get code(): string { return code; }\r\n public get messageText(): string { return undefined === this.messageArgs ? messageText : formatString(messageText, ...this.messageArgs); }\r\n };\r\n}\r\n\r\n/**\r\n * Helper method for creating [[CustomAttributeContainerDiagnostic]] child classes.\r\n * @param code The that uniquely identifies the type of diagnostic in the format '<ruleSetName>:<number>'.\r\n * @param messageText The message to associate with the diagnostic class.\r\n * @beta\r\n */\r\nexport function createCustomAttributeContainerDiagnosticClass<ARGS extends any[]>(code: string, messageText: string) {\r\n validateCode(code);\r\n return class extends CustomAttributeContainerDiagnostic<ARGS> {\r\n public get code(): string { return code; }\r\n public get messageText(): string { return undefined === this.messageArgs ? messageText : formatString(messageText, ...this.messageArgs); }\r\n };\r\n}\r\n\r\n/** @beta */\r\nexport function diagnosticCategoryToString(category: DiagnosticCategory) {\r\n switch (category) {\r\n case DiagnosticCategory.Error:\r\n return \"Error\";\r\n case DiagnosticCategory.Warning:\r\n return \"Warning\";\r\n case DiagnosticCategory.Message:\r\n return \"Message\";\r\n case DiagnosticCategory.Suggestion:\r\n return \"Suggestion\";\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport function diagnosticTypeToString(type: DiagnosticType) {\r\n switch (type) {\r\n case DiagnosticType.CustomAttributeContainer:\r\n return \"CustomAttributeContainer\";\r\n case DiagnosticType.None:\r\n return \"None\";\r\n case DiagnosticType.Property:\r\n return \"Property\";\r\n case DiagnosticType.RelationshipConstraint:\r\n return \"RelationshipConstraint\";\r\n case DiagnosticType.Schema:\r\n return \"Schema\";\r\n case DiagnosticType.SchemaItem:\r\n return \"SchemaItem\";\r\n }\r\n}\r\n\r\nfunction validateCode(code: string) {\r\n const msg = `Diagnostic code ${code} is invalid. Expected the format <ruleSetName>-<number>.`;\r\n const parts = code.split(\"-\");\r\n if (parts.length !== 2)\r\n throw new Error(msg);\r\n\r\n if (isNaN(Number(parts[1])))\r\n throw new Error(msg);\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"Diagnostic.js","sourceRoot":"","sources":["../../../src/Validation/Diagnostic.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAIH,iDAAiD;AAEjD,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,GAAG,IAAc,EAAE,EAAE;IACzD,OAAO,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;QACrD,OAAO,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,WAAW;YAC3C,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC;YACjB,CAAC,CAAC,KAAK,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF;;;GAGG;AACH,IAAY,cAOX;AAPD,WAAY,cAAc;IACxB,mDAAI,CAAA;IACJ,uDAAM,CAAA;IACN,+DAAU,CAAA;IACV,2DAAQ,CAAA;IACR,2FAAwB,CAAA;IACxB,uFAAsB,CAAA;AACxB,CAAC,EAPW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAOzB;AAED;;;GAGG;AACH,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,iEAAO,CAAA;IACP,6DAAK,CAAA;IACL,uEAAU,CAAA;IACV,iEAAO,CAAA;AACT,CAAC,EALW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAK7B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CAAC;IAEvB,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Diagnostic\n */\n\nimport { AnyClass, AnyECType, AnyProperty, CustomAttributeContainerProps, RelationshipConstraint, Schema, SchemaItem } from \"@itwin/ecschema-metadata\";\n\n/* eslint-disable @typescript-eslint/no-shadow */\n\nconst formatString = (format: string, ...args: string[]) => {\n return format.replace(/{(\\d+)}/g, (match, theNumber) => {\n return typeof args[theNumber] !== \"undefined\"\n ? args[theNumber]\n : match;\n });\n};\n\n/**\n * Defines the possible diagnostic types.\n * @beta\n */\nexport enum DiagnosticType {\n None,\n Schema, // eslint-disable-line @typescript-eslint/no-shadow\n SchemaItem, // eslint-disable-line @typescript-eslint/no-shadow\n Property,\n CustomAttributeContainer,\n RelationshipConstraint, // eslint-disable-line @typescript-eslint/no-shadow\n}\n\n/**\n * Defines the possible diagnostic categories.\n * @beta\n */\nexport enum DiagnosticCategory {\n Warning,\n Error,\n Suggestion,\n Message,\n}\n\n/**\n * The interface implemented by all diagnostics used during schema validation.\n * @beta\n */\nexport interface IDiagnostic<TYPE extends AnyECType, ARGS extends any[]> {\n /** The diagnostic category (error, warning, etc...). Value is static across all instances. */\n category: DiagnosticCategory;\n /** The unique string identifier of the diagnostic in the format '<ruleSetName>:<number>. Value is static across all instances. */\n code: string;\n /** The context type of diagnostic (schema, schema item, property, etc...). Value is static across all instances. */\n diagnosticType: DiagnosticType;\n /** The unformatted message text associated with the diagnostic. Value is static across all instances. */\n messageText: string;\n /** The arguments used when formatted the diagnostic instance's message. */\n messageArgs?: ARGS;\n /** The EC object associated with the diagnostic instance. */\n ecDefinition: TYPE;\n /** The schema where the diagnostic originated. */\n schema: Schema;\n}\n\n/**\n * Type which encapsulates all possible diagnostics.\n * @beta\n */\nexport type AnyDiagnostic = IDiagnostic<AnyECType, any[]>;\n\n/**\n * The abstract base class for all [[IDiagnostic]] implementations.\n * @beta\n */\nexport abstract class BaseDiagnostic<TYPE extends AnyECType, ARGS extends any[]> implements IDiagnostic<TYPE, ARGS> {\n /**\n * Initializes a new BaseDiagnostic.\n * @param ecDefinition The EC object to associate with the diagnostic.\n * @param messageArgs The arguments used when formatting the diagnostic message.\n * @param category The [[DiagnosticCategory]] to associate with the diagnostic, Error by default.\n */\n constructor(ecDefinition: TYPE, messageArgs?: ARGS, category: DiagnosticCategory = DiagnosticCategory.Error) {\n this.ecDefinition = ecDefinition;\n this.messageArgs = messageArgs;\n this.category = category;\n }\n\n /** Gets the unique string identifier for the diagnostic in the format '<ruleSetName>:<number>'. */\n public abstract get code(): string;\n /** Gets the context type of the diagnostic (schema, schema item, property, etc...) */\n public abstract get diagnosticType(): DiagnosticType;\n /** Gets the message associated with the diagnostic. */\n public abstract get messageText(): string;\n /** Gets the schema where the diagnostic originated. */\n public abstract get schema(): Schema;\n\n /** The EC object to associate with the diagnostic. */\n public ecDefinition: TYPE;\n /** The arguments used when formatting the diagnostic message. */\n public messageArgs?: ARGS;\n /** The diagnostic category is of the type DiagnosticCategory; which is defined as an enumeration above. */\n public category: DiagnosticCategory;\n}\n\n/**\n * An [[IDiagnostic]] implementation used for [[Schema]] diagnostics.\n * @beta\n */\nexport abstract class SchemaDiagnostic<ARGS extends any[]> extends BaseDiagnostic<Schema, ARGS> {\n public static diagnosticType = DiagnosticType.SchemaItem;\n\n /**\n * Initializes a new SchemaDiagnostic.\n * @param ecDefinition The EC object to associate with the diagnostic.\n * @param messageArgs The arguments used when formatting the diagnostic message.\n * @param category The [[DiagnosticCategory]] to associate with the diagnostic, Error by default.\n */\n constructor(schema: Schema, messageArgs: ARGS, category: DiagnosticCategory = DiagnosticCategory.Error) {\n super(schema, messageArgs, category);\n }\n\n /** Gets the schema where the diagnostic originated. */\n public get schema(): Schema { return this.ecDefinition; }\n\n /** Gets the DiagnosticType. */\n public get diagnosticType(): DiagnosticType { return DiagnosticType.Schema; }\n}\n\n/**\n * An [[IDiagnostic]] implementation used for [[SchemaItem]] diagnostics.\n * @beta\n */\nexport abstract class SchemaItemDiagnostic<TYPE extends SchemaItem, ARGS extends any[]> extends BaseDiagnostic<TYPE, ARGS> {\n public static diagnosticType = DiagnosticType.SchemaItem;\n /**\n * Initializes a new SchemaItemDiagnostic.\n * @param ecDefinition The EC object to associate with the diagnostic.\n * @param messageArgs The arguments used when formatting the diagnostic message.\n * @param category The [[DiagnosticCategory]] to associate with the diagnostic, Error by default.\n */\n constructor(ecDefinition: SchemaItem, messageArgs: ARGS, category: DiagnosticCategory = DiagnosticCategory.Error) {\n super(ecDefinition as TYPE, messageArgs, category);\n }\n\n /** Gets the schema where the diagnostic originated. */\n public get schema(): Schema { return this.ecDefinition.schema; }\n\n /** Gets the DiagnosticType. */\n public get diagnosticType(): DiagnosticType { return DiagnosticType.SchemaItem; }\n}\n\n/**\n * An [[IDiagnostic]] implementation used for [[ECClass]] diagnostics.\n * @beta\n */\nexport abstract class ClassDiagnostic<ARGS extends any[]> extends SchemaItemDiagnostic<AnyClass, ARGS> {\n /**\n * Initializes a new ClassDiagnostic.\n * @param ecClass The class to associate with the diagnostic.\n * @param messageArgs The arguments used when formatting the diagnostic message.\n * @param category The [[DiagnosticCategory]] to associate with the diagnostic, Error by default.\n */\n constructor(ecClass: AnyClass, messageArgs: ARGS, category: DiagnosticCategory = DiagnosticCategory.Error) {\n super(ecClass, messageArgs, category);\n }\n\n /** Gets the schema where the diagnostic originated. */\n public override get schema(): Schema { return this.ecDefinition.schema; }\n}\n\n/**\n * An [[IDiagnostic]] implementation used for [[Property]] diagnostics.\n * @beta\n */\nexport abstract class PropertyDiagnostic<ARGS extends any[]> extends BaseDiagnostic<AnyProperty, ARGS> {\n /**\n * Initializes a new PropertyDiagnostic.\n * @param property The property to associate with the diagnostic.\n * @param messageArgs The arguments used when formatting the diagnostic message.\n * @param category The [[DiagnosticCategory]] to associate with the diagnostic, Error by default.\n */\n constructor(property: AnyProperty, messageArgs?: ARGS, category: DiagnosticCategory = DiagnosticCategory.Error) {\n super(property, messageArgs, category);\n }\n\n /** Gets the schema where the diagnostic originated. */\n public get schema(): Schema { return this.ecDefinition.schema; }\n\n /** Gets the DiagnosticType. */\n public get diagnosticType(): DiagnosticType { return DiagnosticType.Property; }\n}\n\n/**\n * An [[IDiagnostic]] implementation used for [[RelationshipConstraint]] diagnostics.\n * @beta\n */\nexport abstract class RelationshipConstraintDiagnostic<ARGS extends any[]> extends BaseDiagnostic<RelationshipConstraint, ARGS> {\n /**\n * Initializes a new RelationshipConstraintDiagnostic.\n * @param constraint The Relationship Constraint to associate with the diagnostic.\n * @param messageArgs The arguments used when formatting the diagnostic message.\n * @param category The [[DiagnosticCategory]] to associate with the diagnostic, Error by default.\n */\n constructor(constraint: RelationshipConstraint, messageArgs: ARGS, category: DiagnosticCategory = DiagnosticCategory.Error) {\n super(constraint, messageArgs, category);\n }\n\n /** Gets the schema where the diagnostic originated. */\n public get schema(): Schema { return this.ecDefinition.schema; }\n\n /** Gets the DiagnosticType. */\n public get diagnosticType(): DiagnosticType { return DiagnosticType.RelationshipConstraint; }\n}\n\n/**\n * An [[IDiagnostic]] implementation used for [[CustomAttributeContainerProps]] diagnostics.\n * @beta\n */\nexport abstract class CustomAttributeContainerDiagnostic<ARGS extends any[]> extends BaseDiagnostic<CustomAttributeContainerProps, ARGS> {\n /**\n * Initializes a new CustomAttributeContainerDiagnostic.\n * @param constraint The Custom Attribute Container to associate with the diagnostic.\n * @param messageArgs The arguments used when formatting the diagnostic message.\n * @param category The [[DiagnosticCategory]] to associate with the diagnostic, Error by default.\n */\n constructor(container: CustomAttributeContainerProps, messageArgs: ARGS, category: DiagnosticCategory = DiagnosticCategory.Error) {\n super(container, messageArgs, category);\n }\n\n /** Gets the schema where the diagnostic originated. */\n public get schema(): Schema { return this.ecDefinition.schema; }\n\n /** Gets the DiagnosticType. */\n public get diagnosticType(): DiagnosticType { return DiagnosticType.CustomAttributeContainer; }\n}\n\n/**\n * Helper method for creating [[SchemaDiagnostic]] child classes.\n * @param code The string that uniquely identifies the diagnostic in the format '<ruleSetName>:<number>'.\n * @param messageText The message to associate with the diagnostic class.\n * @beta\n */\nexport function createSchemaDiagnosticClass<ARGS extends any[]>(code: string, messageText: string) {\n validateCode(code);\n return class extends SchemaDiagnostic<ARGS> {\n public static code = code;\n public get code(): string { return code; }\n public get messageText(): string { return undefined === this.messageArgs ? messageText : formatString(messageText, ...this.messageArgs); }\n };\n}\n\n/**\n * Helper method for creating [[SchemaItemDiagnostic]] child classes.\n * @param code The string that uniquely identifies the diagnostic in the format '<ruleSetName>:<number>'.\n * @param messageText The message to associate with the diagnostic class.\n * @beta\n */\nexport function createSchemaItemDiagnosticClass<ITEM extends SchemaItem, ARGS extends any[]>(code: string, messageText: string) {\n validateCode(code);\n return class extends SchemaItemDiagnostic<ITEM, ARGS> {\n public get code(): string { return code; }\n public get messageText(): string { return undefined === this.messageArgs ? messageText : formatString(messageText, ...this.messageArgs); }\n };\n}\n\n/**\n * Helper method for creating [[ClassDiagnostic]] child classes.\n * @param code The string that uniquely identifies the diagnostic in the format '<ruleSetName>:<number>'.\n * @param messageText The message to associate with the diagnostic class.\n * @beta\n */\nexport function createClassDiagnosticClass<ARGS extends any[]>(code: string, messageText: string) {\n validateCode(code);\n return class extends ClassDiagnostic<ARGS> {\n public get code(): string { return code; }\n public get messageText(): string { return undefined === this.messageArgs ? messageText : formatString(messageText, ...this.messageArgs); }\n };\n}\n\n/**\n * Helper method for creating [[PropertyDiagnostic]] child classes.\n * @param code The string that uniquely identifies the diagnostic in the format '<ruleSetName>:<number>'.\n * @param messageText The message to associate with the diagnostic class.\n * @beta\n */\nexport function createPropertyDiagnosticClass<ARGS extends any[]>(code: string, messageText: string) {\n validateCode(code);\n return class extends PropertyDiagnostic<ARGS> {\n public static code = code;\n public get code(): string { return code; }\n public get messageText(): string { return undefined === this.messageArgs ? messageText : formatString(messageText, ...this.messageArgs); }\n };\n}\n\n/**\n * Helper method for creating [[RelationshipConstraintDiagnostic]] child classes.\n * @param code The string that uniquely identifies the type of diagnostic in the format '<ruleSetName>:<number>'.\n * @param messageText The message to associate with the diagnostic class.\n * @beta\n */\nexport function createRelationshipConstraintDiagnosticClass<ARGS extends any[]>(code: string, messageText: string) {\n validateCode(code);\n return class extends RelationshipConstraintDiagnostic<ARGS> {\n public get code(): string { return code; }\n public get messageText(): string { return undefined === this.messageArgs ? messageText : formatString(messageText, ...this.messageArgs); }\n };\n}\n\n/**\n * Helper method for creating [[CustomAttributeContainerDiagnostic]] child classes.\n * @param code The that uniquely identifies the type of diagnostic in the format '<ruleSetName>:<number>'.\n * @param messageText The message to associate with the diagnostic class.\n * @beta\n */\nexport function createCustomAttributeContainerDiagnosticClass<ARGS extends any[]>(code: string, messageText: string) {\n validateCode(code);\n return class extends CustomAttributeContainerDiagnostic<ARGS> {\n public get code(): string { return code; }\n public get messageText(): string { return undefined === this.messageArgs ? messageText : formatString(messageText, ...this.messageArgs); }\n };\n}\n\n/** @beta */\nexport function diagnosticCategoryToString(category: DiagnosticCategory) {\n switch (category) {\n case DiagnosticCategory.Error:\n return \"Error\";\n case DiagnosticCategory.Warning:\n return \"Warning\";\n case DiagnosticCategory.Message:\n return \"Message\";\n case DiagnosticCategory.Suggestion:\n return \"Suggestion\";\n }\n}\n\n/** @beta */\nexport function diagnosticTypeToString(type: DiagnosticType) {\n switch (type) {\n case DiagnosticType.CustomAttributeContainer:\n return \"CustomAttributeContainer\";\n case DiagnosticType.None:\n return \"None\";\n case DiagnosticType.Property:\n return \"Property\";\n case DiagnosticType.RelationshipConstraint:\n return \"RelationshipConstraint\";\n case DiagnosticType.Schema:\n return \"Schema\";\n case DiagnosticType.SchemaItem:\n return \"SchemaItem\";\n }\n}\n\nfunction validateCode(code: string) {\n const msg = `Diagnostic code ${code} is invalid. Expected the format <ruleSetName>-<number>.`;\n const parts = code.split(\"-\");\n if (parts.length !== 2)\n throw new Error(msg);\n\n if (isNaN(Number(parts[1])))\n throw new Error(msg);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiagnosticReporter.js","sourceRoot":"","sources":["../../../src/Validation/DiagnosticReporter.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAKH,iCAAkC;AAElC,MAAM,oBAAoB,GAAG,kBAAkB,CAAC;AAChD,MAAM,uBAAuB,GAAG,aAAa,CAAC;AAC9C,MAAM,kBAAkB,GAAG,GAAG,oBAAoB,IAAI,uBAAuB,EAAE,CAAC;AAwBhF;;;;;GAKG;AACH,MAAsB,6BAA6B;IAGjD;;;OAGG;IACH,YAAY,YAAoC;QAC9C,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;IAED;;;OAGG;IACH,IAAW,YAAY;QACrB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,UAAyB;QACrC,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE;YAC5E,MAAM,eAAe,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC3E,IAAI,eAAgB,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC;gBAC5C,OAAO;SACV;QAED,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;CAQF;AAxCD,sEAwCC;AAED;;;;;GAKG;AACH,MAAsB,wBAAyB,SAAQ,6BAA6B;IAClF;;;;OAIG;IACH,YAAY,YAAoC,EAAE,YAA2B;QAC3E,KAAK,CAAC,YAAY,C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AAI;YACvC,OAAO,MAAM,CAAC,KAAK,EAAE,OAAO,CAAU,CAAC;QAEzC,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AApED,4DAoEC","sourcesContent":["/*---------------------------------------------------------------------------------------------\
|
|
1
|
+
{"version":3,"file":"DiagnosticReporter.js","sourceRoot":"","sources":["../../../src/Validation/DiagnosticReporter.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAKH,iCAAkC;AAElC,MAAM,oBAAoB,GAAG,kBAAkB,CAAC;AAChD,MAAM,uBAAuB,GAAG,aAAa,CAAC;AAC9C,MAAM,kBAAkB,GAAG,GAAG,oBAAoB,IAAI,uBAAuB,EAAE,CAAC;AAwBhF;;;;;GAKG;AACH,MAAsB,6BAA6B;IAGjD;;;OAGG;IACH,YAAY,YAAoC;QAC9C,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;IAED;;;OAGG;IACH,IAAW,YAAY;QACrB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,UAAyB;QACrC,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE;YAC5E,MAAM,eAAe,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC3E,IAAI,eAAgB,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC;gBAC5C,OAAO;SACV;QAED,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;CAQF;AAxCD,sEAwCC;AAED;;;;;GAKG;AACH,MAAsB,wBAAyB,SAAQ,6BAA6B;IAClF;;;;OAIG;IACH,YAAY,YAAoC,EAAE,YAA2B;QAC3E,KAAK,CAAC,YAAY,CAAC,CAAC;QACpB,IAAI,CAAC,YAAY,GAA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E,OAAO,CAAU,CAAC;QAEzC,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AApED,4DAoEC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Diagnostic\n */\n\nimport { Localization } from \"@itwin/core-common\";\nimport { AnyDiagnostic } from \"./Diagnostic\";\n\nimport assert = require(\"assert\");\n\nconst translationNamespace = \"ECSchemaMetaData\";\nconst subTranslationNamespace = \"Diagnostics\";\nconst baseTranslationKey = `${translationNamespace}:${subTranslationNamespace}`;\n\n/**\n * Interface used to report [[IDiagnostic]] objects created during schema validation.\n * @beta\n */\nexport interface IDiagnosticReporter {\n /**\n * A map where the key is a schema full name and the value is a collection\n * of diagnostics codes identifying which rules violations to ignore during validation.\n */\n suppressions?: Map<string, string[]>;\n\n /** The localization object to use for message translation. */\n localization?: Localization;\n\n /**\n * Handles the given [[IDiagnostic]] based on the implementation requirements for a\n * given reporter.\n * @param diagnostic The diagnostic to report.\n */\n report(diagnostic: AnyDiagnostic): void;\n}\n\n/**\n * An abstract base class for [[IDiagnosticReporter]] implementation that used the\n * provided Map to suppress certain rule violations from being reported. The Map's key\n * a schema full name, and the Map's value is a collection of rule codes to suppress.\n * @beta\n */\nexport abstract class SuppressionDiagnosticReporter implements IDiagnosticReporter {\n private _suppressions?: Map<string, string[]>;\n\n /**\n * Initializes a new SuppressionDiagnosticReporter\n * @param suppressions A Map where the key is a schema full name and the value is collection of diagnostic codes to suppress.\n */\n constructor(suppressions?: Map<string, string[]>) {\n this._suppressions = suppressions;\n }\n\n /**\n * Gets the collection of ISchemaDiagnosticSuppression objects that identify\n * rules violations to ignore during validation.\n */\n public get suppressions(): Map<string, string[]> | undefined {\n return this._suppressions;\n }\n\n /**\n * Prior to reporting the [[IDiagnostic]], the diagnostic message is formatted (with translations)\n * base on arguments contained in the diagnostic. Calls reportDiagnostic after the message is formatted.\n * @param diagnostic The diagnostic to report.\n */\n public report(diagnostic: AnyDiagnostic) {\n if (this._suppressions && this._suppressions.has(diagnostic.schema.fullName)) {\n const suppressedCodes = this._suppressions.get(diagnostic.schema.fullName);\n if (suppressedCodes!.includes(diagnostic.code))\n return;\n }\n\n this.reportInternal(diagnostic);\n }\n\n /**\n * Handles the given [[IDiagnostic]] based on the implementation requirements for a\n * given reporter.\n * @param diagnostic The diagnostic to report.\n */\n protected abstract reportInternal(diagnostic: AnyDiagnostic): void;\n}\n\n/**\n * An abstract [[SuppressionDiagnosticReporter]] implementation that formats the\n * diagnostic message with the message args. If a Localization implementation is specified,\n * the message will also be translated.\n * @beta\n */\nexport abstract class FormatDiagnosticReporter extends SuppressionDiagnosticReporter {\n /**\n * Initializes a new FormatDiagnosticReporter\n * @param suppressions A Map where the key is a schema full name and the value is collection of diagnostic codes to suppress.\n * @param localization The Localization instance to use to translate validation messages.\n */\n constructor(suppressions?: Map<string, string[]>, localization?: Localization) {\n super(suppressions);\n this.localization = localization;\n }\n\n /** The Localization object to use for message translation. If undefined, no translation will occur. */\n public localization?: Localization;\n\n /**\n * Prior to reporting the [[IDiagnostic]], the diagnostic message is formatted (with translations)\n * base on arguments contained in the diagnostic. Calls reportDiagnostic after the message is formatted.\n * @param diagnostic The diagnostic to report.\n */\n public reportInternal(diagnostic: AnyDiagnostic) {\n const message = this.formatMessage(diagnostic);\n this.reportDiagnostic(diagnostic, message);\n }\n\n /**\n * Handles the given [[IDiagnostic]] based on the implementation requirements for a\n * given reporter.\n * @param diagnostic The diagnostic to report.\n * @param messageText The formatted message.\n */\n protected abstract reportDiagnostic(diagnostic: AnyDiagnostic, messageText: string): void;\n\n /**\n * Helper method that formats string with provided arguments where the place holders\n * are in the the format '{0}', '{1}', etc.\n * @param text The text to format.\n * @param args The arguments to place in the text.\n * @param baseIndex The base index for the args, used for validation (typically 0, which is the default).\n */\n protected formatStringFromArgs(text: string, args: ArrayLike<string>, baseIndex = 0): string {\n return text.replace(/{(\\d+)}/g, (_match, index: string) => this.assertDefined(args[+index + baseIndex]));\n }\n\n private formatMessage(diagnostic: AnyDiagnostic): string {\n let translatedMessage = this.translateMessage(diagnostic);\n\n if (diagnostic.messageArgs && diagnostic.messageArgs.length > 0)\n translatedMessage = this.formatStringFromArgs(translatedMessage, diagnostic.messageArgs);\n return translatedMessage;\n }\n\n private translateMessage(diagnostic: AnyDiagnostic): string {\n if (!this.localization)\n return diagnostic.messageText;\n\n return this.localization.getLocalizedString(this.getTranslationKey(diagnostic));\n }\n\n private getTranslationKey(diagnostic: AnyDiagnostic): string {\n return `${baseTranslationKey}.${diagnostic.code}`;\n }\n\n private assertDefined<T>(value: T | null | undefined, message?: string): T {\n if (value === undefined || value === null)\n return assert(false, message) as never;\n\n return value;\n }\n}\n"]}
|