@itwin/ecschema-editing 4.10.0-dev.1 → 4.10.0-dev.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/lib/cjs/Differencing/SchemaDiagnosticVisitor.d.ts.map +1 -1
  2. package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js.map +1 -1
  3. package/lib/cjs/Differencing/SchemaDifference.d.ts +2 -2
  4. package/lib/cjs/Differencing/SchemaDifference.d.ts.map +1 -1
  5. package/lib/cjs/Differencing/SchemaDifference.js.map +1 -1
  6. package/lib/cjs/Differencing/SchemaDifferenceValidator.d.ts.map +1 -1
  7. package/lib/cjs/Differencing/SchemaDifferenceValidator.js.map +1 -1
  8. package/lib/cjs/Differencing/SchemaDifferenceVisitor.d.ts +7 -4
  9. package/lib/cjs/Differencing/SchemaDifferenceVisitor.d.ts.map +1 -1
  10. package/lib/cjs/Differencing/SchemaDifferenceVisitor.js +28 -25
  11. package/lib/cjs/Differencing/SchemaDifferenceVisitor.js.map +1 -1
  12. package/lib/cjs/Differencing/Utils.d.ts +2 -2
  13. package/lib/cjs/Differencing/Utils.d.ts.map +1 -1
  14. package/lib/cjs/Differencing/Utils.js.map +1 -1
  15. package/lib/cjs/Merging/ClassMerger.d.ts +2 -6
  16. package/lib/cjs/Merging/ClassMerger.d.ts.map +1 -1
  17. package/lib/cjs/Merging/ClassMerger.js +12 -82
  18. package/lib/cjs/Merging/ClassMerger.js.map +1 -1
  19. package/lib/cjs/Merging/ConstantMerger.d.ts +10 -4
  20. package/lib/cjs/Merging/ConstantMerger.d.ts.map +1 -1
  21. package/lib/cjs/Merging/ConstantMerger.js +58 -54
  22. package/lib/cjs/Merging/ConstantMerger.js.map +1 -1
  23. package/lib/cjs/Merging/CustomAttributeClassMerger.d.ts +14 -0
  24. package/lib/cjs/Merging/CustomAttributeClassMerger.d.ts.map +1 -0
  25. package/lib/cjs/Merging/CustomAttributeClassMerger.js +41 -0
  26. package/lib/cjs/Merging/CustomAttributeClassMerger.js.map +1 -0
  27. package/lib/cjs/Merging/CustomAttributeMerger.d.ts +2 -6
  28. package/lib/cjs/Merging/CustomAttributeMerger.d.ts.map +1 -1
  29. package/lib/cjs/Merging/CustomAttributeMerger.js +39 -48
  30. package/lib/cjs/Merging/CustomAttributeMerger.js.map +1 -1
  31. package/lib/cjs/Merging/Edits/RenameEditHandler.d.ts.map +1 -1
  32. package/lib/cjs/Merging/Edits/RenameEditHandler.js.map +1 -1
  33. package/lib/cjs/Merging/EntityClassMerger.d.ts +11 -6
  34. package/lib/cjs/Merging/EntityClassMerger.d.ts.map +1 -1
  35. package/lib/cjs/Merging/EntityClassMerger.js +32 -32
  36. package/lib/cjs/Merging/EntityClassMerger.js.map +1 -1
  37. package/lib/cjs/Merging/EnumerationMerger.d.ts +7 -6
  38. package/lib/cjs/Merging/EnumerationMerger.d.ts.map +1 -1
  39. package/lib/cjs/Merging/EnumerationMerger.js +39 -67
  40. package/lib/cjs/Merging/EnumerationMerger.js.map +1 -1
  41. package/lib/cjs/Merging/EnumeratorMerger.d.ts +14 -0
  42. package/lib/cjs/Merging/EnumeratorMerger.d.ts.map +1 -0
  43. package/lib/cjs/Merging/EnumeratorMerger.js +41 -0
  44. package/lib/cjs/Merging/EnumeratorMerger.js.map +1 -0
  45. package/lib/cjs/Merging/KindOfQuantityMerger.d.ts +10 -4
  46. package/lib/cjs/Merging/KindOfQuantityMerger.d.ts.map +1 -1
  47. package/lib/cjs/Merging/KindOfQuantityMerger.js +51 -46
  48. package/lib/cjs/Merging/KindOfQuantityMerger.js.map +1 -1
  49. package/lib/cjs/Merging/MixinMerger.d.ts +10 -4
  50. package/lib/cjs/Merging/MixinMerger.d.ts.map +1 -1
  51. package/lib/cjs/Merging/MixinMerger.js +30 -25
  52. package/lib/cjs/Merging/MixinMerger.js.map +1 -1
  53. package/lib/cjs/Merging/PhenomenonMerger.d.ts +10 -4
  54. package/lib/cjs/Merging/PhenomenonMerger.d.ts.map +1 -1
  55. package/lib/cjs/Merging/PhenomenonMerger.js +34 -29
  56. package/lib/cjs/Merging/PhenomenonMerger.js.map +1 -1
  57. package/lib/cjs/Merging/PropertyCategoryMerger.d.ts +10 -4
  58. package/lib/cjs/Merging/PropertyCategoryMerger.d.ts.map +1 -1
  59. package/lib/cjs/Merging/PropertyCategoryMerger.js +30 -27
  60. package/lib/cjs/Merging/PropertyCategoryMerger.js.map +1 -1
  61. package/lib/cjs/Merging/PropertyMerger.d.ts +2 -2
  62. package/lib/cjs/Merging/PropertyMerger.d.ts.map +1 -1
  63. package/lib/cjs/Merging/PropertyMerger.js +7 -7
  64. package/lib/cjs/Merging/PropertyMerger.js.map +1 -1
  65. package/lib/cjs/Merging/RelationshipClassMerger.d.ts +8 -4
  66. package/lib/cjs/Merging/RelationshipClassMerger.d.ts.map +1 -1
  67. package/lib/cjs/Merging/RelationshipClassMerger.js +40 -40
  68. package/lib/cjs/Merging/RelationshipClassMerger.js.map +1 -1
  69. package/lib/cjs/Merging/SchemaMerger.d.ts +1 -1
  70. package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
  71. package/lib/cjs/Merging/SchemaMerger.js +7 -42
  72. package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
  73. package/lib/cjs/Merging/SchemaMergingVisitor.d.ts +138 -0
  74. package/lib/cjs/Merging/SchemaMergingVisitor.d.ts.map +1 -0
  75. package/lib/cjs/Merging/SchemaMergingVisitor.js +309 -0
  76. package/lib/cjs/Merging/SchemaMergingVisitor.js.map +1 -0
  77. package/lib/cjs/Merging/SchemaMergingWalker.d.ts +19 -0
  78. package/lib/cjs/Merging/SchemaMergingWalker.d.ts.map +1 -0
  79. package/lib/cjs/Merging/SchemaMergingWalker.js +62 -0
  80. package/lib/cjs/Merging/SchemaMergingWalker.js.map +1 -0
  81. package/lib/cjs/Merging/SchemaReferenceMerger.d.ts +9 -6
  82. package/lib/cjs/Merging/SchemaReferenceMerger.d.ts.map +1 -1
  83. package/lib/cjs/Merging/SchemaReferenceMerger.js +28 -37
  84. package/lib/cjs/Merging/SchemaReferenceMerger.js.map +1 -1
  85. package/lib/cjs/Merging/StructClassMerger.d.ts +14 -0
  86. package/lib/cjs/Merging/StructClassMerger.d.ts.map +1 -0
  87. package/lib/cjs/Merging/StructClassMerger.js +25 -0
  88. package/lib/cjs/Merging/StructClassMerger.js.map +1 -0
  89. package/lib/cjs/Merging/UnitSystemMerger.d.ts +10 -4
  90. package/lib/cjs/Merging/UnitSystemMerger.d.ts.map +1 -1
  91. package/lib/cjs/Merging/UnitSystemMerger.js +23 -19
  92. package/lib/cjs/Merging/UnitSystemMerger.js.map +1 -1
  93. package/lib/cjs/Merging/Utils.d.ts +18 -0
  94. package/lib/cjs/Merging/Utils.d.ts.map +1 -0
  95. package/lib/cjs/Merging/Utils.js +56 -0
  96. package/lib/cjs/Merging/Utils.js.map +1 -0
  97. package/package.json +9 -9
  98. package/lib/cjs/Merging/CAClassMerger.d.ts +0 -8
  99. package/lib/cjs/Merging/CAClassMerger.d.ts.map +0 -1
  100. package/lib/cjs/Merging/CAClassMerger.js +0 -36
  101. package/lib/cjs/Merging/CAClassMerger.js.map +0 -1
  102. package/lib/cjs/Merging/SchemaItemMerger.d.ts +0 -35
  103. package/lib/cjs/Merging/SchemaItemMerger.d.ts.map +0 -1
  104. package/lib/cjs/Merging/SchemaItemMerger.js +0 -121
  105. package/lib/cjs/Merging/SchemaItemMerger.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAiF;AACjF,8CAAwD;AACxD,mDAA8D;AAC9D,uEAAsJ;AAEtJ,mEAA+D;AAC/D,yDAAsD;AACtD,mEAAgE;AAChE,+CAA+C;AAa/C;;;;GAIG;AACH,MAAa,YAAY;IAIvB;;;OAGG;IACH,YAAY,cAA6B;QACvC,IAAI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,eAAe,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IACvF,CAAC;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, type SchemaContext, SchemaKey } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaContextEditor } from \"../Editing/Editor\";\r\nimport { SchemaConflictsError } from \"../Differencing/Errors\";\r\nimport { type AnySchemaDifference, getSchemaDifferences, type SchemaDifference, type SchemaDifferenceResult } from \"../Differencing/SchemaDifference\";\r\nimport { type SchemaEdits } from \"./Edits/SchemaEdits\";\r\nimport { mergeCustomAttribute } from \"./CustomAttributeMerger\";\r\nimport { mergeSchemaItems } from \"./SchemaItemMerger\";\r\nimport { mergeSchemaReferences } from \"./SchemaReferenceMerger\";\r\nimport * as Utils from \"../Differencing/Utils\";\r\n\r\n/**\r\n * Defines the context of a Schema merging run.\r\n * @internal\r\n */\r\nexport interface SchemaMergeContext {\r\n readonly targetSchema: Schema;\r\n readonly targetSchemaKey: SchemaKey;\r\n readonly sourceSchemaKey: SchemaKey;\r\n readonly editor: SchemaContextEditor;\r\n}\r\n\r\n/**\r\n * Class to merge two schemas together.\r\n * @see [[merge]] or [[mergeSchemas]] to merge two schemas together.\r\n * @beta\r\n */\r\nexport class SchemaMerger {\r\n\r\n private readonly _editor: SchemaContextEditor;\r\n\r\n /**\r\n * Constructs a new instance of the SchemaMerger object.\r\n * @param editingContext The schema contexts that holds the schema to be edited.\r\n */\r\n constructor(editingContext: SchemaContext) {\r\n this._editor = new SchemaContextEditor(editingContext);\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 * @param edits An optional instance of schema edits that shall be applied before the schemas get merged.\r\n * @returns The merged target schema.\r\n * @alpha\r\n */\r\n public async mergeSchemas(targetSchema: Schema, sourceSchema: Schema, edits?: SchemaEdits): Promise<Schema> {\r\n return this.merge(await getSchemaDifferences(targetSchema, sourceSchema), edits);\r\n }\r\n\r\n /**\r\n * Merges the schema differences into the target schema context.\r\n * @param differenceResult The differences that shall be applied to the target schema.\r\n * @param edits An optional instance of schema edits that shall be applied before the schemas get merged.\r\n * @alpha\r\n */\r\n public async merge(differenceResult: SchemaDifferenceResult, edits?: SchemaEdits): Promise<Schema> {\r\n const targetSchemaKey = SchemaKey.parseString(differenceResult.targetSchemaName);\r\n const sourceSchemaKey = SchemaKey.parseString(differenceResult.sourceSchemaName);\r\n\r\n // If schema changes were provided, they'll get applied and a new SchemaDifferenceResult is returned\r\n // to prevent altering the differenceResult the caller passed in.\r\n if (edits) {\r\n await edits.applyTo(differenceResult = { ...differenceResult });\r\n }\r\n\r\n if (differenceResult.conflicts && differenceResult.conflicts.length > 0) {\r\n throw new SchemaConflictsError(\r\n \"Schema's can't be merged if there are unresolved conflicts.\",\r\n differenceResult.conflicts,\r\n sourceSchemaKey,\r\n targetSchemaKey,\r\n );\r\n }\r\n\r\n const schema = await this._editor.getSchema(targetSchemaKey);\r\n if (schema === undefined) {\r\n throw new Error(`The target schema '${targetSchemaKey.name}' could not be found in the editing context.`);\r\n }\r\n\r\n const context: SchemaMergeContext = {\r\n editor: this._editor,\r\n targetSchema: schema,\r\n targetSchemaKey,\r\n sourceSchemaKey,\r\n };\r\n\r\n await mergeSchemaDifferences(context, differenceResult.differences);\r\n\r\n return schema;\r\n }\r\n}\r\n\r\n/**\r\n * Merges the schema differences in the target schema.\r\n * @param context The current merging context.\r\n * @param differences The differences between a source schema and the target schema.\r\n * @internal\r\n */\r\nasync function mergeSchemaDifferences(context: SchemaMergeContext, differences: AnySchemaDifference[]): Promise<void> {\r\n for (const referenceDifference of differences.filter(Utils.isSchemaReferenceDifference)) {\r\n await mergeSchemaReferences(context, referenceDifference);\r\n }\r\n\r\n for (const schemaDifference of differences.filter(Utils.isSchemaDifference)) {\r\n await mergeSchemaProperties(context, schemaDifference);\r\n }\r\n\r\n // Filter a list of possible schema item changes. This list gets filtered and order in the\r\n // mergeSchemaItems method.\r\n for await (const _mergeResult of mergeSchemaItems(context, differences)) {\r\n }\r\n\r\n // At last the custom attributes gets merged because it could be that the CustomAttributes\r\n // depend on classes that has to get merged in as items before.\r\n for (const customAttributeDifference of differences.filter(Utils.isCustomAttributeDifference)) {\r\n await mergeCustomAttribute(context, customAttributeDifference);\r\n }\r\n}\r\n\r\n/**\r\n * Sets the editable properties of a Schema.\r\n * @internal\r\n */\r\nasync function mergeSchemaProperties(context: SchemaMergeContext, { difference }: SchemaDifference) {\r\n if (difference.label !== undefined) {\r\n await context.editor.setDisplayLabel(context.targetSchemaKey, difference.label);\r\n }\r\n if (difference.description !== undefined) {\r\n await context.editor.setDescription(context.targetSchemaKey, difference.description);\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,gEAAiF;AACjF,8CAAwD;AACxD,mDAA8D;AAC9D,uEAAqG;AACrG,iEAA8D;AAC9D,+DAA4D;AAc5D;;;;GAIG;AACH,MAAa,YAAY;IAIvB;;;OAGG;IACH,YAAY,cAA6B;QACvC,IAAI,CAAC,OAAO,GAAG,IAAI,4BAAmB,CAAC,cAAc,CAAC,CAAC;IACzD,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,YAAY,CAAC,YAAoB,EAAE,YAAoB,EAAE,KAAmB;QACvF,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,IAAA,uCAAoB,EAAC,YAAY,EAAE,YAAY,CAAC,EAAE,KAAK,CAAC,CAAC;IACnF,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,KAAK,CAAC,gBAAw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------------\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, type SchemaContext, SchemaKey } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaContextEditor } from \"../Editing/Editor\";\r\nimport { SchemaConflictsError } from \"../Differencing/Errors\";\r\nimport { getSchemaDifferences, type SchemaDifferenceResult } from \"../Differencing/SchemaDifference\";\r\nimport { SchemaMergingVisitor } from \"./SchemaMergingVisitor\";\r\nimport { SchemaMergingWalker } from \"./SchemaMergingWalker\";\r\nimport type { SchemaEdits } from \"./Edits/SchemaEdits\";\r\n\r\n/**\r\n * Defines the context of a Schema merging run.\r\n * @internal\r\n */\r\nexport interface SchemaMergeContext {\r\n readonly targetSchema: Schema;\r\n readonly targetSchemaKey: SchemaKey;\r\n readonly sourceSchemaKey: SchemaKey;\r\n readonly editor: SchemaContextEditor;\r\n}\r\n\r\n/**\r\n * Class to merge two schemas together.\r\n * @see [[merge]] or [[mergeSchemas]] to merge two schemas together.\r\n * @beta\r\n */\r\nexport class SchemaMerger {\r\n\r\n private readonly _editor: SchemaContextEditor;\r\n\r\n /**\r\n * Constructs a new instance of the SchemaMerger object.\r\n * @param editingContext The schema contexts that holds the schema to be edited.\r\n */\r\n constructor(editingContext: SchemaContext) {\r\n this._editor = new SchemaContextEditor(editingContext);\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 * @param edits An optional instance of schema edits that shall be applied before the schemas get merged.\r\n * @returns The merged target schema.\r\n * @alpha\r\n */\r\n public async mergeSchemas(targetSchema: Schema, sourceSchema: Schema, edits?: SchemaEdits): Promise<Schema> {\r\n return this.merge(await getSchemaDifferences(targetSchema, sourceSchema), edits);\r\n }\r\n\r\n /**\r\n * Merges the schema differences into the target schema context.\r\n * @param differenceResult The differences that shall be applied to the target schema.\r\n * @param edits An optional instance of schema edits that shall be applied before the schemas get merged.\r\n * @alpha\r\n */\r\n public async merge(differenceResult: SchemaDifferenceResult, edits?: SchemaEdits): Promise<Schema> {\r\n const targetSchemaKey = SchemaKey.parseString(differenceResult.targetSchemaName);\r\n const sourceSchemaKey = SchemaKey.parseString(differenceResult.sourceSchemaName);\r\n\r\n // If schema changes were provided, they'll get applied and a new SchemaDifferenceResult is returned\r\n // to prevent altering the differenceResult the caller passed in.\r\n if (edits) {\r\n await edits.applyTo(differenceResult = { ...differenceResult });\r\n }\r\n\r\n if (differenceResult.conflicts && differenceResult.conflicts.length > 0) {\r\n throw new SchemaConflictsError(\r\n \"Schema's can't be merged if there are unresolved conflicts.\",\r\n differenceResult.conflicts,\r\n sourceSchemaKey,\r\n targetSchemaKey,\r\n );\r\n }\r\n\r\n const schema = await this._editor.getSchema(targetSchemaKey);\r\n if (schema === undefined) {\r\n throw new Error(`The target schema '${targetSchemaKey.name}' could not be found in the editing context.`);\r\n }\r\n\r\n const visitor = new SchemaMergingVisitor({\r\n editor: this._editor,\r\n targetSchema: schema,\r\n targetSchemaKey,\r\n sourceSchemaKey,\r\n });\r\n\r\n const walker = new SchemaMergingWalker(visitor);\r\n await walker.traverse(differenceResult.differences, \"add\");\r\n await walker.traverse(differenceResult.differences, \"modify\");\r\n\r\n return schema;\r\n }\r\n}\r\n"]}
