@itwin/ecschema-editing 4.8.0-dev.37 → 4.8.0-dev.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -1
- package/lib/cjs/Differencing/SchemaConflicts.d.ts +2 -0
- package/lib/cjs/Differencing/SchemaConflicts.d.ts.map +1 -1
- package/lib/cjs/Differencing/SchemaConflicts.js.map +1 -1
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.d.ts.map +1 -1
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js +2 -0
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js.map +1 -1
- package/lib/cjs/Differencing/Utils.d.ts +11 -1
- package/lib/cjs/Differencing/Utils.d.ts.map +1 -1
- package/lib/cjs/Differencing/Utils.js +21 -1
- package/lib/cjs/Differencing/Utils.js.map +1 -1
- package/lib/cjs/Merging/Edits/RenameEditHandler.d.ts +14 -0
- package/lib/cjs/Merging/Edits/RenameEditHandler.d.ts.map +1 -0
- package/lib/cjs/Merging/Edits/RenameEditHandler.js +344 -0
- package/lib/cjs/Merging/Edits/RenameEditHandler.js.map +1 -0
- package/lib/cjs/Merging/Edits/SchemaEdits.d.ts +78 -0
- package/lib/cjs/Merging/Edits/SchemaEdits.d.ts.map +1 -0
- package/lib/cjs/Merging/Edits/SchemaEdits.js +111 -0
- package/lib/cjs/Merging/Edits/SchemaEdits.js.map +1 -0
- package/lib/cjs/Merging/Edits/SkipEditHandler.d.ts +14 -0
- package/lib/cjs/Merging/Edits/SkipEditHandler.d.ts.map +1 -0
- package/lib/cjs/Merging/Edits/SkipEditHandler.js +60 -0
- package/lib/cjs/Merging/Edits/SkipEditHandler.js.map +1 -0
- package/lib/cjs/Merging/SchemaMerger.d.ts +9 -12
- package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.js +40 -37
- package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
- package/lib/cjs/ecschema-editing.d.ts +1 -0
- package/lib/cjs/ecschema-editing.d.ts.map +1 -1
- package/lib/cjs/ecschema-editing.js +1 -0
- package/lib/cjs/ecschema-editing.js.map +1 -1
- package/package.json +9 -9
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module Merging
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.applySkipEdit = void 0;
|
|
11
|
+
/**
|
|
12
|
+
* Applies a skip edit to the schema differences. It basically removes all entries that
|
|
13
|
+
* that are associated with the item to skip.
|
|
14
|
+
* @param result The result of a schema differencing run
|
|
15
|
+
* @param edit The skip edit to be applied.
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
function applySkipEdit(result, edit) {
|
|
19
|
+
const [itemName, pathName] = edit.key.split(".");
|
|
20
|
+
const foundIndices = pathName !== undefined
|
|
21
|
+
? findRelatedItemEntries(result, itemName, pathName)
|
|
22
|
+
: findItemEntries(result, itemName);
|
|
23
|
+
for (const index of foundIndices.reverse()) {
|
|
24
|
+
result.differences.splice(index, 1);
|
|
25
|
+
}
|
|
26
|
+
if (result.conflicts) {
|
|
27
|
+
removeRelatedConflicts(result.conflicts, itemName, pathName);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.applySkipEdit = applySkipEdit;
|
|
31
|
+
function removeRelatedConflicts(conflicts, itemName, path) {
|
|
32
|
+
const indices = [];
|
|
33
|
+
conflicts.forEach((conflict, index) => {
|
|
34
|
+
if (conflict.itemName === itemName && conflict.path === path) {
|
|
35
|
+
indices.push(index);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
for (const index of indices.reverse()) {
|
|
39
|
+
conflicts.splice(index, 1);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function findItemEntries({ differences }, itemName) {
|
|
43
|
+
const found = [];
|
|
44
|
+
differences.forEach((difference, index) => {
|
|
45
|
+
if ("itemName" in difference && difference.itemName === itemName) {
|
|
46
|
+
found.push(index);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return found;
|
|
50
|
+
}
|
|
51
|
+
function findRelatedItemEntries({ differences }, itemName, pathName) {
|
|
52
|
+
const found = [];
|
|
53
|
+
differences.forEach((difference, index) => {
|
|
54
|
+
if ("itemName" in difference && difference.itemName === itemName && "path" in difference && difference.path === pathName) {
|
|
55
|
+
found.push(index);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return found;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=SkipEditHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SkipEditHandler.js","sourceRoot":"","sources":["../../../../src/Merging/Edits/SkipEditHandler.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAMH;;;;;;GAMG;AACH,SAAgB,aAAa,CAAC,MAA8B,EAAE,IAAc;IAC1E,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAiC,CAAC;IACjF,MAAM,YAAY,GAAG,QAAQ,KAAK,SAAS;QACzC,CAAC,CAAC,sBAAsB,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC;QACpD,CAAC,CAAC,eAAe,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAEtC,KAAK,MAAM,KAAK,IAAI,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC;QAC3C,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACtC,CAAC;IAED,IAAI,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Q,IAAI,MAAM,IAAI,UAAU,IAAI,UAAU,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACzH,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,KAAK,CAAC;AACf,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 type { SchemaDifferenceResult } from \"../../Differencing/SchemaDifference\";\nimport type { SchemaDifferenceConflict } from \"../../ecschema-editing\";\nimport type { SkipEdit } from \"./SchemaEdits\";\n\n/**\n * Applies a skip edit to the schema differences. It basically removes all entries that\n * that are associated with the item to skip.\n * @param result The result of a schema differencing run\n * @param edit The skip edit to be applied.\n * @internal\n */\nexport function applySkipEdit(result: SchemaDifferenceResult, edit: SkipEdit) {\n const [itemName, pathName] = edit.key.split(\".\") as [string, string | undefined];\n const foundIndices = pathName !== undefined\n ? findRelatedItemEntries(result, itemName, pathName)\n : findItemEntries(result, itemName);\n\n for (const index of foundIndices.reverse()) {\n result.differences.splice(index, 1);\n }\n\n if (result.conflicts) {\n removeRelatedConflicts(result.conflicts, itemName, pathName);\n }\n}\n\nfunction removeRelatedConflicts(conflicts: SchemaDifferenceConflict[], itemName: string, path?: string) {\n const indices: number[] = [];\n conflicts.forEach((conflict, index) => {\n if (conflict.itemName === itemName && conflict.path === path) {\n indices.push(index);\n }\n });\n\n for (const index of indices.reverse()) {\n conflicts.splice(index, 1);\n }\n}\n\nfunction findItemEntries({ differences }: SchemaDifferenceResult, itemName: string): number[] {\n const found: number[] = [];\n differences.forEach((difference, index) => {\n if (\"itemName\" in difference && difference.itemName === itemName) {\n found.push(index);\n }\n });\n return found;\n}\n\nfunction findRelatedItemEntries({ differences }: SchemaDifferenceResult, itemName: string, pathName: string): number[] {\n const found: number[] = [];\n differences.forEach((difference, index) => {\n if (\"itemName\" in difference && difference.itemName === itemName && \"path\" in difference && difference.path === pathName) {\n found.push(index);\n }\n });\n return found;\n}\n\n"]}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Schema, type SchemaContext, SchemaKey } from "@itwin/ecschema-metadata";
|
|
5
5
|
import { SchemaContextEditor } from "../Editing/Editor";
|
|
6
|
-
import { SchemaDifferenceResult } from "../Differencing/SchemaDifference";
|
|
6
|
+
import { type SchemaDifferenceResult } from "../Differencing/SchemaDifference";
|
|
7
|
+
import { type SchemaEdits } from "./Edits/SchemaEdits";
|
|
7
8
|
/**
|
|
8
9
|
* Defines the context of a Schema merging run.
|
|
9
10
|
* @internal
|
|
@@ -16,7 +17,7 @@ export interface SchemaMergeContext {
|
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
* Class to merge two schemas together.
|
|
19
|
-
* @see [[merge]] to merge
|
|
20
|
+
* @see [[merge]] or [[mergeSchemas]] to merge two schemas together.
|
|
20
21
|
* @beta
|
|
21
22
|
*/
|
|
22
23
|
export declare class SchemaMerger {
|
|
@@ -30,21 +31,17 @@ export declare class SchemaMerger {
|
|
|
30
31
|
* Copy the SchemaItems of the source schemas to the target schema.
|
|
31
32
|
* @param targetSchema The schema the SchemaItems gets merged to.
|
|
32
33
|
* @param sourceSchema The schema the SchemaItems gets copied from.
|
|
34
|
+
* @param edits An optional instance of schema edits that shall be applied before the schemas get merged.
|
|
33
35
|
* @returns The merged target schema.
|
|
36
|
+
* @alpha
|
|
34
37
|
*/
|
|
35
|
-
mergeSchemas(targetSchema: Schema, sourceSchema: Schema): Promise<Schema>;
|
|
38
|
+
mergeSchemas(targetSchema: Schema, sourceSchema: Schema, edits?: SchemaEdits): Promise<Schema>;
|
|
36
39
|
/**
|
|
37
40
|
* Merges the schema differences into the target schema context.
|
|
38
|
-
* @param differenceResult
|
|
41
|
+
* @param differenceResult The differences that shall be applied to the target schema.
|
|
42
|
+
* @param edits An optional instance of schema edits that shall be applied before the schemas get merged.
|
|
39
43
|
* @alpha
|
|
40
44
|
*/
|
|
41
|
-
merge(differenceResult: SchemaDifferenceResult): Promise<Schema>;
|
|
42
|
-
/**
|
|
43
|
-
* Merges the schema differences in the target schema. The target schema is defined
|
|
44
|
-
* in the given differences object.
|
|
45
|
-
* @param differenceResult The differences between a source schema and the target schema.
|
|
46
|
-
* @returns The modified Schema.
|
|
47
|
-
*/
|
|
48
|
-
private mergeDifferences;
|
|
45
|
+
merge(differenceResult: SchemaDifferenceResult, edits?: SchemaEdits): Promise<Schema>;
|
|
49
46
|
}
|
|
50
47
|
//# sourceMappingURL=SchemaMerger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":"AAIA;;GAEG;
|
|
1
|
+
{"version":3,"file":"SchemaMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAyE,KAAK,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AACtJ,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAMvD;;;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;;;;;;;OAOG;IACU,YAAY,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAI3G;;;;;OAKG;IACU,KAAK,CAAC,gBAAgB,EAAE,sBAAsB,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;CAmCnG"}
|
|
@@ -18,7 +18,7 @@ const SchemaReferenceMerger_1 = require("./SchemaReferenceMerger");
|
|
|
18
18
|
const Utils = require("../Differencing/Utils");
|
|
19
19
|
/**
|
|
20
20
|
* Class to merge two schemas together.
|
|
21
|
-
* @see [[merge]] to merge
|
|
21
|
+
* @see [[merge]] or [[mergeSchemas]] to merge two schemas together.
|
|
22
22
|
* @beta
|
|
23
23
|
*/
|
|
24
24
|
class SchemaMerger {
|
|
@@ -33,28 +33,27 @@ class SchemaMerger {
|
|
|
33
33
|
* Copy the SchemaItems of the source schemas to the target schema.
|
|
34
34
|
* @param targetSchema The schema the SchemaItems gets merged to.
|
|
35
35
|
* @param sourceSchema The schema the SchemaItems gets copied from.
|
|
36
|
+
* @param edits An optional instance of schema edits that shall be applied before the schemas get merged.
|
|
36
37
|
* @returns The merged target schema.
|
|
38
|
+
* @alpha
|
|
37
39
|
*/
|
|
38
|
-
async mergeSchemas(targetSchema, sourceSchema) {
|
|
39
|
-
return this.merge(await (0, SchemaDifference_1.getSchemaDifferences)(targetSchema, sourceSchema));
|
|
40
|
+
async mergeSchemas(targetSchema, sourceSchema, edits) {
|
|
41
|
+
return this.merge(await (0, SchemaDifference_1.getSchemaDifferences)(targetSchema, sourceSchema), edits);
|
|
40
42
|
}
|
|
41
43
|
/**
|
|
42
44
|
* Merges the schema differences into the target schema context.
|
|
43
|
-
* @param differenceResult
|
|
45
|
+
* @param differenceResult The differences that shall be applied to the target schema.
|
|
46
|
+
* @param edits An optional instance of schema edits that shall be applied before the schemas get merged.
|
|
44
47
|
* @alpha
|
|
45
48
|
*/
|
|
46
|
-
async merge(differenceResult) {
|
|
47
|
-
return this.mergeDifferences(differenceResult);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Merges the schema differences in the target schema. The target schema is defined
|
|
51
|
-
* in the given differences object.
|
|
52
|
-
* @param differenceResult The differences between a source schema and the target schema.
|
|
53
|
-
* @returns The modified Schema.
|
|
54
|
-
*/
|
|
55
|
-
async mergeDifferences(differenceResult) {
|
|
49
|
+
async merge(differenceResult, edits) {
|
|
56
50
|
const targetSchemaKey = ecschema_metadata_1.SchemaKey.parseString(differenceResult.targetSchemaName);
|
|
57
51
|
const sourceSchemaKey = ecschema_metadata_1.SchemaKey.parseString(differenceResult.sourceSchemaName);
|
|
52
|
+
// If schema changes were provided, they'll get applied and a new SchemaDifferenceResult is returned
|
|
53
|
+
// to prevent altering the differenceResult the caller passed in.
|
|
54
|
+
if (edits) {
|
|
55
|
+
await edits.applyTo(differenceResult = { ...differenceResult });
|
|
56
|
+
}
|
|
58
57
|
if (differenceResult.conflicts && differenceResult.conflicts.length > 0) {
|
|
59
58
|
throw new Errors_1.SchemaConflictsError("Schema's can't be merged if there are unresolved conflicts.", differenceResult.conflicts, sourceSchemaKey, targetSchemaKey);
|
|
60
59
|
}
|
|
@@ -62,46 +61,50 @@ class SchemaMerger {
|
|
|
62
61
|
if (schema === undefined) {
|
|
63
62
|
throw new Error(`The target schema '${targetSchemaKey.name}' could not be found in the editing context.`);
|
|
64
63
|
}
|
|
65
|
-
const { differences } = differenceResult;
|
|
66
|
-
if (differences === undefined || differences.length === 0) {
|
|
67
|
-
return schema;
|
|
68
|
-
}
|
|
69
64
|
const context = {
|
|
70
65
|
editor: this._editor,
|
|
71
66
|
targetSchema: schema,
|
|
72
67
|
targetSchemaKey,
|
|
73
68
|
sourceSchemaKey,
|
|
74
69
|
};
|
|
75
|
-
|
|
76
|
-
await (0, SchemaReferenceMerger_1.mergeSchemaReferences)(context, referenceChange);
|
|
77
|
-
}
|
|
78
|
-
const schemaDifference = differences.find(Utils.isSchemaDifference);
|
|
79
|
-
if (schemaDifference !== undefined) {
|
|
80
|
-
await mergeSchemaProperties(schema, schemaDifference);
|
|
81
|
-
}
|
|
82
|
-
// Filter a list of possible schema item changes. This list gets filtered and order in the
|
|
83
|
-
// mergeSchemaItems method.
|
|
84
|
-
for await (const _mergeResult of (0, SchemaItemMerger_1.mergeSchemaItems)(context, differences)) {
|
|
85
|
-
}
|
|
86
|
-
// At last the custom attributes gets merged because it could be that the CustomAttributes
|
|
87
|
-
// depend on classes that has to get merged in as items before.
|
|
88
|
-
for (const customAttributeChange of differences.filter(Utils.isCustomAttributeDifference)) {
|
|
89
|
-
await (0, CustomAttributeMerger_1.mergeCustomAttribute)(context, customAttributeChange);
|
|
90
|
-
}
|
|
70
|
+
await mergeSchemaDifferences(context, differenceResult.differences);
|
|
91
71
|
return schema;
|
|
92
72
|
}
|
|
93
73
|
}
|
|
94
74
|
exports.SchemaMerger = SchemaMerger;
|
|
75
|
+
/**
|
|
76
|
+
* Merges the schema differences in the target schema.
|
|
77
|
+
* @param context The current merging context.
|
|
78
|
+
* @param differences The differences between a source schema and the target schema.
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
async function mergeSchemaDifferences(context, differences) {
|
|
82
|
+
for (const referenceDifference of differences.filter(Utils.isSchemaReferenceDifference)) {
|
|
83
|
+
await (0, SchemaReferenceMerger_1.mergeSchemaReferences)(context, referenceDifference);
|
|
84
|
+
}
|
|
85
|
+
for (const schemaDifference of differences.filter(Utils.isSchemaDifference)) {
|
|
86
|
+
await mergeSchemaProperties(context, schemaDifference);
|
|
87
|
+
}
|
|
88
|
+
// Filter a list of possible schema item changes. This list gets filtered and order in the
|
|
89
|
+
// mergeSchemaItems method.
|
|
90
|
+
for await (const _mergeResult of (0, SchemaItemMerger_1.mergeSchemaItems)(context, differences)) {
|
|
91
|
+
}
|
|
92
|
+
// At last the custom attributes gets merged because it could be that the CustomAttributes
|
|
93
|
+
// depend on classes that has to get merged in as items before.
|
|
94
|
+
for (const customAttributeDifference of differences.filter(Utils.isCustomAttributeDifference)) {
|
|
95
|
+
await (0, CustomAttributeMerger_1.mergeCustomAttribute)(context, customAttributeDifference);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
95
98
|
/**
|
|
96
99
|
* Sets the editable properties of a Schema.
|
|
97
100
|
* @internal
|
|
98
101
|
*/
|
|
99
|
-
async function mergeSchemaProperties(
|
|
102
|
+
async function mergeSchemaProperties(context, { difference }) {
|
|
100
103
|
if (difference.label !== undefined) {
|
|
101
|
-
|
|
104
|
+
await context.editor.setDisplayLabel(context.targetSchemaKey, difference.label);
|
|
102
105
|
}
|
|
103
106
|
if (difference.description !== undefined) {
|
|
104
|
-
|
|
107
|
+
await context.editor.setDescription(context.targetSchemaKey, difference.description);
|
|
105
108
|
}
|
|
106
109
|
}
|
|
107
110
|
//# 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;;;
|
|
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,CAAC,OAAO,GAAG,IAAI,4BAAmB,CAAC,cAAc,CAAC,CAAC;IACzD,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,YAAY,CAAC,YAAoB,EAAE,YAAoB,EAAE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U,sBAAsB,CAAC,OAA2B,EAAE,WAAkC;IACnG,KAAK,MAAM,mBAAmB,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,CAAC,EAAE,CAAC;QACxF,MAAM,IAAA,6CAAqB,EAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,MAAM,gBAAgB,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAC5E,MAAM,qBAAqB,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;IACzD,CAAC;IAED,0FAA0F;IAC1F,2BAA2B;IAC3B,IAAI,KAAK,EAAE,MAAM,YAAY,IAAI,IAAA,mCAAgB,EAAC,OAAO,EAAE,WAAW,CAAC,EAAE,CAAC;IAC1E,CAAC;IAED,0FAA0F;IAC1F,+DAA+D;IAC/D,KAAK,MAAM,yBAAyB,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,CAAC,EAAE,CAAC;QAC9F,MAAM,IAAA,4CAAoB,EAAC,OAAO,EAAE,yBAAyB,CAAC,CAAC;IACjE,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,qBAAqB,CAAC,OAA2B,EAAE,EAAE,UAAU,EAAoB;IAChG,IAAI,UAAU,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QACnC,MAAM,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,eAAe,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IAClF,CAAC;IACD,IAAI,UAAU,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QACzC,MAAM,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,eAAe,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IACvF,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 { Schema, type SchemaContext, SchemaKey } from \"@itwin/ecschema-metadata\";\nimport { SchemaContextEditor } from \"../Editing/Editor\";\nimport { SchemaConflictsError } from \"../Differencing/Errors\";\nimport { type AnySchemaDifference, getSchemaDifferences, type SchemaDifference, type SchemaDifferenceResult } from \"../Differencing/SchemaDifference\";\nimport { type SchemaEdits } from \"./Edits/SchemaEdits\";\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]] or [[mergeSchemas]] to merge two schemas together.\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 * @param edits An optional instance of schema edits that shall be applied before the schemas get merged.\n * @returns The merged target schema.\n * @alpha\n */\n public async mergeSchemas(targetSchema: Schema, sourceSchema: Schema, edits?: SchemaEdits): Promise<Schema> {\n return this.merge(await getSchemaDifferences(targetSchema, sourceSchema), edits);\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 * @param edits An optional instance of schema edits that shall be applied before the schemas get merged.\n * @alpha\n */\n public async merge(differenceResult: SchemaDifferenceResult, edits?: SchemaEdits): Promise<Schema> {\n const targetSchemaKey = SchemaKey.parseString(differenceResult.targetSchemaName);\n const sourceSchemaKey = SchemaKey.parseString(differenceResult.sourceSchemaName);\n\n // If schema changes were provided, they'll get applied and a new SchemaDifferenceResult is returned\n // to prevent altering the differenceResult the caller passed in.\n if (edits) {\n await edits.applyTo(differenceResult = { ...differenceResult });\n }\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 context: SchemaMergeContext = {\n editor: this._editor,\n targetSchema: schema,\n targetSchemaKey,\n sourceSchemaKey,\n };\n\n await mergeSchemaDifferences(context, differenceResult.differences);\n\n return schema;\n }\n}\n\n/**\n * Merges the schema differences in the target schema.\n * @param context The current merging context.\n * @param differences The differences between a source schema and the target schema.\n * @internal\n */\nasync function mergeSchemaDifferences(context: SchemaMergeContext, differences: AnySchemaDifference[]): Promise<void> {\n for (const referenceDifference of differences.filter(Utils.isSchemaReferenceDifference)) {\n await mergeSchemaReferences(context, referenceDifference);\n }\n\n for (const schemaDifference of differences.filter(Utils.isSchemaDifference)) {\n await mergeSchemaProperties(context, 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 customAttributeDifference of differences.filter(Utils.isCustomAttributeDifference)) {\n await mergeCustomAttribute(context, customAttributeDifference);\n }\n}\n\n/**\n * Sets the editable properties of a Schema.\n * @internal\n */\nasync function mergeSchemaProperties(context: SchemaMergeContext, { difference }: SchemaDifference) {\n if (difference.label !== undefined) {\n await context.editor.setDisplayLabel(context.targetSchemaKey, difference.label);\n }\n if (difference.description !== undefined) {\n await context.editor.setDescription(context.targetSchemaKey, difference.description);\n }\n}\n"]}
|
|
@@ -18,6 +18,7 @@ export * from "./Differencing/SchemaConflicts";
|
|
|
18
18
|
export * from "./Differencing/Errors";
|
|
19
19
|
export * from "./Differencing/Utils";
|
|
20
20
|
export { SchemaMerger } from "./Merging/SchemaMerger";
|
|
21
|
+
export * from "./Merging/Edits/SchemaEdits";
|
|
21
22
|
/** @docs-package-description
|
|
22
23
|
* 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).
|
|
23
24
|
*/
|
|
@@ -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,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;
|
|
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;AACtD,cAAc,6BAA6B,CAAC;AAE5C;;GAEG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG"}
|
|
@@ -44,6 +44,7 @@ __exportStar(require("./Differencing/Errors"), exports);
|
|
|
44
44
|
__exportStar(require("./Differencing/Utils"), exports);
|
|
45
45
|
var SchemaMerger_1 = require("./Merging/SchemaMerger");
|
|
46
46
|
Object.defineProperty(exports, "SchemaMerger", { enumerable: true, get: function () { return SchemaMerger_1.SchemaMerger; } });
|
|
47
|
+
__exportStar(require("./Merging/Edits/SchemaEdits"), exports);
|
|
47
48
|
/** @docs-package-description
|
|
48
49
|
* 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).
|
|
49
50
|
*/
|
|
@@ -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,kEAAgD;AAChD,iEAA+C;AAC/C,wDAAsC;AACtC,uDAAqC;AACrC,uDAAsD;AAA7C,4GAAA,YAAY,OAAA;
|
|
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;AACrB,8DAA4C;AAE5C;;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\";\nexport * from \"./Merging/Edits/SchemaEdits\";\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.38",
|
|
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/core-quantity": "4.8.0-dev.
|
|
49
|
-
"@itwin/ecschema-metadata": "4.8.0-dev.
|
|
45
|
+
"@itwin/build-tools": "4.8.0-dev.38",
|
|
46
|
+
"@itwin/core-bentley": "4.8.0-dev.38",
|
|
47
|
+
"@itwin/core-common": "4.8.0-dev.38",
|
|
48
|
+
"@itwin/core-quantity": "4.8.0-dev.38",
|
|
49
|
+
"@itwin/ecschema-metadata": "4.8.0-dev.38"
|
|
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.38",
|
|
53
|
+
"@itwin/core-quantity": "^4.8.0-dev.38",
|
|
54
|
+
"@itwin/ecschema-metadata": "^4.8.0-dev.38"
|
|
55
55
|
},
|
|
56
56
|
"nyc": {
|
|
57
57
|
"extends": "./node_modules/@itwin/build-tools/.nycrc"
|