@itwin/ecschema-editing 4.8.0-dev.8 → 4.8.0-dev.9
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/lib/cjs/Differencing/SchemaDifference.d.ts +10 -119
- package/lib/cjs/Differencing/SchemaDifference.d.ts.map +1 -1
- package/lib/cjs/Differencing/SchemaDifference.js +28 -198
- package/lib/cjs/Differencing/SchemaDifference.js.map +1 -1
- package/lib/cjs/Differencing/Utils.d.ts +100 -0
- package/lib/cjs/Differencing/Utils.d.ts.map +1 -0
- package/lib/cjs/Differencing/Utils.js +165 -0
- package/lib/cjs/Differencing/Utils.js.map +1 -0
- package/lib/cjs/Editing/Editor.d.ts +7 -2
- package/lib/cjs/Editing/Editor.d.ts.map +1 -1
- package/lib/cjs/Editing/Editor.js +24 -1
- package/lib/cjs/Editing/Editor.js.map +1 -1
- package/lib/cjs/Editing/Exception.d.ts +0 -1
- package/lib/cjs/Editing/Exception.d.ts.map +1 -1
- package/lib/cjs/Editing/Exception.js +0 -1
- package/lib/cjs/Editing/Exception.js.map +1 -1
- package/lib/cjs/Editing/Formats.d.ts.map +1 -1
- package/lib/cjs/Editing/Formats.js +4 -1
- package/lib/cjs/Editing/Formats.js.map +1 -1
- package/lib/cjs/Editing/KindOfQuantities.d.ts.map +1 -1
- package/lib/cjs/Editing/KindOfQuantities.js +3 -1
- package/lib/cjs/Editing/KindOfQuantities.js.map +1 -1
- package/lib/cjs/Editing/Properties.d.ts +1 -4
- package/lib/cjs/Editing/Properties.d.ts.map +1 -1
- package/lib/cjs/Editing/Properties.js +4 -5
- package/lib/cjs/Editing/Properties.js.map +1 -1
- package/lib/cjs/Editing/SchemaItems.d.ts +2 -2
- package/lib/cjs/Editing/SchemaItems.d.ts.map +1 -1
- package/lib/cjs/Editing/SchemaItems.js +4 -24
- package/lib/cjs/Editing/SchemaItems.js.map +1 -1
- package/lib/cjs/Merging/ClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/ClassMerger.js +10 -10
- package/lib/cjs/Merging/ClassMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaItemMerger.d.ts +4 -4
- package/lib/cjs/Merging/SchemaItemMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaItemMerger.js +18 -18
- package/lib/cjs/Merging/SchemaItemMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.d.ts +7 -7
- package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.js +32 -31
- package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
- package/lib/cjs/ecschema-editing.d.ts +2 -1
- package/lib/cjs/ecschema-editing.d.ts.map +1 -1
- package/lib/cjs/ecschema-editing.js +3 -2
- package/lib/cjs/ecschema-editing.js.map +1 -1
- package/package.json +9 -9
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateSchemaItemKey = exports.updateSchemaItemFullName = exports.mergeSchemaItems = exports.locateSchemaItem = void 0;
|
|
4
|
-
const SchemaDifference_1 = require("../Differencing/SchemaDifference");
|
|
5
4
|
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
6
5
|
const EnumerationMerger_1 = require("./EnumerationMerger");
|
|
7
6
|
const PhenomenonMerger_1 = require("./PhenomenonMerger");
|
|
@@ -10,20 +9,21 @@ const UnitSystemMerger_1 = require("./UnitSystemMerger");
|
|
|
10
9
|
const KindOfQuantityMerger_1 = require("./KindOfQuantityMerger");
|
|
11
10
|
const ConstantMerger_1 = require("./ConstantMerger");
|
|
12
11
|
const ClassMerger_1 = require("./ClassMerger");
|
|
12
|
+
const Utils = require("../Differencing/Utils");
|
|
13
13
|
/**
|
|
14
14
|
* Handles the merging logic for everything that is same for all schema items such as labels or descriptions
|
|
15
15
|
* @internal
|
|
16
16
|
*/
|
|
17
|
-
async function mergeSchemaItem(context,
|
|
18
|
-
if (
|
|
19
|
-
await merger.add(context,
|
|
17
|
+
async function mergeSchemaItem(context, difference, merger) {
|
|
18
|
+
if (difference.changeType === "add") {
|
|
19
|
+
await merger.add(context, difference);
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
|
-
if (
|
|
23
|
-
const schemaItem = await locateSchemaItem(context,
|
|
24
|
-
return merger.modify(context,
|
|
22
|
+
if (difference.changeType === "modify") {
|
|
23
|
+
const schemaItem = await locateSchemaItem(context, difference.itemName, difference.schemaType);
|
|
24
|
+
return merger.modify(context, difference, schemaItem.key, schemaItem);
|
|
25
25
|
}
|
|
26
|
-
throw new Error(`The merger does not support ${
|
|
26
|
+
throw new Error(`The merger does not support ${difference.changeType} of ${difference.schemaType}.`);
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* @internal
|
|
@@ -41,24 +41,24 @@ exports.locateSchemaItem = locateSchemaItem;
|
|
|
41
41
|
* Merges the given set of schema items. As schema items may depend or relate with other
|
|
42
42
|
* schema items, the list gets filtered to ensure the items get merged in a certain order.
|
|
43
43
|
* @param context The current merging context.
|
|
44
|
-
* @param
|
|
44
|
+
* @param differences Set of schema item that differed.
|
|
45
45
|
* @returns An async iterable with the merge result for each schema item.
|
|
46
46
|
* @internal
|
|
47
47
|
*/
|
|
48
|
-
async function* mergeSchemaItems(context,
|
|
49
|
-
for (const difference of
|
|
48
|
+
async function* mergeSchemaItems(context, differences) {
|
|
49
|
+
for (const difference of differences.filter(Utils.isUnitSystemDifference)) {
|
|
50
50
|
yield await mergeSchemaItem(context, difference, UnitSystemMerger_1.unitSystemMerger);
|
|
51
51
|
}
|
|
52
|
-
for (const difference of
|
|
52
|
+
for (const difference of differences.filter(Utils.isPropertyCategoryDifference)) {
|
|
53
53
|
yield await mergeSchemaItem(context, difference, PropertyCategoryMerger_1.propertyCategoryMerger);
|
|
54
54
|
}
|
|
55
|
-
for (const difference of
|
|
55
|
+
for (const difference of differences.filter(Utils.isEnumerationDifference)) {
|
|
56
56
|
yield await mergeSchemaItem(context, difference, EnumerationMerger_1.enumerationMerger);
|
|
57
57
|
}
|
|
58
|
-
for (const difference of
|
|
58
|
+
for (const difference of differences.filter(Utils.isEnumeratorDifference)) {
|
|
59
59
|
yield await mergeSchemaItem(context, difference, EnumerationMerger_1.enumeratorMerger);
|
|
60
60
|
}
|
|
61
|
-
for (const difference of
|
|
61
|
+
for (const difference of differences.filter(Utils.isPhenomenonDifference)) {
|
|
62
62
|
yield await mergeSchemaItem(context, difference, PhenomenonMerger_1.phenomenonMerger);
|
|
63
63
|
}
|
|
64
64
|
// TODO:
|
|
@@ -66,15 +66,15 @@ async function* mergeSchemaItems(context, itemChanges) {
|
|
|
66
66
|
// - Unit
|
|
67
67
|
// - Inverted Unit
|
|
68
68
|
// - Format
|
|
69
|
-
for (const difference of
|
|
69
|
+
for (const difference of differences.filter(Utils.isKindOfQuantityDifference)) {
|
|
70
70
|
yield await mergeSchemaItem(context, difference, KindOfQuantityMerger_1.kindOfQuantityMerger);
|
|
71
71
|
}
|
|
72
|
-
for (const difference of
|
|
72
|
+
for (const difference of differences.filter(Utils.isConstantDifference)) {
|
|
73
73
|
yield await mergeSchemaItem(context, difference, ConstantMerger_1.constantMerger);
|
|
74
74
|
}
|
|
75
75
|
// Classes are slightly differently merged, since they can refer each other the process
|
|
76
76
|
// uses several stages to merge.
|
|
77
|
-
for await (const classMergeResult of (0, ClassMerger_1.mergeClassItems)(context,
|
|
77
|
+
for await (const classMergeResult of (0, ClassMerger_1.mergeClassItems)(context, differences)) {
|
|
78
78
|
yield classMergeResult;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaItemMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaItemMerger.ts"],"names":[],"mappings":";;;AAKA,uEAA+I;AAC/I,gEAAqH;AACrH,2DAA0E;AAC1E,yDAAsD;AACtD,qEAAkE;AAClE,yDAAsD;AACtD,iEAA8D;AAC9D,qDAAk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AC,aAA4B,EAAE,OAAsB;IACtF,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IACxD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,mGAAmG;QACnG,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,CAAC;AAClB,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 type { SchemaMergeContext } from \"./SchemaMerger\";\nimport { AnySchemaDifference, AnySchemaItemDifference, AnySchemaItemPathDifference, SchemaDifference } from \"../Differencing/SchemaDifference\";\nimport { ECObjectsError, ECObjectsStatus, SchemaContext, SchemaItem, SchemaItemKey } from \"@itwin/ecschema-metadata\";\nimport { enumerationMerger, enumeratorMerger } from \"./EnumerationMerger\";\nimport { phenomenonMerger } from \"./PhenomenonMerger\";\nimport { propertyCategoryMerger } from \"./PropertyCategoryMerger\";\nimport { unitSystemMerger } from \"./UnitSystemMerger\";\nimport { kindOfQuantityMerger } from \"./KindOfQuantityMerger\";\nimport { constantMerger } from \"./ConstantMerger\";\nimport { mergeClassItems } from \"./ClassMerger\";\n\n/**\n * @internal\n */\nexport interface SchemaItemMergerHandler<T extends AnySchemaItemDifference | AnySchemaItemPathDifference> {\n add: (context: SchemaMergeContext, change: T) => Promise<SchemaItemKey>;\n modify: (context: SchemaMergeContext, change: T, itemKey: SchemaItemKey, item: any) => Promise<void>;\n}\n\n/**\n * Handles the merging logic for everything that is same for all schema items such as labels or descriptions\n * @internal\n */\nasync function mergeSchemaItem<T extends AnySchemaItemDifference|AnySchemaItemPathDifference>(context: SchemaMergeContext, change: T, merger: SchemaItemMergerHandler<T>): Promise<void> {\n if(change.changeType === \"add\") {\n await merger.add(context, change);\n return;\n }\n\n if(change.changeType === \"modify\") {\n const schemaItem = await locateSchemaItem(context, change.itemName, change.schemaType);\n return merger.modify(context, change, schemaItem.key, schemaItem);\n }\n\n throw new Error(`The merger does not support ${change.changeType} of ${change.schemaType}.`);\n}\n\n/**\n * @internal\n */\nexport async function locateSchemaItem(context: SchemaMergeContext, itemName: string, schemaType: string) {\n const schemaItemKey = new SchemaItemKey(itemName, context.targetSchemaKey);\n const schemaItem = await context.editor.schemaContext.getSchemaItem(schemaItemKey);\n if (schemaItem === undefined) {\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `${schemaType} ${schemaItemKey.fullName} not found in schema context.`);\n }\n\n return schemaItem;\n}\n\n/**\n * Merges the given set of schema items. As schema items may depend or relate with other\n * schema items, the list gets filtered to ensure the items get merged in a certain order.\n * @param context The current merging context.\n * @param itemChanges Set of schema item that differed.\n * @returns An async iterable with the merge result for each schema item.\n * @internal\n */\nexport async function* mergeSchemaItems(context: SchemaMergeContext, itemChanges: AnySchemaDifference[]) {\n for (const difference of itemChanges.filter(SchemaDifference.isUnitSystemDifference)) {\n yield await mergeSchemaItem(context, difference, unitSystemMerger);\n }\n\n for (const difference of itemChanges.filter(SchemaDifference.isPropertyCategoryDifference)) {\n yield await mergeSchemaItem(context, difference, propertyCategoryMerger);\n }\n\n for (const difference of itemChanges.filter(SchemaDifference.isEnumerationDifference)) {\n yield await mergeSchemaItem(context, difference, enumerationMerger);\n }\n\n for (const difference of itemChanges.filter(SchemaDifference.isEnumeratorDifference)) {\n yield await mergeSchemaItem(context, difference, enumeratorMerger);\n }\n\n for (const difference of itemChanges.filter(SchemaDifference.isPhenomenonDifference)) {\n yield await mergeSchemaItem(context, difference, phenomenonMerger);\n }\n\n // TODO:\n // The following schema items are not supported yet. Mentioned in the processing order:\n // - Unit\n // - Inverted Unit\n // - Format\n\n for (const difference of itemChanges.filter(SchemaDifference.isKindOfQuantityDifference)) {\n yield await mergeSchemaItem(context, difference, kindOfQuantityMerger);\n }\n\n for (const difference of itemChanges.filter(SchemaDifference.isConstantDifference)) {\n yield await mergeSchemaItem(context, difference, constantMerger);\n }\n\n // Classes are slightly differently merged, since they can refer each other the process\n // uses several stages to merge.\n for await (const classMergeResult of mergeClassItems(context, itemChanges)) {\n yield classMergeResult;\n }\n}\n\n/**\n * Convenience-method around updateSchemaItemKey that returns the full name instead of a SchemaItemKey.\n * @internal\n */\nexport async function updateSchemaItemFullName(context: SchemaMergeContext, reference: string) {\n const schemaItemKey = await updateSchemaItemKey(context, reference);\n return schemaItemKey.fullName;\n}\n\n/**\n * Updates the given reference if it refers to a SchemaItem in the source Schema and\n * returns a SchemaItemKey. If any other schema is referred the reference is not change.\n * @internal\n */\nexport async function updateSchemaItemKey(context: SchemaMergeContext, reference: string) {\n const [schemaName, itemName] = SchemaItem.parseFullName(reference);\n if (context.sourceSchemaKey.compareByName(schemaName)) {\n return resolveSchemaItemKey(context.editor.schemaContext, new SchemaItemKey(itemName, context.targetSchemaKey));\n }\n\n const referencedSchema = await context.targetSchema.getReference(schemaName);\n if (referencedSchema !== undefined) {\n return resolveSchemaItemKey(context.editor.schemaContext, new SchemaItemKey(itemName, referencedSchema.schemaKey));\n }\n\n throw new Error(`Cannot locate referenced schema item ${reference}`);\n}\n\n/**\n * To support case insensitivity for schema items, the given key is checked if there\n * exists an item for it.\n * @internal\n */\nasync function resolveSchemaItemKey(schemaContext: SchemaContext, itemKey: SchemaItemKey): Promise<SchemaItemKey> {\n const item = await schemaContext.getSchemaItem(itemKey);\n if (item === undefined) {\n // If the schema item hasn't been created yet, we have to trust the given key is correctly spelled.\n return itemKey;\n }\n return item.key;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SchemaItemMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaItemMerger.ts"],"names":[],"mappings":";;;AAMA,gEAAqH;AACrH,2DAA0E;AAC1E,yDAAsD;AACtD,qEAAkE;AAClE,yDAAsD;AACtD,iEAA8D;AAC9D,qDAAkD;AAClD,+CAAgD;AAChD,+CAA+C;AAU/C;;;GAGG;AACH,KAAK,UAAU,eA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C,aAAa,CAAC,OAAO,CAAC,CAAC;IACxD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,mGAAmG;QACnG,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,CAAC;AAClB,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 type { SchemaMergeContext } from \"./SchemaMerger\";\nimport { AnySchemaDifference, AnySchemaItemDifference, AnySchemaItemPathDifference } from \"../Differencing/SchemaDifference\";\nimport { ECObjectsError, ECObjectsStatus, SchemaContext, SchemaItem, SchemaItemKey } from \"@itwin/ecschema-metadata\";\nimport { enumerationMerger, enumeratorMerger } from \"./EnumerationMerger\";\nimport { phenomenonMerger } from \"./PhenomenonMerger\";\nimport { propertyCategoryMerger } from \"./PropertyCategoryMerger\";\nimport { unitSystemMerger } from \"./UnitSystemMerger\";\nimport { kindOfQuantityMerger } from \"./KindOfQuantityMerger\";\nimport { constantMerger } from \"./ConstantMerger\";\nimport { mergeClassItems } from \"./ClassMerger\";\nimport * as Utils from \"../Differencing/Utils\";\n\n/**\n * @internal\n */\nexport interface SchemaItemMergerHandler<T extends AnySchemaItemDifference | AnySchemaItemPathDifference> {\n add: (context: SchemaMergeContext, difference: T) => Promise<SchemaItemKey>;\n modify: (context: SchemaMergeContext, difference: T, itemKey: SchemaItemKey, item: any) => Promise<void>;\n}\n\n/**\n * Handles the merging logic for everything that is same for all schema items such as labels or descriptions\n * @internal\n */\nasync function mergeSchemaItem<T extends AnySchemaItemDifference | AnySchemaItemPathDifference>(context: SchemaMergeContext, difference: T, merger: SchemaItemMergerHandler<T>): Promise<void> {\n if (difference.changeType === \"add\") {\n await merger.add(context, difference);\n return;\n }\n\n if (difference.changeType === \"modify\") {\n const schemaItem = await locateSchemaItem(context, difference.itemName, difference.schemaType);\n return merger.modify(context, difference, schemaItem.key, schemaItem);\n }\n\n throw new Error(`The merger does not support ${difference.changeType} of ${difference.schemaType}.`);\n}\n\n/**\n * @internal\n */\nexport async function locateSchemaItem(context: SchemaMergeContext, itemName: string, schemaType: string) {\n const schemaItemKey = new SchemaItemKey(itemName, context.targetSchemaKey);\n const schemaItem = await context.editor.schemaContext.getSchemaItem(schemaItemKey);\n if (schemaItem === undefined) {\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `${schemaType} ${schemaItemKey.fullName} not found in schema context.`);\n }\n\n return schemaItem;\n}\n\n/**\n * Merges the given set of schema items. As schema items may depend or relate with other\n * schema items, the list gets filtered to ensure the items get merged in a certain order.\n * @param context The current merging context.\n * @param differences Set of schema item that differed.\n * @returns An async iterable with the merge result for each schema item.\n * @internal\n */\nexport async function* mergeSchemaItems(context: SchemaMergeContext, differences: AnySchemaDifference[]) {\n for (const difference of differences.filter(Utils.isUnitSystemDifference)) {\n yield await mergeSchemaItem(context, difference, unitSystemMerger);\n }\n\n for (const difference of differences.filter(Utils.isPropertyCategoryDifference)) {\n yield await mergeSchemaItem(context, difference, propertyCategoryMerger);\n }\n\n for (const difference of differences.filter(Utils.isEnumerationDifference)) {\n yield await mergeSchemaItem(context, difference, enumerationMerger);\n }\n\n for (const difference of differences.filter(Utils.isEnumeratorDifference)) {\n yield await mergeSchemaItem(context, difference, enumeratorMerger);\n }\n\n for (const difference of differences.filter(Utils.isPhenomenonDifference)) {\n yield await mergeSchemaItem(context, difference, phenomenonMerger);\n }\n\n // TODO:\n // The following schema items are not supported yet. Mentioned in the processing order:\n // - Unit\n // - Inverted Unit\n // - Format\n\n for (const difference of differences.filter(Utils.isKindOfQuantityDifference)) {\n yield await mergeSchemaItem(context, difference, kindOfQuantityMerger);\n }\n\n for (const difference of differences.filter(Utils.isConstantDifference)) {\n yield await mergeSchemaItem(context, difference, constantMerger);\n }\n\n // Classes are slightly differently merged, since they can refer each other the process\n // uses several stages to merge.\n for await (const classMergeResult of mergeClassItems(context, differences)) {\n yield classMergeResult;\n }\n}\n\n/**\n * Convenience-method around updateSchemaItemKey that returns the full name instead of a SchemaItemKey.\n * @internal\n */\nexport async function updateSchemaItemFullName(context: SchemaMergeContext, reference: string) {\n const schemaItemKey = await updateSchemaItemKey(context, reference);\n return schemaItemKey.fullName;\n}\n\n/**\n * Updates the given reference if it refers to a SchemaItem in the source Schema and\n * returns a SchemaItemKey. If any other schema is referred the reference is not change.\n * @internal\n */\nexport async function updateSchemaItemKey(context: SchemaMergeContext, reference: string) {\n const [schemaName, itemName] = SchemaItem.parseFullName(reference);\n if (context.sourceSchemaKey.compareByName(schemaName)) {\n return resolveSchemaItemKey(context.editor.schemaContext, new SchemaItemKey(itemName, context.targetSchemaKey));\n }\n\n const referencedSchema = await context.targetSchema.getReference(schemaName);\n if (referencedSchema !== undefined) {\n return resolveSchemaItemKey(context.editor.schemaContext, new SchemaItemKey(itemName, referencedSchema.schemaKey));\n }\n\n throw new Error(`Cannot locate referenced schema item ${reference}`);\n}\n\n/**\n * To support case insensitivity for schema items, the given key is checked if there\n * exists an item for it.\n * @internal\n */\nasync function resolveSchemaItemKey(schemaContext: SchemaContext, itemKey: SchemaItemKey): Promise<SchemaItemKey> {\n const item = await schemaContext.getSchemaItem(itemKey);\n if (item === undefined) {\n // If the schema item hasn't been created yet, we have to trust the given key is correctly spelled.\n return itemKey;\n }\n return item.key;\n}\n"]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Schema, type SchemaContext, SchemaKey } from "@itwin/ecschema-metadata";
|
|
5
5
|
import { SchemaContextEditor } from "../Editing/Editor";
|
|
6
|
-
import {
|
|
6
|
+
import { SchemaDifferenceResult } from "../Differencing/SchemaDifference";
|
|
7
7
|
/**
|
|
8
8
|
* Defines the context of a Schema merging run.
|
|
9
9
|
* @internal
|
|
@@ -32,19 +32,19 @@ export declare class SchemaMerger {
|
|
|
32
32
|
* @param sourceSchema The schema the SchemaItems gets copied from.
|
|
33
33
|
* @returns The merged target schema.
|
|
34
34
|
*/
|
|
35
|
-
|
|
35
|
+
mergeSchemas(targetSchema: Schema, sourceSchema: Schema): Promise<Schema>;
|
|
36
36
|
/**
|
|
37
37
|
* Merges the schema differences into the target schema context.
|
|
38
|
-
* @param
|
|
38
|
+
* @param differenceResult The differences that shall be applied to the target schema.
|
|
39
39
|
* @alpha
|
|
40
40
|
*/
|
|
41
|
-
merge(
|
|
41
|
+
merge(differenceResult: SchemaDifferenceResult): Promise<Schema>;
|
|
42
42
|
/**
|
|
43
43
|
* Merges the schema differences in the target schema. The target schema is defined
|
|
44
44
|
* in the given differences object.
|
|
45
|
-
* @param
|
|
46
|
-
* @returns
|
|
45
|
+
* @param differenceResult The differences between a source schema and the target schema.
|
|
46
|
+
* @returns The modified Schema.
|
|
47
47
|
*/
|
|
48
|
-
private
|
|
48
|
+
private mergeDifferences;
|
|
49
49
|
}
|
|
50
50
|
//# sourceMappingURL=SchemaMerger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,
|
|
1
|
+
{"version":3,"file":"SchemaMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAA0C,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAMlH;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,eAAe,EAAE,SAAS,CAAC;IACpC,QAAQ,CAAC,eAAe,EAAE,SAAS,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC;CACtC;AAED;;;;GAIG;AACH,qBAAa,YAAY;IAEvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;IAE9C;;;OAGG;gBACS,cAAc,EAAE,aAAa;IAIzC;;;;;OAKG;IACU,YAAY,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAItF;;;;OAIG;IACU,KAAK,CAAC,gBAAgB,EAAE,sBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC;IAI7E;;;;;OAKG;YACW,gBAAgB;CAoD/B"}
|
|
@@ -15,6 +15,7 @@ const SchemaDifference_1 = require("../Differencing/SchemaDifference");
|
|
|
15
15
|
const CustomAttributeMerger_1 = require("./CustomAttributeMerger");
|
|
16
16
|
const SchemaItemMerger_1 = require("./SchemaItemMerger");
|
|
17
17
|
const SchemaReferenceMerger_1 = require("./SchemaReferenceMerger");
|
|
18
|
+
const Utils = require("../Differencing/Utils");
|
|
18
19
|
/**
|
|
19
20
|
* Class to merge two schemas together.
|
|
20
21
|
* @see [[merge]] to merge the schemas.
|
|
@@ -29,40 +30,40 @@ class SchemaMerger {
|
|
|
29
30
|
this._editor = new Editor_1.SchemaContextEditor(editingContext);
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* @
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
* Copy the SchemaItems of the source schemas to the target schema.
|
|
34
|
+
* @param targetSchema The schema the SchemaItems gets merged to.
|
|
35
|
+
* @param sourceSchema The schema the SchemaItems gets copied from.
|
|
36
|
+
* @returns The merged target schema.
|
|
37
|
+
*/
|
|
38
|
+
async mergeSchemas(targetSchema, sourceSchema) {
|
|
39
|
+
return this.merge(await (0, SchemaDifference_1.getSchemaDifferences)(targetSchema, sourceSchema));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Merges the schema differences into the target schema context.
|
|
43
|
+
* @param differenceResult The differences that shall be applied to the target schema.
|
|
38
44
|
* @alpha
|
|
39
45
|
*/
|
|
40
|
-
async merge(
|
|
41
|
-
|
|
42
|
-
if (source === undefined) {
|
|
43
|
-
throw new Error("When merging two schemas, source must not be undefined.");
|
|
44
|
-
}
|
|
45
|
-
return this.merge(await SchemaDifference_1.SchemaDifference.fromSchemas(input, source));
|
|
46
|
-
}
|
|
47
|
-
return this.mergeSchemas(input);
|
|
46
|
+
async merge(differenceResult) {
|
|
47
|
+
return this.mergeDifferences(differenceResult);
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* Merges the schema differences in the target schema. The target schema is defined
|
|
51
51
|
* in the given differences object.
|
|
52
|
-
* @param
|
|
53
|
-
* @returns
|
|
52
|
+
* @param differenceResult The differences between a source schema and the target schema.
|
|
53
|
+
* @returns The modified Schema.
|
|
54
54
|
*/
|
|
55
|
-
async
|
|
56
|
-
const targetSchemaKey = ecschema_metadata_1.SchemaKey.parseString(
|
|
57
|
-
const sourceSchemaKey = ecschema_metadata_1.SchemaKey.parseString(
|
|
58
|
-
if (
|
|
59
|
-
throw new Errors_1.SchemaConflictsError("Schema's can't be merged if there are unresolved conflicts.",
|
|
55
|
+
async mergeDifferences(differenceResult) {
|
|
56
|
+
const targetSchemaKey = ecschema_metadata_1.SchemaKey.parseString(differenceResult.targetSchemaName);
|
|
57
|
+
const sourceSchemaKey = ecschema_metadata_1.SchemaKey.parseString(differenceResult.sourceSchemaName);
|
|
58
|
+
if (differenceResult.conflicts && differenceResult.conflicts.length > 0) {
|
|
59
|
+
throw new Errors_1.SchemaConflictsError("Schema's can't be merged if there are unresolved conflicts.", differenceResult.conflicts, sourceSchemaKey, targetSchemaKey);
|
|
60
60
|
}
|
|
61
61
|
const schema = await this._editor.getSchema(targetSchemaKey);
|
|
62
62
|
if (schema === undefined) {
|
|
63
63
|
throw new Error(`The target schema '${targetSchemaKey.name}' could not be found in the editing context.`);
|
|
64
64
|
}
|
|
65
|
-
|
|
65
|
+
const { differences } = differenceResult;
|
|
66
|
+
if (differences === undefined || differences.length === 0) {
|
|
66
67
|
return schema;
|
|
67
68
|
}
|
|
68
69
|
const context = {
|
|
@@ -71,20 +72,20 @@ class SchemaMerger {
|
|
|
71
72
|
targetSchemaKey,
|
|
72
73
|
sourceSchemaKey,
|
|
73
74
|
};
|
|
74
|
-
for (const referenceChange of differences.
|
|
75
|
+
for (const referenceChange of differences.filter(Utils.isSchemaReferenceDifference)) {
|
|
75
76
|
await (0, SchemaReferenceMerger_1.mergeSchemaReferences)(context, referenceChange);
|
|
76
77
|
}
|
|
77
|
-
const schemaDifference = differences.
|
|
78
|
+
const schemaDifference = differences.find(Utils.isSchemaDifference);
|
|
78
79
|
if (schemaDifference !== undefined) {
|
|
79
80
|
await mergeSchemaProperties(schema, schemaDifference);
|
|
80
81
|
}
|
|
81
82
|
// Filter a list of possible schema item changes. This list gets filtered and order in the
|
|
82
83
|
// mergeSchemaItems method.
|
|
83
|
-
for await (const _mergeResult of (0, SchemaItemMerger_1.mergeSchemaItems)(context, differences
|
|
84
|
+
for await (const _mergeResult of (0, SchemaItemMerger_1.mergeSchemaItems)(context, differences)) {
|
|
84
85
|
}
|
|
85
86
|
// At last the custom attributes gets merged because it could be that the CustomAttributes
|
|
86
87
|
// depend on classes that has to get merged in as items before.
|
|
87
|
-
for (const customAttributeChange of differences.
|
|
88
|
+
for (const customAttributeChange of differences.filter(Utils.isCustomAttributeDifference)) {
|
|
88
89
|
await (0, CustomAttributeMerger_1.mergeCustomAttribute)(context, customAttributeChange);
|
|
89
90
|
}
|
|
90
91
|
return schema;
|
|
@@ -95,12 +96,12 @@ exports.SchemaMerger = SchemaMerger;
|
|
|
95
96
|
* Sets the editable properties of a Schema.
|
|
96
97
|
* @internal
|
|
97
98
|
*/
|
|
98
|
-
async function mergeSchemaProperties(schema,
|
|
99
|
-
if (
|
|
100
|
-
schema.setDisplayLabel(
|
|
99
|
+
async function mergeSchemaProperties(schema, { difference }) {
|
|
100
|
+
if (difference.label !== undefined) {
|
|
101
|
+
schema.setDisplayLabel(difference.label);
|
|
101
102
|
}
|
|
102
|
-
if (
|
|
103
|
-
schema.setDescription(
|
|
103
|
+
if (difference.description !== undefined) {
|
|
104
|
+
schema.setDescription(difference.description);
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
//# sourceMappingURL=SchemaMerger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,gEAAiF;AACjF,8CAAwD;AACxD,mDAA8D;AAC9D,
|
|
1
|
+
{"version":3,"file":"SchemaMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,gEAAiF;AACjF,8CAAwD;AACxD,mDAA8D;AAC9D,uEAAkH;AAClH,mEAA+D;AAC/D,yDAAsD;AACtD,mEAAgE;AAChE,+CAA+C;AAa/C;;;;GAIG;AACH,MAAa,YAAY;IAIvB;;;OAGG;IACH,YAAY,cAA6B;QACvC,IAAI,CAAC,OAAO,GAAG,IAAI,4BAAmB,CAAC,cAAc,CAAC,CAAC;IACzD,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,YAAY,CAAC,YAAoB,EAAE,YAAoB;QAClE,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,IAAA,uCAAoB,EAAC,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC;IAC5E,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,KAAK,CAAC,gBAAwC;QACzD,OAAO,IAAI,CAAC,gBAAgB,CAA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I,gBAAgB,KAAK,SAAS,EAAE,CAAC;YACnC,MAAM,qBAAqB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;QACxD,CAAC;QAED,0FAA0F;QAC1F,2BAA2B;QAC3B,IAAI,KAAK,EAAE,MAAM,YAAY,IAAI,IAAA,mCAAgB,EAAC,OAAO,EAAE,WAAW,CAAC,EAAE,CAAC;QAC1E,CAAC;QAED,0FAA0F;QAC1F,+DAA+D;QAC/D,KAAK,MAAM,qBAAqB,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,CAAC,EAAE,CAAC;YAC1F,MAAM,IAAA,4CAAoB,EAAC,OAAO,EAAE,qBAAqB,CAAC,CAAC;QAC7D,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAzFD,oCAyFC;AAED;;;GAGG;AACH,KAAK,UAAU,qBAAqB,CAAC,MAAqB,EAAE,EAAE,UAAU,EAAoB;IAC1F,IAAI,UAAU,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QACnC,MAAM,CAAC,eAAe,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,UAAU,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QACzC,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IAChD,CAAC;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 { MutableSchema } from \"../Editing/Mutable/MutableSchema\";\nimport { Schema, type SchemaContext, SchemaKey } from \"@itwin/ecschema-metadata\";\nimport { SchemaContextEditor } from \"../Editing/Editor\";\nimport { SchemaConflictsError } from \"../Differencing/Errors\";\nimport { getSchemaDifferences, SchemaDifference, SchemaDifferenceResult } from \"../Differencing/SchemaDifference\";\nimport { mergeCustomAttribute } from \"./CustomAttributeMerger\";\nimport { mergeSchemaItems } from \"./SchemaItemMerger\";\nimport { mergeSchemaReferences } from \"./SchemaReferenceMerger\";\nimport * as Utils from \"../Differencing/Utils\";\n\n/**\n * Defines the context of a Schema merging run.\n * @internal\n */\nexport interface SchemaMergeContext {\n readonly targetSchema: Schema;\n readonly targetSchemaKey: SchemaKey;\n readonly sourceSchemaKey: SchemaKey;\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 private readonly _editor: SchemaContextEditor;\n\n /**\n * Constructs a new instance of the SchemaMerger object.\n * @param editingContext The schema contexts that holds the schema to be edited.\n */\n constructor(editingContext: SchemaContext) {\n this._editor = new SchemaContextEditor(editingContext);\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 mergeSchemas(targetSchema: Schema, sourceSchema: Schema): Promise<Schema> {\n return this.merge(await getSchemaDifferences(targetSchema, sourceSchema));\n }\n\n /**\n * Merges the schema differences into the target schema context.\n * @param differenceResult The differences that shall be applied to the target schema.\n * @alpha\n */\n public async merge(differenceResult: SchemaDifferenceResult): Promise<Schema> {\n return this.mergeDifferences(differenceResult);\n }\n\n /**\n * Merges the schema differences in the target schema. The target schema is defined\n * in the given differences object.\n * @param differenceResult The differences between a source schema and the target schema.\n * @returns The modified Schema.\n */\n private async mergeDifferences(differenceResult: SchemaDifferenceResult): Promise<Schema> {\n const targetSchemaKey = SchemaKey.parseString(differenceResult.targetSchemaName);\n const sourceSchemaKey = SchemaKey.parseString(differenceResult.sourceSchemaName);\n\n if (differenceResult.conflicts && differenceResult.conflicts.length > 0) {\n throw new SchemaConflictsError(\n \"Schema's can't be merged if there are unresolved conflicts.\",\n differenceResult.conflicts,\n sourceSchemaKey,\n targetSchemaKey,\n );\n }\n\n const schema = await this._editor.getSchema(targetSchemaKey);\n if (schema === undefined) {\n throw new Error(`The target schema '${targetSchemaKey.name}' could not be found in the editing context.`);\n }\n\n const { differences } = differenceResult;\n if (differences === undefined || differences.length === 0) {\n return schema;\n }\n\n const context: SchemaMergeContext = {\n editor: this._editor,\n targetSchema: schema,\n targetSchemaKey,\n sourceSchemaKey,\n };\n\n for (const referenceChange of differences.filter(Utils.isSchemaReferenceDifference)) {\n await mergeSchemaReferences(context, referenceChange);\n }\n\n const schemaDifference = differences.find(Utils.isSchemaDifference);\n if (schemaDifference !== undefined) {\n await mergeSchemaProperties(schema, schemaDifference);\n }\n\n // Filter a list of possible schema item changes. This list gets filtered and order in the\n // mergeSchemaItems method.\n for await (const _mergeResult of mergeSchemaItems(context, differences)) {\n }\n\n // At last the custom attributes gets merged because it could be that the CustomAttributes\n // depend on classes that has to get merged in as items before.\n for (const customAttributeChange of differences.filter(Utils.isCustomAttributeDifference)) {\n await mergeCustomAttribute(context, customAttributeChange);\n }\n\n return schema;\n }\n}\n\n/**\n * Sets the editable properties of a Schema.\n * @internal\n */\nasync function mergeSchemaProperties(schema: MutableSchema, { difference }: SchemaDifference) {\n if (difference.label !== undefined) {\n schema.setDisplayLabel(difference.label);\n }\n if (difference.description !== undefined) {\n schema.setDescription(difference.description);\n }\n}\n"]}
|
|
@@ -13,10 +13,11 @@ export * from "./Editing/Editor";
|
|
|
13
13
|
export * from "./Editing/Exception";
|
|
14
14
|
export { ISuppressionRule, IRuleSuppressionSet, IRuleSuppressionMap } from "./Validation/RuleSuppressionSet";
|
|
15
15
|
export { SchemaValidater } from "./Validation/SchemaValidater";
|
|
16
|
-
export { SchemaMerger } from "./Merging/SchemaMerger";
|
|
17
16
|
export * from "./Differencing/SchemaDifference";
|
|
18
17
|
export * from "./Differencing/SchemaConflicts";
|
|
19
18
|
export * from "./Differencing/Errors";
|
|
19
|
+
export * from "./Differencing/Utils";
|
|
20
|
+
export { SchemaMerger } from "./Merging/SchemaMerger";
|
|
20
21
|
/** @docs-package-description
|
|
21
22
|
* The ecschema-editing package contains classes for validating, and editing ECSchemas that can be used in both [frontend]($docs/learning/frontend/index.md) and [backend]($docs/learning/backend/index.md).
|
|
22
23
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecschema-editing.d.ts","sourceRoot":"","sources":["../../src/ecschema-editing.ts"],"names":[],"mappings":"AAKA,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC/E,cAAc,wCAAwC,CAAC;AACvD,cAAc,oBAAoB,CAAC;AACnC,cAAc,sCAAsC,CAAC;AACrD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uCAAuC,CAAC;AACtD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oCAAoC,CAAC;AACnD,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC7G,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,
|
|
1
|
+
{"version":3,"file":"ecschema-editing.d.ts","sourceRoot":"","sources":["../../src/ecschema-editing.ts"],"names":[],"mappings":"AAKA,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC/E,cAAc,wCAAwC,CAAC;AACvD,cAAc,oBAAoB,CAAC;AACnC,cAAc,sCAAsC,CAAC;AACrD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uCAAuC,CAAC;AACtD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oCAAoC,CAAC;AACnD,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC7G,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD;;GAEG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG"}
|
|
@@ -38,11 +38,12 @@ __exportStar(require("./Editing/Editor"), exports);
|
|
|
38
38
|
__exportStar(require("./Editing/Exception"), exports);
|
|
39
39
|
var SchemaValidater_1 = require("./Validation/SchemaValidater");
|
|
40
40
|
Object.defineProperty(exports, "SchemaValidater", { enumerable: true, get: function () { return SchemaValidater_1.SchemaValidater; } });
|
|
41
|
-
var SchemaMerger_1 = require("./Merging/SchemaMerger");
|
|
42
|
-
Object.defineProperty(exports, "SchemaMerger", { enumerable: true, get: function () { return SchemaMerger_1.SchemaMerger; } });
|
|
43
41
|
__exportStar(require("./Differencing/SchemaDifference"), exports);
|
|
44
42
|
__exportStar(require("./Differencing/SchemaConflicts"), exports);
|
|
45
43
|
__exportStar(require("./Differencing/Errors"), exports);
|
|
44
|
+
__exportStar(require("./Differencing/Utils"), exports);
|
|
45
|
+
var SchemaMerger_1 = require("./Merging/SchemaMerger");
|
|
46
|
+
Object.defineProperty(exports, "SchemaMerger", { enumerable: true, get: function () { return SchemaMerger_1.SchemaMerger; } });
|
|
46
47
|
/** @docs-package-description
|
|
47
48
|
* The ecschema-editing package contains classes for validating, and editing ECSchemas that can be used in both [frontend]($docs/learning/frontend/index.md) and [backend]($docs/learning/backend/index.md).
|
|
48
49
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecschema-editing.js","sourceRoot":"","sources":["../../src/ecschema-editing.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;;;;;AAE/F,0DAAwC;AACxC,kEAAgD;AAChD,sDAAsD;AACtD,gDAA+E;AAAtE,0GAAA,eAAe,OAAA;AAAE,sGAAA,WAAW,OAAA;AAAE,oGAAA,SAAS,OAAA;AAChD,yEAAuD;AACvD,qDAAmC;AACnC,uEAAqD;AACrD,4DAA0C;AAC1C,wEAAsD;AACtD,6DAA2C;AAC3C,8DAA4C;AAC5C,qEAAmD;AACnD,mDAAiC;AACjC,sDAAoC;AAEpC,gEAA+D;AAAtD,kHAAA,eAAe,OAAA;AACxB,
|
|
1
|
+
{"version":3,"file":"ecschema-editing.js","sourceRoot":"","sources":["../../src/ecschema-editing.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;;;;;AAE/F,0DAAwC;AACxC,kEAAgD;AAChD,sDAAsD;AACtD,gDAA+E;AAAtE,0GAAA,eAAe,OAAA;AAAE,sGAAA,WAAW,OAAA;AAAE,oGAAA,SAAS,OAAA;AAChD,yEAAuD;AACvD,qDAAmC;AACnC,uEAAqD;AACrD,4DAA0C;AAC1C,wEAAsD;AACtD,6DAA2C;AAC3C,8DAA4C;AAC5C,qEAAmD;AACnD,mDAAiC;AACjC,sDAAoC;AAEpC,gEAA+D;AAAtD,kHAAA,eAAe,OAAA;AACxB,kEAAgD;AAChD,iEAA+C;AAC/C,wDAAsC;AACtC,uDAAqC;AACrC,uDAAsD;AAA7C,4GAAA,YAAY,OAAA;AAErB;;GAEG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG","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\nexport * from \"./Validation/Diagnostic\";\nexport * from \"./Validation/DiagnosticReporter\";\n/* eslint-disable-next-line deprecation/deprecation */\nexport { DiagnosticCodes, Diagnostics, ECRuleSet } from \"./Validation/ECRules\";\nexport * from \"./Validation/LoggingDiagnosticReporter\";\nexport * from \"./Validation/Rules\";\nexport * from \"./Validation/SchemaValidationVisitor\";\nexport * from \"./Validation/SchemaWalker\";\nexport * from \"./Validation/SchemaCompareDiagnostics\";\nexport * from \"./Validation/SchemaChanges\";\nexport * from \"./Validation/SchemaComparer\";\nexport * from \"./Validation/SchemaCompareReporter\";\nexport * from \"./Editing/Editor\";\nexport * from \"./Editing/Exception\";\nexport { ISuppressionRule, IRuleSuppressionSet, IRuleSuppressionMap } from \"./Validation/RuleSuppressionSet\";\nexport { SchemaValidater } from \"./Validation/SchemaValidater\";\nexport * from \"./Differencing/SchemaDifference\";\nexport * from \"./Differencing/SchemaConflicts\";\nexport * from \"./Differencing/Errors\";\nexport * from \"./Differencing/Utils\";\nexport { SchemaMerger } from \"./Merging/SchemaMerger\";\n\n/** @docs-package-description\n * The ecschema-editing package contains classes for validating, and editing ECSchemas that can be used in both [frontend]($docs/learning/frontend/index.md) and [backend]($docs/learning/backend/index.md).\n */\n/**\n * @docs-group-description Editing\n * Set of classes used to perform editing of ECSchemas.\n */\n/**\n * @docs-group-description Diagnostic\n * Set of classes to categorize and manage ECSchema validation results.\n */\n/**\n * @docs-group-description Validation\n * Set of classes used to perform validation on ECSchemas.\n */\n/**\n * @docs-group-description Comparison\n * Set of classes to enable comparison of ECSchemas.\n */\n/**\n * @docs-group-description Merging\n * Set of classes used to merge schemas.\n */\n/**\n * @docs-group-description Differencing\n * Set of classes used to perform differences between ECSchemas.\n */\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/ecschema-editing",
|
|
3
|
-
"version": "4.8.0-dev.
|
|
3
|
+
"version": "4.8.0-dev.9",
|
|
4
4
|
"description": "ECSchema editing and validation API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/cjs/ecschema-editing.js",
|
|
@@ -42,16 +42,16 @@
|
|
|
42
42
|
"rimraf": "^3.0.2",
|
|
43
43
|
"sinon": "^17.0.1",
|
|
44
44
|
"typescript": "~5.3.3",
|
|
45
|
-
"@itwin/
|
|
46
|
-
"@itwin/
|
|
47
|
-
"@itwin/core-
|
|
48
|
-
"@itwin/
|
|
49
|
-
"@itwin/core-
|
|
45
|
+
"@itwin/build-tools": "4.8.0-dev.9",
|
|
46
|
+
"@itwin/core-common": "4.8.0-dev.9",
|
|
47
|
+
"@itwin/core-quantity": "4.8.0-dev.9",
|
|
48
|
+
"@itwin/ecschema-metadata": "4.8.0-dev.9",
|
|
49
|
+
"@itwin/core-bentley": "4.8.0-dev.9"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@itwin/core-bentley": "^4.8.0-dev.
|
|
53
|
-
"@itwin/core-quantity": "^4.8.0-dev.
|
|
54
|
-
"@itwin/ecschema-metadata": "^4.8.0-dev.
|
|
52
|
+
"@itwin/core-bentley": "^4.8.0-dev.9",
|
|
53
|
+
"@itwin/core-quantity": "^4.8.0-dev.9",
|
|
54
|
+
"@itwin/ecschema-metadata": "^4.8.0-dev.9"
|
|
55
55
|
},
|
|
56
56
|
"nyc": {
|
|
57
57
|
"extends": "./node_modules/@itwin/build-tools/.nycrc"
|