@@ -0,0 +1,138 @@
1
+ import { AnySchemaDifference, ClassPropertyDifference, ConstantDifference, CustomAttributeClassDifference, CustomAttributeDifference, EntityClassDifference, EntityClassMixinDifference, EnumerationDifference, EnumeratorDifference, FormatDifference, InvertedUnitDifference, KindOfQuantityDifference, MixinClassDifference, PhenomenonDifference, PropertyCategoryDifference, RelationshipClassDifference, RelationshipConstraintClassDifference, RelationshipConstraintDifference, SchemaDifference, SchemaReferenceDifference, StructClassDifference, UnitDifference, UnitSystemDifference } from "../Differencing/SchemaDifference";
2
+ import { SchemaDifferenceVisitor } from "../Differencing/SchemaDifferenceVisitor";
3
+ import { SchemaMergeContext } from "./SchemaMerger";
4
+ /**
5
+ * Implementation of ISchemaDifferenceVisitor that can be used to traverse schema
6
+ * differences to call the appropriated merger methods.
7
+ * @internal
8
+ */
9
+ export declare class SchemaMergingVisitor implements SchemaDifferenceVisitor {
10
+ private readonly _context;
11
+ /**
12
+ * Initializes a new instance of SchemaMergingVisitor class.
13
+ */
14
+ constructor(context: SchemaMergeContext);
15
+ /**
16
+ * Gets a SchemaItemKey for the given item name.
17
+ */
18
+ private toItemKey;
19
+ /**
20
+ * Shared merging logic for all types of ClassItemDifference union.
21
+ */
22
+ private visitClassDifference;
23
+ /**
24
+ * Visitor implementation for handling ConstantDifference.
25
+ * @internal
26
+ */
27
+ visitConstantDifference(entry: ConstantDifference): Promise<void>;
28
+ /**
29
+ * Visitor implementation for handling CustomAttributeClassDifference.
30
+ * @internal
31
+ */
32
+ visitCustomAttributeClassDifference(entry: CustomAttributeClassDifference, index: number, array: AnySchemaDifference[]): Promise<void>;
33
+ /**
34
+ * Visitor implementation for handling CustomAttributeDifference.
35
+ * @internal
36
+ */
37
+ visitCustomAttributeInstanceDifference(entry: CustomAttributeDifference): Promise<void>;
38
+ /**
39
+ * Visitor implementation for handling EntityClassDifference.
40
+ * @internal
41
+ */
42
+ visitEntityClassDifference(entry: EntityClassDifference, index: number, array: AnySchemaDifference[]): Promise<void>;
43
+ /**
44
+ * Visitor implementation for handling EntityClassMixinDifference.
45
+ * @internal
46
+ */
47
+ visitEntityClassMixinDifference(entry: EntityClassMixinDifference): Promise<void>;
48
+ /**
49
+ * Visitor implementation for handling EnumerationDifference.
50
+ * @internal
51
+ */
52
+ visitEnumerationDifference(entry: EnumerationDifference): Promise<void>;
53
+ /**
54
+ * Visitor implementation for handling EnumeratorDifference.
55
+ * @internal
56
+ */
57
+ visitEnumeratorDifference(entry: EnumeratorDifference): Promise<void>;
58
+ /**
59
+ * Visitor implementation for handling FormatDifference.
60
+ * @internal
61
+ */
62
+ visitFormatDifference(_entry: FormatDifference): Promise<void>;
63
+ /**
64
+ * Visitor implementation for handling InvertedUnitDifference.
65
+ * @internal
66
+ */
67
+ visitInvertedUnitDifference(_entry: InvertedUnitDifference): Promise<void>;
68
+ /**
69
+ * Visitor implementation for handling KindOfQuantityDifference.
70
+ * @internal
71
+ */
72
+ visitKindOfQuantityDifference(entry: KindOfQuantityDifference): Promise<void>;
73
+ /**
74
+ * Visitor implementation for handling MixinClassDifference.
75
+ * @internal
76
+ */
77
+ visitMixinDifference(entry: MixinClassDifference, index: number, array: AnySchemaDifference[]): Promise<void>;
78
+ /**
79
+ * Visitor implementation for handling PhenomenonDifference.
80
+ * @internal
81
+ */
82
+ visitPhenomenonDifference(entry: PhenomenonDifference): Promise<void>;
83
+ /**
84
+ * Visitor implementation for handling PropertyCategoryDifference.
85
+ * @internal
86
+ */
87
+ visitPropertyCategoryDifference(entry: PropertyCategoryDifference): Promise<void>;
88
+ /**
89
+ * Visitor implementation for handling ClassPropertyDifference.
90
+ * @internal
91
+ */
92
+ visitPropertyDifference(entry: ClassPropertyDifference): Promise<void>;
93
+ /**
94
+ * Visitor implementation for handling RelationshipClassDifference.
95
+ * @internal
96
+ */
97
+ visitRelationshipClassDifference(entry: RelationshipClassDifference, index: number, array: AnySchemaDifference[]): Promise<void>;
98
+ /**
99
+ * Visitor implementation for handling RelationshipConstraintClassDifference.
100
+ * @internal
101
+ */
102
+ visitRelationshipConstraintClassDifference(entry: RelationshipConstraintClassDifference): Promise<void>;
103
+ /**
104
+ * Visitor implementation for handling RelationshipConstraintDifference.
105
+ * @internal
106
+ */
107
+ visitRelationshipConstraintDifference(entry: RelationshipConstraintDifference): Promise<void>;
108
+ /**
109
+ * Visitor implementation for handling SchemaDifference.
110
+ * @internal
111
+ */
112
+ visitSchemaDifference({ difference }: SchemaDifference): Promise<void>;
113
+ /**
114
+ * Shared merging logic for all types of AnySchemaItemDifference union.
115
+ */
116
+ private visitSchemaItemDifference;
117
+ /**
118
+ * Visitor implementation for handling SchemaReferenceDifference.
119
+ * @internal
120
+ */
121
+ visitSchemaReferenceDifference(entry: SchemaReferenceDifference): Promise<void>;
122
+ /**
123
+ * Visitor implementation for handling StructClassDifference.
124
+ * @internal
125
+ */
126
+ visitStructClassDifference(entry: StructClassDifference, index: number, array: AnySchemaDifference[]): Promise<void>;
127
+ /**
128
+ * Visitor implementation for handling UnitDifference.
129
+ * @internal
130
+ */
131
+ visitUnitDifference(_entry: UnitDifference): Promise<void>;
132
+ /**
133
+ * Visitor implementation for handling UnitSystemDifference.
134
+ * @internal
135
+ */
136
+ visitUnitSystemDifference(entry: UnitSystemDifference): Promise<void>;
137
+ }
138
+ //# sourceMappingURL=SchemaMergingVisitor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaMergingVisitor.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaMergingVisitor.ts"],"names":[],"mappings":"AAIA,OAAO,EAA0B,mBAAmB,EAA2B,uBAAuB,EAAE,kBAAkB,EAAE,8BAA8B,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,2BAA2B,EAAE,qCAAqC,EAAE,gCAAgC,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAiB5pB,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAElF,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAQpD;;;;GAIG;AACH,qBAAa,oBAAqB,YAAW,uBAAuB;IAElE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAE9C;;OAEG;gBACS,OAAO,EAAE,kBAAkB;IAIvC;;OAEG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AC,IAAI,CAAC;IAOlF;;;OAGG;IACU,+BAA+B,CAAC,KAAK,EAAE,0BAA0B,GAAG,OAAO,CAAC,IAAI,CAAC;IAO9F;;;OAGG;IACU,uBAAuB,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;IAInF;;;OAGG;IACU,gCAAgC,CAAC,KAAK,EAAE,2BAA2B,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAO7I;;;OAGG;IACU,0CAA0C,CAAC,KAAK,EAAE,qCAAqC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpH;;;OAGG;IACU,qCAAqC,CAAC,KAAK,EAAE,gCAAgC,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1G;;;OAGG;IACU,qBAAqB,CAAC,EAAE,UAAU,EAAE,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IASnF;;OAEG;YACW,yBAAyB;IAevC;;;OAGG;IACU,8BAA8B,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;IAO5F;;;OAGG;IACU,0BAA0B,CAAC,KAAK,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjI;;;OAGG;IACU,mBAAmB,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvE;;;OAGG;IACU,yBAAyB,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;CAMnF"}
@@ -0,0 +1,309 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchemaMergingVisitor = void 0;
4
+ const ConstantMerger_1 = require("./ConstantMerger");
5
+ const CustomAttributeMerger_1 = require("./CustomAttributeMerger");
6
+ const CustomAttributeClassMerger_1 = require("./CustomAttributeClassMerger");
7
+ const EntityClassMerger_1 = require("./EntityClassMerger");
8
+ const EnumerationMerger_1 = require("./EnumerationMerger");
9
+ const EnumeratorMerger_1 = require("./EnumeratorMerger");
10
+ const KindOfQuantityMerger_1 = require("./KindOfQuantityMerger");
11
+ const MixinMerger_1 = require("./MixinMerger");
12
+ const PhenomenonMerger_1 = require("./PhenomenonMerger");
13
+ const PropertyCategoryMerger_1 = require("./PropertyCategoryMerger");
14
+ const RelationshipClassMerger_1 = require("./RelationshipClassMerger");
15
+ const SchemaReferenceMerger_1 = require("./SchemaReferenceMerger");
16
+ const StructClassMerger_1 = require("./StructClassMerger");
17
+ const UnitSystemMerger_1 = require("./UnitSystemMerger");
18
+ const PropertyMerger_1 = require("./PropertyMerger");
19
+ const Utils_1 = require("../Differencing/Utils");
20
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
21
+ /**
22
+ * Implementation of ISchemaDifferenceVisitor that can be used to traverse schema
23
+ * differences to call the appropriated merger methods.
24
+ * @internal
25
+ */
26
+ class SchemaMergingVisitor {
27
+ /**
28
+ * Initializes a new instance of SchemaMergingVisitor class.
29
+ */
30
+ constructor(context) {
31
+ this._context = context;
32
+ }
33
+ /**
34
+ * Gets a SchemaItemKey for the given item name.
35
+ */
36
+ toItemKey(itemName) {
37
+ return new ecschema_metadata_1.SchemaItemKey(itemName, this._context.targetSchemaKey);
38
+ }
39
+ /**
40
+ * Shared merging logic for all types of ClassItemDifference union.
41
+ */
42
+ async visitClassDifference(entry, index, array, handler) {
43
+ return this.visitSchemaItemDifference(entry, {
44
+ add: async (context) => {
45
+ // To add classes a slightly different approach is done. In fact the class entries gets processed
46
+ // two times. The first time, a stub with the bare minimum is added to the schema. The second time,
47
+ // the class gets completed with all properties, mixins, etc...
48
+ if (entry.changeType === "add" && !await context.targetSchema.getItem(entry.itemName)) {
49
+ await handler.add(this._context, {
50
+ ...entry,
51
+ difference: {
52
+ ...entry.difference,
53
+ // Remove everything we want to validate before setting, this is done in the second iteration.
54
+ baseClass: undefined,
55
+ mixins: undefined,
56
+ properties: undefined,
57
+ customAttributes: undefined,
58
+ },
59
+ });
60
+ // Searches for the last class difference and adds the entry after it. That way,
61
+ // the class is completed before class related entries get processed.
62
+ const insertIndex = findIndexOf(array, (e) => !(0, Utils_1.isClassDifference)(e), index) || array.length;
63
+ array.splice(insertIndex, 0, entry);
64
+ return;
65
+ }
66
+ // Now both a modification change or the second add iteration is a modification of an existing class.
67
+ // So, regardless of the actual change type, modify is called.
68
+ return handler.modify(this._context, entry, this.toItemKey(entry.itemName));
69
+ },
70
+ modify: handler.modify,
71
+ });
72
+ }
73
+ /**
74
+ * Visitor implementation for handling ConstantDifference.
75
+ * @internal
76
+ */
77
+ async visitConstantDifference(entry) {
78
+ return this.visitSchemaItemDifference(entry, {
79
+ add: ConstantMerger_1.addConstant,
80
+ modify: ConstantMerger_1.modifyConstant,
81
+ });
82
+ }
83
+ /**
84
+ * Visitor implementation for handling CustomAttributeClassDifference.
85
+ * @internal
86
+ */
87
+ async visitCustomAttributeClassDifference(entry, index, array) {
88
+ return this.visitClassDifference(entry, index, array, {
89
+ add: CustomAttributeClassMerger_1.addCustomAttributeClass,
90
+ modify: CustomAttributeClassMerger_1.modifyCustomAttributeClass,
91
+ });
92
+ }
93
+ /**
94
+ * Visitor implementation for handling CustomAttributeDifference.
95
+ * @internal
96
+ */
97
+ async visitCustomAttributeInstanceDifference(entry) {
98
+ switch (entry.changeType) {
99
+ case "add": return (0, CustomAttributeMerger_1.addCustomAttribute)(this._context, entry);
100
+ }
101
+ }
102
+ /**
103
+ * Visitor implementation for handling EntityClassDifference.
104
+ * @internal
105
+ */
106
+ async visitEntityClassDifference(entry, index, array) {
107
+ return this.visitClassDifference(entry, index, array, {
108
+ add: EntityClassMerger_1.addEntityClass,
109
+ modify: EntityClassMerger_1.modifyEntityClass,
110
+ });
111
+ }
112
+ /**
113
+ * Visitor implementation for handling EntityClassMixinDifference.
114
+ * @internal
115
+ */
116
+ async visitEntityClassMixinDifference(entry) {
117
+ switch (entry.changeType) {
118
+ case "add": return (0, EntityClassMerger_1.addClassMixins)(this._context, entry);
119
+ }
120
+ }
121
+ /**
122
+ * Visitor implementation for handling EnumerationDifference.
123
+ * @internal
124
+ */
125
+ async visitEnumerationDifference(entry) {
126
+ return this.visitSchemaItemDifference(entry, {
127
+ add: EnumerationMerger_1.addEnumeration,
128
+ modify: EnumerationMerger_1.modifyEnumeration,
129
+ });
130
+ }
131
+ /**
132
+ * Visitor implementation for handling EnumeratorDifference.
133
+ * @internal
134
+ */
135
+ async visitEnumeratorDifference(entry) {
136
+ switch (entry.changeType) {
137
+ case "add": return (0, EnumeratorMerger_1.addEnumerator)(this._context, entry);
138
+ case "modify": return (0, EnumeratorMerger_1.modifyEnumerator)(this._context, entry, this.toItemKey(entry.itemName));
139
+ }
140
+ }
141
+ /**
142
+ * Visitor implementation for handling FormatDifference.
143
+ * @internal
144
+ */
145
+ async visitFormatDifference(_entry) {
146
+ // TODO: Add merger handler...
147
+ }
148
+ /**
149
+ * Visitor implementation for handling InvertedUnitDifference.
150
+ * @internal
151
+ */
152
+ async visitInvertedUnitDifference(_entry) {
153
+ // TODO: Add merger handler...
154
+ }
155
+ /**
156
+ * Visitor implementation for handling KindOfQuantityDifference.
157
+ * @internal
158
+ */
159
+ async visitKindOfQuantityDifference(entry) {
160
+ return this.visitSchemaItemDifference(entry, {
161
+ add: KindOfQuantityMerger_1.addKindOfQuantity,
162
+ modify: KindOfQuantityMerger_1.modifyKindOfQuantity,
163
+ });
164
+ }
165
+ /**
166
+ * Visitor implementation for handling MixinClassDifference.
167
+ * @internal
168
+ */
169
+ async visitMixinDifference(entry, index, array) {
170
+ return this.visitClassDifference(entry, index, array, {
171
+ add: MixinMerger_1.addMixinClass,
172
+ modify: MixinMerger_1.modifyMixinClass,
173
+ });
174
+ }
175
+ /**
176
+ * Visitor implementation for handling PhenomenonDifference.
177
+ * @internal
178
+ */
179
+ async visitPhenomenonDifference(entry) {
180
+ return this.visitSchemaItemDifference(entry, {
181
+ add: PhenomenonMerger_1.addPhenomenon,
182
+ modify: PhenomenonMerger_1.modifyPhenomenon,
183
+ });
184
+ }
185
+ /**
186
+ * Visitor implementation for handling PropertyCategoryDifference.
187
+ * @internal
188
+ */
189
+ async visitPropertyCategoryDifference(entry) {
190
+ return this.visitSchemaItemDifference(entry, {
191
+ add: PropertyCategoryMerger_1.addPropertyCategory,
192
+ modify: PropertyCategoryMerger_1.modifyPropertyCategory,
193
+ });
194
+ }
195
+ /**
196
+ * Visitor implementation for handling ClassPropertyDifference.
197
+ * @internal
198
+ */
199
+ async visitPropertyDifference(entry) {
200
+ await (0, PropertyMerger_1.mergePropertyDifference)(this._context, entry);
201
+ }
202
+ /**
203
+ * Visitor implementation for handling RelationshipClassDifference.
204
+ * @internal
205
+ */
206
+ async visitRelationshipClassDifference(entry, index, array) {
207
+ return this.visitClassDifference(entry, index, array, {
208
+ add: RelationshipClassMerger_1.addRelationshipClass,
209
+ modify: RelationshipClassMerger_1.modifyRelationshipClass,
210
+ });
211
+ }
212
+ /**
213
+ * Visitor implementation for handling RelationshipConstraintClassDifference.
214
+ * @internal
215
+ */
216
+ async visitRelationshipConstraintClassDifference(entry) {
217
+ await (0, RelationshipClassMerger_1.mergeRelationshipClassConstraint)(this._context, entry);
218
+ }
219
+ /**
220
+ * Visitor implementation for handling RelationshipConstraintDifference.
221
+ * @internal
222
+ */
223
+ async visitRelationshipConstraintDifference(entry) {
224
+ await (0, RelationshipClassMerger_1.mergeRelationshipConstraint)(this._context, entry);
225
+ }
226
+ /**
227
+ * Visitor implementation for handling SchemaDifference.
228
+ * @internal
229
+ */
230
+ async visitSchemaDifference({ difference }) {
231
+ if (difference.label !== undefined) {
232
+ await this._context.editor.setDisplayLabel(this._context.targetSchemaKey, difference.label);
233
+ }
234
+ if (difference.description !== undefined) {
235
+ await this._context.editor.setDescription(this._context.targetSchemaKey, difference.description);
236
+ }
237
+ }
238
+ /**
239
+ * Shared merging logic for all types of AnySchemaItemDifference union.
240
+ */
241
+ async visitSchemaItemDifference(entry, handler) {
242
+ switch (entry.changeType) {
243
+ case "add": {
244
+ return handler.add(this._context, entry);
245
+ }
246
+ case "modify":
247
+ {
248
+ if ("schemaItemType" in entry.difference && entry.difference.schemaItemType !== entry.schemaType) {
249
+ throw new Error(`Changing the type of item '${entry.itemName}' not supported.`);
250
+ }
251
+ return handler.modify(this._context, entry, this.toItemKey(entry.itemName));
252
+ }
253
+ ;
254
+ }
255
+ }
256
+ /**
257
+ * Visitor implementation for handling SchemaReferenceDifference.
258
+ * @internal
259
+ */
260
+ async visitSchemaReferenceDifference(entry) {
261
+ switch (entry.changeType) {
262
+ case "add": return (0, SchemaReferenceMerger_1.addSchemaReferences)(this._context, entry);
263
+ case "modify": return (0, SchemaReferenceMerger_1.modifySchemaReferences)(this._context, entry);
264
+ }
265
+ }
266
+ /**
267
+ * Visitor implementation for handling StructClassDifference.
268
+ * @internal
269
+ */
270
+ async visitStructClassDifference(entry, index, array) {
271
+ return this.visitClassDifference(entry, index, array, {
272
+ add: StructClassMerger_1.addStructClass,
273
+ modify: StructClassMerger_1.modifyStructClass,
274
+ });
275
+ }
276
+ /**
277
+ * Visitor implementation for handling UnitDifference.
278
+ * @internal
279
+ */
280
+ async visitUnitDifference(_entry) {
281
+ // TODO: Add merger handler...
282
+ }
283
+ /**
284
+ * Visitor implementation for handling UnitSystemDifference.
285
+ * @internal
286
+ */
287
+ async visitUnitSystemDifference(entry) {
288
+ return this.visitSchemaItemDifference(entry, {
289
+ add: UnitSystemMerger_1.addUnitSystem,
290
+ modify: UnitSystemMerger_1.modifyUnitSystem,
291
+ });
292
+ }
293
+ }
294
+ exports.SchemaMergingVisitor = SchemaMergingVisitor;
295
+ /**
296
+ * Helper method to get the index of the first element in the array that satisfies the provided testing function.
297
+ * @param array Array to search.
298
+ * @param predicate Function to execute on each value in the array.
299
+ * @param fromIndex The index to start the search at.
300
+ * @returns An index in the array if an element passes the test; otherwise, false.
301
+ */
302
+ function findIndexOf(array, predicate, fromIndex) {
303
+ for (let i = fromIndex; i < array.length; i++) {
304
+ if (predicate(array[i]))
305
+ return i;
306
+ }
307
+ return false;
308
+ }
309
+ //# sourceMappingURL=SchemaMergingVisitor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaMergingVisitor.js","sourceRoot":"","sources":["../../../src/Merging/SchemaMergingVisitor.ts"],"names":[],"mappings":";;;AAKA,qDAA+D;AAC/D,mEAA6D;AAC7D,6EAAmG;AACnG,2DAAwF;AACxF,2DAAwE;AACxE,yDAAqE;AACrE,iEAAiF;AACjF,+CAAgE;AAChE,yDAAqE;AACrE,qEAAuF;AACvF,uEAAyJ;AACzJ,mEAAsF;AACtF,2DAAwE;AACxE,yDAAqE;AACrE,qDAA2D;AAC3D,iDAA0D;AAE1D,gEAAyD;AASzD;;;;GAIG;AACH,MAAa,oBAAoB;IAI/B;;OAEG;IACH,YAAY,OAA2B;QACrC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED;;OAEG;IACK,SAAS,CAAC,QAAgB;QAChC,OAAO,IAAI,iCAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;IACpE,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,oBAAoB,CAAmC,KAAQ,EAAE,KAAa,EAAE,KAA4B,EAAE,OAAiC;QAC3J,OAAO,IAAI,CAAC,yBAAyB,CAAC,KAAK,EAAE;YAC3C,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;gBACrB,iGAAiG;gBACjG,mGAAmG;gBACnG,+DAA+D;gBAC/D,IAAG,KAAK,CAAC,UAAU,KAAK,KAAK,IAAI,CAAC,MAAM,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;oBACrF,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE;wBAC/B,GAAG,KAAK;wBAC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AAC,CAAC,CAAC;YACrB,OAAO,CAAC,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { AnyClassItemDifference, AnySchemaDifference, AnySchemaItemDifference, ClassPropertyDifference, ConstantDifference, CustomAttributeClassDifference, CustomAttributeDifference, EntityClassDifference, EntityClassMixinDifference, EnumerationDifference, EnumeratorDifference, FormatDifference, InvertedUnitDifference, KindOfQuantityDifference, MixinClassDifference, PhenomenonDifference, PropertyCategoryDifference, RelationshipClassDifference, RelationshipConstraintClassDifference, RelationshipConstraintDifference, SchemaDifference, SchemaReferenceDifference, StructClassDifference, UnitDifference, UnitSystemDifference } from \"../Differencing/SchemaDifference\";\r\nimport { addConstant, modifyConstant } from \"./ConstantMerger\";\r\nimport { addCustomAttribute } from \"./CustomAttributeMerger\";\r\nimport { addCustomAttributeClass, modifyCustomAttributeClass } from \"./CustomAttributeClassMerger\";\r\nimport { addClassMixins, addEntityClass, modifyEntityClass } from \"./EntityClassMerger\";\r\nimport { addEnumeration, modifyEnumeration } from \"./EnumerationMerger\";\r\nimport { addEnumerator, modifyEnumerator } from \"./EnumeratorMerger\";\r\nimport { addKindOfQuantity, modifyKindOfQuantity } from \"./KindOfQuantityMerger\";\r\nimport { addMixinClass, modifyMixinClass } from \"./MixinMerger\";\r\nimport { addPhenomenon, modifyPhenomenon } from \"./PhenomenonMerger\";\r\nimport { addPropertyCategory, modifyPropertyCategory } from \"./PropertyCategoryMerger\";\r\nimport { addRelationshipClass, mergeRelationshipClassConstraint, mergeRelationshipConstraint, modifyRelationshipClass } from \"./RelationshipClassMerger\";\r\nimport { addSchemaReferences, modifySchemaReferences } from \"./SchemaReferenceMerger\";\r\nimport { addStructClass, modifyStructClass } from \"./StructClassMerger\";\r\nimport { addUnitSystem, modifyUnitSystem } from \"./UnitSystemMerger\";\r\nimport { mergePropertyDifference } from \"./PropertyMerger\";\r\nimport { isClassDifference } from \"../Differencing/Utils\";\r\nimport { SchemaDifferenceVisitor } from \"../Differencing/SchemaDifferenceVisitor\";\r\nimport { SchemaItemKey } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaMergeContext } from \"./SchemaMerger\";\r\n\r\n/** Definition of schema items change type handler array. */\r\ninterface ItemChangeTypeHandler<T extends AnySchemaDifference> {\r\n add: (context: SchemaMergeContext, entry: T) => Promise<void>;\r\n modify: (context: SchemaMergeContext, entry: T, key: SchemaItemKey) => Promise<void>;\r\n}\r\n\r\n/**\r\n * Implementation of ISchemaDifferenceVisitor that can be used to traverse schema\r\n * differences to call the appropriated merger methods.\r\n * @internal\r\n */\r\nexport class SchemaMergingVisitor implements SchemaDifferenceVisitor {\r\n\r\n private readonly _context: SchemaMergeContext;\r\n\r\n /**\r\n * Initializes a new instance of SchemaMergingVisitor class.\r\n */\r\n constructor(context: SchemaMergeContext) {\r\n this._context = context;\r\n }\r\n\r\n /**\r\n * Gets a SchemaItemKey for the given item name.\r\n */\r\n private toItemKey(itemName: string): SchemaItemKey {\r\n return new SchemaItemKey(itemName, this._context.targetSchemaKey);\r\n }\r\n\r\n /**\r\n * Shared merging logic for all types of ClassItemDifference union.\r\n */\r\n private async visitClassDifference<T extends AnyClassItemDifference>(entry: T, index: number, array: AnySchemaDifference[], handler: ItemChangeTypeHandler<T>) {\r\n return this.visitSchemaItemDifference(entry, {\r\n add: async (context) => {\r\n // To add classes a slightly different approach is done. In fact the class entries gets processed\r\n // two times. The first time, a stub with the bare minimum is added to the schema. The second time,\r\n // the class gets completed with all properties, mixins, etc...\r\n if(entry.changeType === \"add\" && !await context.targetSchema.getItem(entry.itemName)) {\r\n await handler.add(this._context, {\r\n ...entry,\r\n difference: {\r\n ...entry.difference,\r\n // Remove everything we want to validate before setting, this is done in the second iteration.\r\n baseClass: undefined,\r\n mixins: undefined,\r\n properties: undefined,\r\n customAttributes: undefined,\r\n },\r\n });\r\n\r\n // Searches for the last class difference and adds the entry after it. That way,\r\n // the class is completed before class related entries get processed.\r\n const insertIndex = findIndexOf(array, (e) => !isClassDifference(e), index) || array.length;\r\n array.splice(insertIndex, 0, entry);\r\n\r\n return;\r\n }\r\n\r\n // Now both a modification change or the second add iteration is a modification of an existing class.\r\n // So, regardless of the actual change type, modify is called.\r\n return handler.modify(this._context, entry, this.toItemKey(entry.itemName));\r\n },\r\n modify: handler.modify,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling ConstantDifference.\r\n * @internal\r\n */\r\n public async visitConstantDifference(entry: ConstantDifference): Promise<void> {\r\n return this.visitSchemaItemDifference(entry, {\r\n add: addConstant,\r\n modify: modifyConstant,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling CustomAttributeClassDifference.\r\n * @internal\r\n */\r\n public async visitCustomAttributeClassDifference(entry: CustomAttributeClassDifference, index: number, array: AnySchemaDifference[]): Promise<void> {\r\n return this.visitClassDifference(entry, index, array, {\r\n add: addCustomAttributeClass,\r\n modify: modifyCustomAttributeClass,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling CustomAttributeDifference.\r\n * @internal\r\n */\r\n public async visitCustomAttributeInstanceDifference(entry: CustomAttributeDifference): Promise<void> {\r\n switch(entry.changeType) {\r\n case \"add\": return addCustomAttribute(this._context, entry);\r\n }\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling EntityClassDifference.\r\n * @internal\r\n */\r\n public async visitEntityClassDifference(entry: EntityClassDifference, index: number, array: AnySchemaDifference[]): Promise<void> {\r\n return this.visitClassDifference(entry, index, array, {\r\n add: addEntityClass,\r\n modify: modifyEntityClass,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling EntityClassMixinDifference.\r\n * @internal\r\n */\r\n public async visitEntityClassMixinDifference(entry: EntityClassMixinDifference): Promise<void> {\r\n switch(entry.changeType) {\r\n case \"add\": return addClassMixins(this._context, entry);\r\n }\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling EnumerationDifference.\r\n * @internal\r\n */\r\n public async visitEnumerationDifference(entry: EnumerationDifference): Promise<void> {\r\n return this.visitSchemaItemDifference(entry, {\r\n add: addEnumeration,\r\n modify: modifyEnumeration,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling EnumeratorDifference.\r\n * @internal\r\n */\r\n public async visitEnumeratorDifference(entry: EnumeratorDifference): Promise<void> {\r\n switch(entry.changeType) {\r\n case \"add\": return addEnumerator(this._context, entry);\r\n case \"modify\": return modifyEnumerator(this._context, entry, this.toItemKey(entry.itemName));\r\n }\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling FormatDifference.\r\n * @internal\r\n */\r\n public async visitFormatDifference(_entry: FormatDifference): Promise<void> {\r\n // TODO: Add merger handler...\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling InvertedUnitDifference.\r\n * @internal\r\n */\r\n public async visitInvertedUnitDifference(_entry: InvertedUnitDifference): Promise<void> {\r\n // TODO: Add merger handler...\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling KindOfQuantityDifference.\r\n * @internal\r\n */\r\n public async visitKindOfQuantityDifference(entry: KindOfQuantityDifference): Promise<void> {\r\n return this.visitSchemaItemDifference(entry, {\r\n add: addKindOfQuantity,\r\n modify: modifyKindOfQuantity,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling MixinClassDifference.\r\n * @internal\r\n */\r\n public async visitMixinDifference(entry: MixinClassDifference, index: number, array: AnySchemaDifference[]): Promise<void> {\r\n return this.visitClassDifference(entry, index, array, {\r\n add: addMixinClass,\r\n modify: modifyMixinClass,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling PhenomenonDifference.\r\n * @internal\r\n */\r\n public async visitPhenomenonDifference(entry: PhenomenonDifference): Promise<void> {\r\n return this.visitSchemaItemDifference(entry, {\r\n add: addPhenomenon,\r\n modify: modifyPhenomenon,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling PropertyCategoryDifference.\r\n * @internal\r\n */\r\n public async visitPropertyCategoryDifference(entry: PropertyCategoryDifference): Promise<void> {\r\n return this.visitSchemaItemDifference(entry, {\r\n add: addPropertyCategory,\r\n modify: modifyPropertyCategory,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling ClassPropertyDifference.\r\n * @internal\r\n */\r\n public async visitPropertyDifference(entry: ClassPropertyDifference): Promise<void> {\r\n await mergePropertyDifference(this._context, entry);\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling RelationshipClassDifference.\r\n * @internal\r\n */\r\n public async visitRelationshipClassDifference(entry: RelationshipClassDifference, index: number, array: AnySchemaDifference[]): Promise<void> {\r\n return this.visitClassDifference(entry, index, array, {\r\n add: addRelationshipClass,\r\n modify: modifyRelationshipClass,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling RelationshipConstraintClassDifference.\r\n * @internal\r\n */\r\n public async visitRelationshipConstraintClassDifference(entry: RelationshipConstraintClassDifference): Promise<void> {\r\n await mergeRelationshipClassConstraint(this._context, entry);\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling RelationshipConstraintDifference.\r\n * @internal\r\n */\r\n public async visitRelationshipConstraintDifference(entry: RelationshipConstraintDifference): Promise<void> {\r\n await mergeRelationshipConstraint(this._context, entry);\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling SchemaDifference.\r\n * @internal\r\n */\r\n public async visitSchemaDifference({ difference }: SchemaDifference): Promise<void> {\r\n if (difference.label !== undefined) {\r\n await this._context.editor.setDisplayLabel(this._context.targetSchemaKey, difference.label);\r\n }\r\n if (difference.description !== undefined) {\r\n await this._context.editor.setDescription(this._context.targetSchemaKey, difference.description);\r\n }\r\n }\r\n\r\n /**\r\n * Shared merging logic for all types of AnySchemaItemDifference union.\r\n */\r\n private async visitSchemaItemDifference<T extends AnySchemaItemDifference>(entry: T, handler: ItemChangeTypeHandler<T>) {\r\n switch(entry.changeType) {\r\n case \"add\": {\r\n return handler.add(this._context, entry);\r\n }\r\n case \"modify\": {\r\n if(\"schemaItemType\" in entry.difference && entry.difference.schemaItemType !== entry.schemaType) {\r\n throw new Error(`Changing the type of item '${entry.itemName}' not supported.`);\r\n }\r\n\r\n return handler.modify(this._context, entry, this.toItemKey(entry.itemName));\r\n };\r\n }\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling SchemaReferenceDifference.\r\n * @internal\r\n */\r\n public async visitSchemaReferenceDifference(entry: SchemaReferenceDifference): Promise<void> {\r\n switch(entry.changeType) {\r\n case \"add\": return addSchemaReferences(this._context, entry);\r\n case \"modify\": return modifySchemaReferences(this._context, entry);\r\n }\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling StructClassDifference.\r\n * @internal\r\n */\r\n public async visitStructClassDifference(entry: StructClassDifference, index: number, array: AnySchemaDifference[]): Promise<void> {\r\n return this.visitClassDifference(entry, index, array, {\r\n add: addStructClass,\r\n modify: modifyStructClass,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling UnitDifference.\r\n * @internal\r\n */\r\n public async visitUnitDifference(_entry: UnitDifference): Promise<void> {\r\n // TODO: Add merger handler...\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling UnitSystemDifference.\r\n * @internal\r\n */\r\n public async visitUnitSystemDifference(entry: UnitSystemDifference): Promise<void> {\r\n return this.visitSchemaItemDifference(entry, {\r\n add: addUnitSystem,\r\n modify: modifyUnitSystem,\r\n });\r\n }\r\n}\r\n\r\n/**\r\n * Helper method to get the index of the first element in the array that satisfies the provided testing function.\r\n * @param array Array to search.\r\n * @param predicate Function to execute on each value in the array.\r\n * @param fromIndex The index to start the search at.\r\n * @returns An index in the array if an element passes the test; otherwise, false.\r\n */\r\nfunction findIndexOf(array: AnySchemaDifference[], predicate: (entry: AnySchemaDifference) => boolean, fromIndex: number) {\r\n for (let i = fromIndex; i < array.length; i++) {\r\n if (predicate(array[i]))\r\n return i;\r\n }\r\n return false;\r\n}\r\n"]}
@@ -0,0 +1,19 @@
1
+ import { SchemaDifferenceWalker } from "../Differencing/SchemaDifferenceVisitor";
2
+ import { AnySchemaDifference, DifferenceType } from "../Differencing/SchemaDifference";
3
+ /**
4
+ * A walker that traverses the schema differences in a certain oder and invokes the appropriate
5
+ * visitor method for each kind of schema difference.
6
+ * @internal
7
+ */
8
+ export declare class SchemaMergingWalker extends SchemaDifferenceWalker {
9
+ /**
10
+ * Traverses the schema differences and calls the appropriate method on the visitor.
11
+ * This method overrides the derived class method to apply some ordering how the
12
+ * differences are traversed.
13
+ *
14
+ * @param differences The differences to traverse.
15
+ * @param changeType Optional type of change to filter by.
16
+ */
17
+ traverse(differences: Array<AnySchemaDifference>, changeType?: DifferenceType): Promise<void>;
18
+ }
19
+ //# sourceMappingURL=SchemaMergingWalker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaMergingWalker.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaMergingWalker.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAgC,MAAM,kCAAkC,CAAC;AAErH;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,sBAAsB;IAE7D;;;;;;;OAOG;IACmB,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC,mBAAmB,CAAC,EAAE,UAAU,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAwCpH"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchemaMergingWalker = void 0;
4
+ /*---------------------------------------------------------------------------------------------
5
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
+ * See LICENSE.md in the project root for license terms and full copyright notice.
7
+ *--------------------------------------------------------------------------------------------*/
8
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
9
+ const SchemaDifferenceVisitor_1 = require("../Differencing/SchemaDifferenceVisitor");
10
+ const SchemaDifference_1 = require("../Differencing/SchemaDifference");
11
+ /**
12
+ * A walker that traverses the schema differences in a certain oder and invokes the appropriate
13
+ * visitor method for each kind of schema difference.
14
+ * @internal
15
+ */
16
+ class SchemaMergingWalker extends SchemaDifferenceVisitor_1.SchemaDifferenceWalker {
17
+ /**
18
+ * Traverses the schema differences and calls the appropriate method on the visitor.
19
+ * This method overrides the derived class method to apply some ordering how the
20
+ * differences are traversed.
21
+ *
22
+ * @param differences The differences to traverse.
23
+ * @param changeType Optional type of change to filter by.
24
+ */
25
+ async traverse(differences, changeType) {
26
+ const filterByType = (schemaType) => {
27
+ return (entry) => {
28
+ return entry.schemaType === schemaType && (!changeType || entry.changeType === changeType);
29
+ };
30
+ };
31
+ return super.traverse([
32
+ // First the schema related differences are traversed...
33
+ ...differences.filter(filterByType(SchemaDifference_1.SchemaOtherTypes.Schema)),
34
+ ...differences.filter(filterByType(SchemaDifference_1.SchemaOtherTypes.SchemaReference)),
35
+ // Then the schema items (excluding classes)...
36
+ ...differences.filter(filterByType(ecschema_metadata_1.SchemaItemType.UnitSystem)),
37
+ ...differences.filter(filterByType(ecschema_metadata_1.SchemaItemType.PropertyCategory)),
38
+ ...differences.filter(filterByType(ecschema_metadata_1.SchemaItemType.Enumeration)),
39
+ ...differences.filter(filterByType(SchemaDifference_1.SchemaOtherTypes.Enumerator)),
40
+ ...differences.filter(filterByType(ecschema_metadata_1.SchemaItemType.Phenomenon)),
41
+ ...differences.filter(filterByType(ecschema_metadata_1.SchemaItemType.Unit)),
42
+ ...differences.filter(filterByType(ecschema_metadata_1.SchemaItemType.InvertedUnit)),
43
+ ...differences.filter(filterByType(ecschema_metadata_1.SchemaItemType.Format)),
44
+ ...differences.filter(filterByType(ecschema_metadata_1.SchemaItemType.KindOfQuantity)),
45
+ ...differences.filter(filterByType(ecschema_metadata_1.SchemaItemType.Constant)),
46
+ // Followed by classes and class related differences...
47
+ ...differences.filter(filterByType(ecschema_metadata_1.SchemaItemType.CustomAttributeClass)),
48
+ ...differences.filter(filterByType(ecschema_metadata_1.SchemaItemType.Mixin)),
49
+ ...differences.filter(filterByType(ecschema_metadata_1.SchemaItemType.StructClass)),
50
+ ...differences.filter(filterByType(ecschema_metadata_1.SchemaItemType.EntityClass)),
51
+ ...differences.filter(filterByType(ecschema_metadata_1.SchemaItemType.RelationshipClass)),
52
+ ...differences.filter(filterByType(SchemaDifference_1.SchemaOtherTypes.EntityClassMixin)),
53
+ ...differences.filter(filterByType(SchemaDifference_1.SchemaOtherTypes.RelationshipConstraint)),
54
+ ...differences.filter(filterByType(SchemaDifference_1.SchemaOtherTypes.RelationshipConstraintClass)),
55
+ ...differences.filter(filterByType(SchemaDifference_1.SchemaOtherTypes.Property)),
56
+ // And then the custom attributes.
57
+ ...differences.filter(filterByType(SchemaDifference_1.SchemaOtherTypes.CustomAttributeInstance)),
58
+ ]);
59
+ }
60
+ }
61
+ exports.SchemaMergingWalker = SchemaMergingWalker;
62
+ //# sourceMappingURL=SchemaMergingWalker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaMergingWalker.js","sourceRoot":"","sources":["../../../src/Merging/SchemaMergingWalker.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAA0D;AAC1D,qFAAiF;AACjF,uEAAqH;AAErH;;;;GAIG;AACH,MAAa,mBAAoB,SAAQ,gDAAsB;IAE7D;;;;;;;OAOG;IACa,KAAK,CAAC,QAAQ,CAAC,WAAuC,EAAE,UAA2B;QAEjG,MAAM,YAAY,GAAG,CAAC,UAAsB,EAAE,EAAE;YAC9C,OAAO,CAAC,KAA0B,EAAE,EAAE;gBACpC,OAAO,KAAK,CAAC,UAAU,KAAK,UAAU,IAAI,CAAC,CAAC,UAAU,IAAI,KAAK,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;YAC7F,CAAC,CAAC;QACJ,CAAC,CAAC;QAEF,OAAO,KAAK,CAAC,QAAQ,CAAC;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C,WAAW,CAAC,CAAC;YAC/D,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,kCAAc,CAAC,WAAW,CAAC,CAAC;YAC/D,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,kCAAc,CAAC,iBAAiB,CAAC,CAAC;YACrE,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,mCAAgB,CAAC,gBAAgB,CAAC,CAAC;YACtE,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,mCAAgB,CAAC,sBAAsB,CAAC,CAAC;YAC5E,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,mCAAgB,CAAC,2BAA2B,CAAC,CAAC;YACjF,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,mCAAgB,CAAC,QAAQ,CAAC,CAAC;YAE9D,kCAAkC;YAClC,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,mCAAgB,CAAC,uBAAuB,CAAC,CAAC;SAC9E,CAAC,CAAC;IACL,CAAC;CACF;AAlDD,kDAkDC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { SchemaItemType } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaDifferenceWalker } from \"../Differencing/SchemaDifferenceVisitor\";\r\nimport { AnySchemaDifference, DifferenceType, SchemaOtherTypes, SchemaType } from \"../Differencing/SchemaDifference\";\r\n\r\n/**\r\n * A walker that traverses the schema differences in a certain oder and invokes the appropriate\r\n * visitor method for each kind of schema difference.\r\n * @internal\r\n */\r\nexport class SchemaMergingWalker extends SchemaDifferenceWalker {\r\n\r\n /**\r\n * Traverses the schema differences and calls the appropriate method on the visitor.\r\n * This method overrides the derived class method to apply some ordering how the\r\n * differences are traversed.\r\n *\r\n * @param differences The differences to traverse.\r\n * @param changeType Optional type of change to filter by.\r\n */\r\n public override async traverse(differences: Array<AnySchemaDifference>, changeType?: DifferenceType): Promise<void> {\r\n\r\n const filterByType = (schemaType: SchemaType) => {\r\n return (entry: AnySchemaDifference) => {\r\n return entry.schemaType === schemaType && (!changeType || entry.changeType === changeType);\r\n };\r\n };\r\n\r\n return super.traverse([\r\n // First the schema related differences are traversed...\r\n ...differences.filter(filterByType(SchemaOtherTypes.Schema)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.SchemaReference)),\r\n\r\n // Then the schema items (excluding classes)...\r\n ...differences.filter(filterByType(SchemaItemType.UnitSystem)),\r\n ...differences.filter(filterByType(SchemaItemType.PropertyCategory)),\r\n ...differences.filter(filterByType(SchemaItemType.Enumeration)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.Enumerator)),\r\n ...differences.filter(filterByType(SchemaItemType.Phenomenon)),\r\n ...differences.filter(filterByType(SchemaItemType.Unit)),\r\n ...differences.filter(filterByType(SchemaItemType.InvertedUnit)),\r\n ...differences.filter(filterByType(SchemaItemType.Format)),\r\n ...differences.filter(filterByType(SchemaItemType.KindOfQuantity)),\r\n ...differences.filter(filterByType(SchemaItemType.Constant)),\r\n\r\n // Followed by classes and class related differences...\r\n ...differences.filter(filterByType(SchemaItemType.CustomAttributeClass)),\r\n ...differences.filter(filterByType(SchemaItemType.Mixin)),\r\n ...differences.filter(filterByType(SchemaItemType.StructClass)),\r\n ...differences.filter(filterByType(SchemaItemType.EntityClass)),\r\n ...differences.filter(filterByType(SchemaItemType.RelationshipClass)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.EntityClassMixin)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.RelationshipConstraint)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.RelationshipConstraintClass)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.Property)),\r\n\r\n // And then the custom attributes.\r\n ...differences.filter(filterByType(SchemaOtherTypes.CustomAttributeInstance)),\r\n ]);\r\n }\r\n}\r\n"]}