@itwin/ecschema-editing 4.7.0-dev.9 → 4.8.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -1
- package/lib/cjs/Editing/Constants.d.ts +6 -6
- package/lib/cjs/Editing/Constants.d.ts.map +1 -1
- package/lib/cjs/Editing/Constants.js +26 -31
- package/lib/cjs/Editing/Constants.js.map +1 -1
- package/lib/cjs/Editing/CustomAttributes.d.ts +3 -3
- package/lib/cjs/Editing/CustomAttributes.d.ts.map +1 -1
- package/lib/cjs/Editing/CustomAttributes.js +18 -28
- package/lib/cjs/Editing/CustomAttributes.js.map +1 -1
- package/lib/cjs/Editing/ECClasses.d.ts +24 -23
- package/lib/cjs/Editing/ECClasses.d.ts.map +1 -1
- package/lib/cjs/Editing/ECClasses.js +126 -156
- package/lib/cjs/Editing/ECClasses.js.map +1 -1
- package/lib/cjs/Editing/Editor.d.ts +10 -31
- package/lib/cjs/Editing/Editor.d.ts.map +1 -1
- package/lib/cjs/Editing/Editor.js +59 -43
- package/lib/cjs/Editing/Editor.js.map +1 -1
- package/lib/cjs/Editing/Entities.d.ts +9 -9
- package/lib/cjs/Editing/Entities.d.ts.map +1 -1
- package/lib/cjs/Editing/Entities.js +65 -85
- package/lib/cjs/Editing/Entities.js.map +1 -1
- package/lib/cjs/Editing/Enumerations.d.ts +6 -6
- package/lib/cjs/Editing/Enumerations.d.ts.map +1 -1
- package/lib/cjs/Editing/Enumerations.js +57 -55
- package/lib/cjs/Editing/Enumerations.js.map +1 -1
- package/lib/cjs/Editing/Exception.d.ts +257 -0
- package/lib/cjs/Editing/Exception.d.ts.map +1 -0
- package/lib/cjs/Editing/Exception.js +426 -0
- package/lib/cjs/Editing/Exception.js.map +1 -0
- package/lib/cjs/Editing/Formats.d.ts +6 -6
- package/lib/cjs/Editing/Formats.d.ts.map +1 -1
- package/lib/cjs/Editing/Formats.js +28 -33
- package/lib/cjs/Editing/Formats.js.map +1 -1
- package/lib/cjs/Editing/InvertedUnits.d.ts +6 -6
- package/lib/cjs/Editing/InvertedUnits.d.ts.map +1 -1
- package/lib/cjs/Editing/InvertedUnits.js +41 -56
- package/lib/cjs/Editing/InvertedUnits.js.map +1 -1
- package/lib/cjs/Editing/KindOfQuantities.d.ts +6 -6
- package/lib/cjs/Editing/KindOfQuantities.d.ts.map +1 -1
- package/lib/cjs/Editing/KindOfQuantities.js +50 -57
- package/lib/cjs/Editing/KindOfQuantities.js.map +1 -1
- package/lib/cjs/Editing/Mixins.d.ts +5 -5
- package/lib/cjs/Editing/Mixins.d.ts.map +1 -1
- package/lib/cjs/Editing/Mixins.js +43 -58
- package/lib/cjs/Editing/Mixins.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableEntityClass.d.ts +1 -5
- package/lib/cjs/Editing/Mutable/MutableEntityClass.d.ts.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableEntityClass.js +1 -45
- package/lib/cjs/Editing/Mutable/MutableEntityClass.js.map +1 -1
- package/lib/cjs/Editing/Phenomena.d.ts +7 -7
- package/lib/cjs/Editing/Phenomena.d.ts.map +1 -1
- package/lib/cjs/Editing/Phenomena.js +23 -23
- package/lib/cjs/Editing/Phenomena.js.map +1 -1
- package/lib/cjs/Editing/Properties.d.ts +7 -6
- package/lib/cjs/Editing/Properties.d.ts.map +1 -1
- package/lib/cjs/Editing/Properties.js +99 -46
- package/lib/cjs/Editing/Properties.js.map +1 -1
- package/lib/cjs/Editing/PropertyCategories.d.ts +6 -6
- package/lib/cjs/Editing/PropertyCategories.d.ts.map +1 -1
- package/lib/cjs/Editing/PropertyCategories.js +29 -27
- package/lib/cjs/Editing/PropertyCategories.js.map +1 -1
- package/lib/cjs/Editing/RelationshipClasses.d.ts +15 -17
- package/lib/cjs/Editing/RelationshipClasses.d.ts.map +1 -1
- package/lib/cjs/Editing/RelationshipClasses.js +97 -101
- package/lib/cjs/Editing/RelationshipClasses.js.map +1 -1
- package/lib/cjs/Editing/SchemaItems.d.ts +13 -5
- package/lib/cjs/Editing/SchemaItems.d.ts.map +1 -1
- package/lib/cjs/Editing/SchemaItems.js +58 -6
- package/lib/cjs/Editing/SchemaItems.js.map +1 -1
- package/lib/cjs/Editing/Structs.d.ts +3 -3
- package/lib/cjs/Editing/Structs.d.ts.map +1 -1
- package/lib/cjs/Editing/Structs.js +17 -27
- package/lib/cjs/Editing/Structs.js.map +1 -1
- package/lib/cjs/Editing/UnitSystems.d.ts +7 -7
- package/lib/cjs/Editing/UnitSystems.d.ts.map +1 -1
- package/lib/cjs/Editing/UnitSystems.js +22 -20
- package/lib/cjs/Editing/UnitSystems.js.map +1 -1
- package/lib/cjs/Editing/Units.d.ts +6 -6
- package/lib/cjs/Editing/Units.d.ts.map +1 -1
- package/lib/cjs/Editing/Units.js +26 -35
- package/lib/cjs/Editing/Units.js.map +1 -1
- package/lib/cjs/Merging/CAClassMerger.js +2 -2
- package/lib/cjs/Merging/CAClassMerger.js.map +1 -1
- package/lib/cjs/Merging/ClassMerger.d.ts +1 -2
- package/lib/cjs/Merging/ClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/ClassMerger.js +15 -39
- package/lib/cjs/Merging/ClassMerger.js.map +1 -1
- package/lib/cjs/Merging/ConstantMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/ConstantMerger.js +2 -3
- package/lib/cjs/Merging/ConstantMerger.js.map +1 -1
- package/lib/cjs/Merging/CustomAttributeMerger.d.ts +4 -5
- package/lib/cjs/Merging/CustomAttributeMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/CustomAttributeMerger.js +8 -18
- package/lib/cjs/Merging/CustomAttributeMerger.js.map +1 -1
- package/lib/cjs/Merging/EntityClassMerger.d.ts +1 -2
- package/lib/cjs/Merging/EntityClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/EntityClassMerger.js +3 -10
- package/lib/cjs/Merging/EntityClassMerger.js.map +1 -1
- package/lib/cjs/Merging/EnumerationMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/EnumerationMerger.js +8 -10
- package/lib/cjs/Merging/EnumerationMerger.js.map +1 -1
- package/lib/cjs/Merging/KindOfQuantityMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/KindOfQuantityMerger.js +2 -3
- package/lib/cjs/Merging/KindOfQuantityMerger.js.map +1 -1
- package/lib/cjs/Merging/MixinMerger.js +2 -2
- package/lib/cjs/Merging/MixinMerger.js.map +1 -1
- package/lib/cjs/Merging/PhenomenonMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/PhenomenonMerger.js +1 -2
- package/lib/cjs/Merging/PhenomenonMerger.js.map +1 -1
- package/lib/cjs/Merging/PropertyCategoryMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/PropertyCategoryMerger.js +1 -2
- package/lib/cjs/Merging/PropertyCategoryMerger.js.map +1 -1
- package/lib/cjs/Merging/PropertyMerger.d.ts +2 -3
- package/lib/cjs/Merging/PropertyMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/PropertyMerger.js +21 -42
- package/lib/cjs/Merging/PropertyMerger.js.map +1 -1
- package/lib/cjs/Merging/RelationshipClassMerger.d.ts +5 -3
- package/lib/cjs/Merging/RelationshipClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/RelationshipClassMerger.js +35 -33
- package/lib/cjs/Merging/RelationshipClassMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaItemMerger.d.ts +3 -4
- package/lib/cjs/Merging/SchemaItemMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaItemMerger.js +3 -2
- package/lib/cjs/Merging/SchemaItemMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.js +2 -8
- package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
- package/lib/cjs/Merging/UnitSystemMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/UnitSystemMerger.js +1 -2
- package/lib/cjs/Merging/UnitSystemMerger.js.map +1 -1
- package/package.json +9 -9
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** @packageDocumentation
|
|
2
2
|
* @module Editing
|
|
3
3
|
*/
|
|
4
|
-
import { CustomAttribute, Schema, SchemaContext,
|
|
4
|
+
import { CustomAttribute, Schema, SchemaContext, SchemaKey } from "@itwin/ecschema-metadata";
|
|
5
5
|
import { MutableSchema } from "./Mutable/MutableSchema";
|
|
6
6
|
import { Constants } from "./Constants";
|
|
7
7
|
import { CustomAttributes } from "./CustomAttributes";
|
|
@@ -17,29 +17,6 @@ import { RelationshipClasses } from "./RelationshipClasses";
|
|
|
17
17
|
import { Structs } from "./Structs";
|
|
18
18
|
import { Units } from "./Units";
|
|
19
19
|
import { UnitSystems } from "./UnitSystems";
|
|
20
|
-
import { SchemaItems } from "./SchemaItems";
|
|
21
|
-
/**
|
|
22
|
-
* @alpha
|
|
23
|
-
*/
|
|
24
|
-
export interface SchemaEditResults {
|
|
25
|
-
schemaKey?: SchemaKey;
|
|
26
|
-
errorMessage?: string;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* @alpha
|
|
30
|
-
*/
|
|
31
|
-
export interface SchemaItemEditResults {
|
|
32
|
-
itemKey?: SchemaItemKey;
|
|
33
|
-
errorMessage?: string;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* @alpha
|
|
37
|
-
*/
|
|
38
|
-
export interface PropertyEditResults {
|
|
39
|
-
itemKey?: SchemaItemKey;
|
|
40
|
-
propertyName?: string;
|
|
41
|
-
errorMessage?: string;
|
|
42
|
-
}
|
|
43
20
|
/**
|
|
44
21
|
* A class that allows you to edit and create schemas, classes, and items from the SchemaContext level.
|
|
45
22
|
* @alpha
|
|
@@ -61,7 +38,6 @@ export declare class SchemaContextEditor {
|
|
|
61
38
|
readonly propertyCategories: PropertyCategories;
|
|
62
39
|
readonly invertedUnits: InvertedUnits;
|
|
63
40
|
/** @internal */
|
|
64
|
-
readonly schemaItems: SchemaItems;
|
|
65
41
|
/**
|
|
66
42
|
* Creates a new SchemaContextEditor instance.
|
|
67
43
|
* @param schemaContext The SchemaContext the Editor will use to edit in.
|
|
@@ -82,35 +58,38 @@ export declare class SchemaContextEditor {
|
|
|
82
58
|
* @param readVersion The read version number of the schema.
|
|
83
59
|
* @param writeVersion The write version number of the schema.
|
|
84
60
|
* @param minorVersion The minor version number of the schema.
|
|
85
|
-
* @returns Resolves to
|
|
61
|
+
* @returns Resolves to the SchemaKey of created schema.
|
|
86
62
|
*/
|
|
87
|
-
createSchema(name: string, alias: string, readVersion: number, writeVersion: number, minorVersion: number): Promise<
|
|
63
|
+
createSchema(name: string, alias: string, readVersion: number, writeVersion: number, minorVersion: number): Promise<SchemaKey>;
|
|
88
64
|
/**
|
|
89
65
|
* Adds a referenced schema to the schema identified by the given SchemaKey.
|
|
90
66
|
* @param schemaKey The SchemaKey identifying the schema.
|
|
91
67
|
* @param refSchema The referenced schema to add.
|
|
92
68
|
*/
|
|
93
|
-
addSchemaReference(schemaKey: SchemaKey, refSchema: Schema): Promise<
|
|
69
|
+
addSchemaReference(schemaKey: SchemaKey, refSchema: Schema): Promise<void>;
|
|
94
70
|
/**
|
|
95
71
|
* Adds a CustomAttribute instance to the schema identified by the given SchemaKey
|
|
96
72
|
* @param schemaKey The SchemaKey identifying the schema.
|
|
97
73
|
* @param customAttribute The CustomAttribute instance to add.
|
|
98
74
|
*/
|
|
99
|
-
addCustomAttribute(schemaKey: SchemaKey, customAttribute: CustomAttribute): Promise<
|
|
75
|
+
addCustomAttribute(schemaKey: SchemaKey, customAttribute: CustomAttribute): Promise<void>;
|
|
100
76
|
/**
|
|
101
77
|
* Sets the schema version.
|
|
102
78
|
* @param schemaKey The SchemaKey identifying the schema.
|
|
103
79
|
* @param readVersion The read version of the schema. If not specified, the existing read version will be maintained.
|
|
104
80
|
* @param writeVersion The write version of the schema. If not specified, the existing write version will be maintained.
|
|
105
81
|
* @param minorVersion The minor version of the schema. If not specified, the existing minor version will be maintained.
|
|
82
|
+
* @returns Resolves to the new SchemaKey containing version updates.
|
|
106
83
|
*/
|
|
107
|
-
setVersion(schemaKey: SchemaKey, readVersion?: number, writeVersion?: number, minorVersion?: number): Promise<
|
|
84
|
+
setVersion(schemaKey: SchemaKey, readVersion?: number, writeVersion?: number, minorVersion?: number): Promise<SchemaKey>;
|
|
108
85
|
/**
|
|
109
86
|
* Increments the minor version of a schema.
|
|
110
87
|
* @param schemaKey The SchemaKey identifying the schema.
|
|
88
|
+
* @returns Resolves to the new SchemaKey containing version updates.
|
|
111
89
|
*/
|
|
112
|
-
incrementMinorVersion(schemaKey: SchemaKey): Promise<
|
|
90
|
+
incrementMinorVersion(schemaKey: SchemaKey): Promise<SchemaKey>;
|
|
113
91
|
private removeReference;
|
|
114
92
|
private removeCustomAttribute;
|
|
93
|
+
private lookupSchema;
|
|
115
94
|
}
|
|
116
95
|
//# sourceMappingURL=Editor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Editor.d.ts","sourceRoot":"","sources":["../../../src/Editing/Editor.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"Editor.d.ts","sourceRoot":"","sources":["../../../src/Editing/Editor.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,EAAmB,MAAM,0BAA0B,CAAC;AAC9G,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC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AM,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAM3I;;;;OAIG;IACU,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBvF;;;;OAIG;IACU,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBtG;;;;;;;OAOG;IACU,UAAU,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAWrI;;;;OAIG;IACU,qBAAqB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IAW5E,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,qBAAqB;YAMf,YAAY;CAO3B"}
|
|
@@ -25,12 +25,14 @@ const RelationshipClasses_1 = require("./RelationshipClasses");
|
|
|
25
25
|
const Structs_1 = require("./Structs");
|
|
26
26
|
const Units_1 = require("./Units");
|
|
27
27
|
const UnitSystems_1 = require("./UnitSystems");
|
|
28
|
-
const
|
|
28
|
+
const Exception_1 = require("./Exception");
|
|
29
29
|
/**
|
|
30
30
|
* A class that allows you to edit and create schemas, classes, and items from the SchemaContext level.
|
|
31
31
|
* @alpha
|
|
32
32
|
*/
|
|
33
33
|
class SchemaContextEditor {
|
|
34
|
+
/** @internal */
|
|
35
|
+
// public readonly schemaItems = new SchemaItems(this);
|
|
34
36
|
/**
|
|
35
37
|
* Creates a new SchemaContextEditor instance.
|
|
36
38
|
* @param schemaContext The SchemaContext the Editor will use to edit in.
|
|
@@ -50,8 +52,6 @@ class SchemaContextEditor {
|
|
|
50
52
|
this.unitSystems = new UnitSystems_1.UnitSystems(this);
|
|
51
53
|
this.propertyCategories = new PropertyCategories_1.PropertyCategories(this);
|
|
52
54
|
this.invertedUnits = new InvertedUnits_1.InvertedUnits(this);
|
|
53
|
-
/** @internal */
|
|
54
|
-
this.schemaItems = new SchemaItems_1.SchemaItems(this);
|
|
55
55
|
// TODO: Make copy
|
|
56
56
|
this._schemaContext = schemaContext;
|
|
57
57
|
}
|
|
@@ -65,7 +65,7 @@ class SchemaContextEditor {
|
|
|
65
65
|
* @param schemaKey The SchemaKey identifying the schema.
|
|
66
66
|
*/
|
|
67
67
|
async getSchema(schemaKey) {
|
|
68
|
-
const schema =
|
|
68
|
+
const schema = await this.schemaContext.getCachedSchema(schemaKey, ecschema_metadata_1.SchemaMatchType.Latest);
|
|
69
69
|
if (schema === undefined)
|
|
70
70
|
return undefined;
|
|
71
71
|
return schema;
|
|
@@ -77,12 +77,12 @@ class SchemaContextEditor {
|
|
|
77
77
|
* @param readVersion The read version number of the schema.
|
|
78
78
|
* @param writeVersion The write version number of the schema.
|
|
79
79
|
* @param minorVersion The minor version number of the schema.
|
|
80
|
-
* @returns Resolves to
|
|
80
|
+
* @returns Resolves to the SchemaKey of created schema.
|
|
81
81
|
*/
|
|
82
82
|
async createSchema(name, alias, readVersion, writeVersion, minorVersion) {
|
|
83
83
|
const newSchema = new ecschema_metadata_1.Schema(this._schemaContext, name, alias, readVersion, writeVersion, minorVersion);
|
|
84
84
|
await this._schemaContext.addSchema(newSchema);
|
|
85
|
-
return
|
|
85
|
+
return newSchema.schemaKey;
|
|
86
86
|
}
|
|
87
87
|
/**
|
|
88
88
|
* Adds a referenced schema to the schema identified by the given SchemaKey.
|
|
@@ -90,23 +90,24 @@ class SchemaContextEditor {
|
|
|
90
90
|
* @param refSchema The referenced schema to add.
|
|
91
91
|
*/
|
|
92
92
|
async addSchemaReference(schemaKey, refSchema) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
93
|
+
try {
|
|
94
|
+
const schema = await this.lookupSchema(schemaKey, ecschema_metadata_1.SchemaMatchType.Exact);
|
|
95
|
+
await schema.addReference(refSchema);
|
|
96
|
+
const diagnostics = [];
|
|
97
|
+
for await (const diagnostic of Rules.validateSchemaReferences(schema)) {
|
|
98
|
+
diagnostics.push(diagnostic);
|
|
99
|
+
}
|
|
100
|
+
if (diagnostics.length > 0) {
|
|
101
|
+
this.removeReference(schema, refSchema);
|
|
102
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.RuleViolation, new Exception_1.SchemaId(schemaKey), undefined, diagnostics);
|
|
103
|
+
}
|
|
104
|
+
if (!await this.schemaContext.getCachedSchema(refSchema.schemaKey)) {
|
|
105
|
+
await this.schemaContext.addSchema(refSchema);
|
|
106
|
+
}
|
|
105
107
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
catch (e) {
|
|
109
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.AddSchemaReference, new Exception_1.SchemaId(schemaKey), e);
|
|
108
110
|
}
|
|
109
|
-
return {};
|
|
110
111
|
}
|
|
111
112
|
/**
|
|
112
113
|
* Adds a CustomAttribute instance to the schema identified by the given SchemaKey
|
|
@@ -114,20 +115,21 @@ class SchemaContextEditor {
|
|
|
114
115
|
* @param customAttribute The CustomAttribute instance to add.
|
|
115
116
|
*/
|
|
116
117
|
async addCustomAttribute(schemaKey, customAttribute) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
118
|
+
try {
|
|
119
|
+
const schema = await this.lookupSchema(schemaKey);
|
|
120
|
+
schema.addCustomAttribute(customAttribute);
|
|
121
|
+
const diagnostics = [];
|
|
122
|
+
for await (const diagnostic of Rules.validateCustomAttributeInstance(schema, customAttribute)) {
|
|
123
|
+
diagnostics.push(diagnostic);
|
|
124
|
+
}
|
|
125
|
+
if (diagnostics.length > 0) {
|
|
126
|
+
this.removeCustomAttribute(schema, customAttribute);
|
|
127
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.RuleViolation, new Exception_1.CustomAttributeId(customAttribute.className, schema), undefined, diagnostics);
|
|
128
|
+
}
|
|
125
129
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return result;
|
|
130
|
+
catch (e) {
|
|
131
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.AddCustomAttributeToClass, new Exception_1.SchemaId(schemaKey), e);
|
|
129
132
|
}
|
|
130
|
-
return {};
|
|
131
133
|
}
|
|
132
134
|
/**
|
|
133
135
|
* Sets the schema version.
|
|
@@ -135,24 +137,32 @@ class SchemaContextEditor {
|
|
|
135
137
|
* @param readVersion The read version of the schema. If not specified, the existing read version will be maintained.
|
|
136
138
|
* @param writeVersion The write version of the schema. If not specified, the existing write version will be maintained.
|
|
137
139
|
* @param minorVersion The minor version of the schema. If not specified, the existing minor version will be maintained.
|
|
140
|
+
* @returns Resolves to the new SchemaKey containing version updates.
|
|
138
141
|
*/
|
|
139
142
|
async setVersion(schemaKey, readVersion, writeVersion, minorVersion) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
try {
|
|
144
|
+
const schema = await this.lookupSchema(schemaKey);
|
|
145
|
+
schema.setVersion(readVersion || schema.readVersion, writeVersion || schema.writeVersion, minorVersion || schema.minorVersion);
|
|
146
|
+
return schema.schemaKey;
|
|
147
|
+
}
|
|
148
|
+
catch (e) {
|
|
149
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.SetSchemaVersion, new Exception_1.SchemaId(schemaKey), e);
|
|
150
|
+
}
|
|
145
151
|
}
|
|
146
152
|
/**
|
|
147
153
|
* Increments the minor version of a schema.
|
|
148
154
|
* @param schemaKey The SchemaKey identifying the schema.
|
|
155
|
+
* @returns Resolves to the new SchemaKey containing version updates.
|
|
149
156
|
*/
|
|
150
157
|
async incrementMinorVersion(schemaKey) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
158
|
+
try {
|
|
159
|
+
const schema = await this.lookupSchema(schemaKey);
|
|
160
|
+
schema.setVersion(schema.readVersion, schema.writeVersion, schema.minorVersion + 1);
|
|
161
|
+
return schema.schemaKey;
|
|
162
|
+
}
|
|
163
|
+
catch (e) {
|
|
164
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.IncrementSchemaMinorVersion, new Exception_1.SchemaId(schemaKey), e);
|
|
165
|
+
}
|
|
156
166
|
}
|
|
157
167
|
removeReference(schema, refSchema) {
|
|
158
168
|
const index = schema.references.indexOf(refSchema);
|
|
@@ -165,6 +175,12 @@ class SchemaContextEditor {
|
|
|
165
175
|
const map = schema.customAttributes;
|
|
166
176
|
map.delete(customAttribute.className);
|
|
167
177
|
}
|
|
178
|
+
async lookupSchema(schemaKey, matchType = ecschema_metadata_1.SchemaMatchType.Latest) {
|
|
179
|
+
const schema = await this.schemaContext.getCachedSchema(schemaKey, matchType);
|
|
180
|
+
if (schema === undefined)
|
|
181
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.SchemaNotFound, new Exception_1.SchemaId(schemaKey));
|
|
182
|
+
return schema;
|
|
183
|
+
}
|
|
168
184
|
}
|
|
169
185
|
exports.SchemaContextEditor = SchemaContextEditor;
|
|
170
186
|
//# sourceMappingURL=Editor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Editor.js","sourceRoot":"","sources":["../../../src/Editing/Editor.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+CAA+C;AAC/C,gEAA6H;AAE7H,sDAA6C;AAC7C,2CAAwC;AACxC,yDAAsD;AACtD,yCAAsC;AACtC,iDAA8C;AAC9C,uCAAoC;AACpC,mDAAgD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CAAC,CAAC,EAAE,CAAC;YACjB,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IAEO,qBAAqB,CAAC,MAAc,EAAE,eAAgC;QAC5E,IAAA,qBAAM,EAAC,MAAM,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC;QAC9C,MAAM,GAAG,GAAG,MAAM,CAAC,gBAAgD,CAAC;QACpE,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;CACF;AAhKD,kDAgKC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Editing\r\n */\r\n\r\nimport * as Rules from \"../Validation/ECRules\";\r\nimport { CustomAttribute, Schema, SchemaContext, SchemaItemKey, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\r\nimport { MutableSchema } from \"./Mutable/MutableSchema\";\r\nimport { assert } from \"@itwin/core-bentley\";\r\nimport { Constants } from \"./Constants\";\r\nimport { CustomAttributes } from \"./CustomAttributes\";\r\nimport { Entities } from \"./Entities\";\r\nimport { Enumerations } from \"./Enumerations\";\r\nimport { Formats } from \"./Formats\";\r\nimport { InvertedUnits } from \"./InvertedUnits\";\r\nimport { KindOfQuantities } from \"./KindOfQuantities\";\r\nimport { Mixins } from \"./Mixins\";\r\nimport { Phenomena } from \"./Phenomena\";\r\nimport { PropertyCategories } from \"./PropertyCategories\";\r\nimport { RelationshipClasses } from \"./RelationshipClasses\";\r\nimport { Structs } from \"./Structs\";\r\nimport { Units } from \"./Units\";\r\nimport { UnitSystems } from \"./UnitSystems\";\r\nimport { SchemaItems } from \"./SchemaItems\";\r\n\r\n// We can either add validation in Editor, or in the protected methods of Schema.\r\n// TODO: Add an error code so we can do something programmatic with the error.\r\n/**\r\n * @alpha\r\n */\r\nexport interface SchemaEditResults {\r\n schemaKey?: SchemaKey;\r\n errorMessage?: string;\r\n}\r\n\r\n/**\r\n * @alpha\r\n */\r\nexport interface SchemaItemEditResults {\r\n itemKey?: SchemaItemKey;\r\n errorMessage?: string;\r\n}\r\n\r\n/**\r\n * @alpha\r\n */\r\nexport interface PropertyEditResults {\r\n itemKey?: SchemaItemKey;\r\n propertyName?: string;\r\n errorMessage?: string;\r\n}\r\n\r\n/**\r\n * A class that allows you to edit and create schemas, classes, and items from the SchemaContext level.\r\n * @alpha\r\n */\r\nexport class SchemaContextEditor {\r\n private _schemaContext: SchemaContext;\r\n public readonly entities = new Entities(this);\r\n public readonly mixins = new Mixins(this);\r\n public readonly structs = new Structs(this);\r\n public readonly customAttributes = new CustomAttributes(this);\r\n public readonly relationships = new RelationshipClasses(this);\r\n public readonly constants = new Constants(this);\r\n public readonly enumerations = new Enumerations(this);\r\n public readonly formats = new Formats(this);\r\n public readonly kindOfQuantities = new KindOfQuantities(this);\r\n public readonly units = new Units(this);\r\n public readonly phenomenons = new Phenomena(this);\r\n public readonly unitSystems = new UnitSystems(this);\r\n public readonly propertyCategories = new PropertyCategories(this);\r\n public readonly invertedUnits = new InvertedUnits(this);\r\n\r\n /** @internal */\r\n public readonly schemaItems = new SchemaItems(this);\r\n\r\n /**\r\n * Creates a new SchemaContextEditor instance.\r\n * @param schemaContext The SchemaContext the Editor will use to edit in.\r\n */\r\n constructor(schemaContext: SchemaContext) {\r\n // TODO: Make copy\r\n this._schemaContext = schemaContext;\r\n }\r\n\r\n /** Allows you to get schema classes and items through regular SchemaContext methods. */\r\n public get schemaContext(): SchemaContext { return this._schemaContext; }\r\n\r\n public async finish(): Promise<SchemaContext> {\r\n return this._schemaContext;\r\n }\r\n\r\n /**\r\n * Helper method for retrieving a schema, previously added, from the SchemaContext.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n */\r\n public async getSchema(schemaKey: SchemaKey): Promise<MutableSchema | undefined> {\r\n const schema = (await this.schemaContext.getCachedSchema<MutableSchema>(schemaKey, SchemaMatchType.Latest));\r\n if (schema === undefined)\r\n return undefined;\r\n\r\n return schema;\r\n }\r\n /**\r\n * Creates a Schema with the given properties and adds it to the current schema context.\r\n * @param name The name given to the new schema.\r\n * @param alias The alias of the new schema.\r\n * @param readVersion The read version number of the schema.\r\n * @param writeVersion The write version number of the schema.\r\n * @param minorVersion The minor version number of the schema.\r\n * @returns Resolves to a SchemaEditResults object.\r\n */\r\n public async createSchema(name: string, alias: string, readVersion: number, writeVersion: number, minorVersion: number): Promise<SchemaEditResults> {\r\n const newSchema = new Schema(this._schemaContext, name, alias, readVersion, writeVersion, minorVersion);\r\n await this._schemaContext.addSchema(newSchema);\r\n return { schemaKey: newSchema.schemaKey };\r\n }\r\n\r\n /**\r\n * Adds a referenced schema to the schema identified by the given SchemaKey.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @param refSchema The referenced schema to add.\r\n */\r\n public async addSchemaReference(schemaKey: SchemaKey, refSchema: Schema): Promise<SchemaEditResults> {\r\n const schema = (await this.schemaContext.getCachedSchema<MutableSchema>(schemaKey, SchemaMatchType.Exact));\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n await schema.addReference(refSchema);\r\n const diagnostics = Rules.validateSchemaReferences(schema);\r\n\r\n const result: SchemaEditResults = { errorMessage: \"\" };\r\n for await (const diagnostic of diagnostics) {\r\n result.errorMessage += `${diagnostic.code}: ${diagnostic.messageText}\\r\\n`;\r\n }\r\n\r\n if (result.errorMessage) {\r\n this.removeReference(schema, refSchema);\r\n return result;\r\n }\r\n\r\n if (!await this.schemaContext.getCachedSchema(refSchema.schemaKey)) {\r\n await this.schemaContext.addSchema(refSchema);\r\n }\r\n\r\n return {};\r\n }\r\n\r\n /**\r\n * Adds a CustomAttribute instance to the schema identified by the given SchemaKey\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @param customAttribute The CustomAttribute instance to add.\r\n */\r\n public async addCustomAttribute(schemaKey: SchemaKey, customAttribute: CustomAttribute): Promise<SchemaEditResults> {\r\n const schema = (await this.schemaContext.getCachedSchema<MutableSchema>(schemaKey, SchemaMatchType.Latest));\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n schema.addCustomAttribute(customAttribute);\r\n\r\n const diagnostics = Rules.validateCustomAttributeInstance(schema, customAttribute);\r\n\r\n const result: SchemaEditResults = { errorMessage: \"\" };\r\n for await (const diagnostic of diagnostics) {\r\n result.errorMessage += `${diagnostic.code}: ${diagnostic.messageText}\\r\\n`;\r\n }\r\n\r\n if (result.errorMessage) {\r\n this.removeCustomAttribute(schema, customAttribute);\r\n return result;\r\n }\r\n\r\n return {};\r\n }\r\n\r\n /**\r\n * Sets the schema version.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @param readVersion The read version of the schema. If not specified, the existing read version will be maintained.\r\n * @param writeVersion The write version of the schema. If not specified, the existing write version will be maintained.\r\n * @param minorVersion The minor version of the schema. If not specified, the existing minor version will be maintained.\r\n */\r\n public async setVersion(schemaKey: SchemaKey, readVersion?: number, writeVersion?: number, minorVersion?: number): Promise<SchemaEditResults> {\r\n const schema = (await this.schemaContext.getCachedSchema(schemaKey, SchemaMatchType.Latest));\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n schema.setVersion(readVersion || schema.readVersion, writeVersion || schema.writeVersion, minorVersion || schema.minorVersion);\r\n return {};\r\n }\r\n\r\n /**\r\n * Increments the minor version of a schema.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n */\r\n public async incrementMinorVersion(schemaKey: SchemaKey): Promise<SchemaEditResults> {\r\n const schema = (await this.schemaContext.getCachedSchema(schemaKey, SchemaMatchType.Latest));\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n schema.setVersion(schema.readVersion, schema.writeVersion, schema.minorVersion + 1);\r\n return {};\r\n }\r\n\r\n private removeReference(schema: Schema, refSchema: Schema) {\r\n const index: number = schema.references.indexOf(refSchema);\r\n if (index !== -1) {\r\n schema.references.splice(index, 1);\r\n }\r\n }\r\n\r\n private removeCustomAttribute(schema: Schema, customAttribute: CustomAttribute) {\r\n assert(schema.customAttributes !== undefined);\r\n const map = schema.customAttributes as Map<string, CustomAttribute>;\r\n map.delete(customAttribute.className);\r\n }\r\n}\r\n\r\n"]}
|
|
1
|
+
{"version":3,"file":"Editor.js","sourceRoot":"","sources":["../../../src/Editing/Editor.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+CAA+C;AAC/C,gEAA8G;AAE9G,sDAA6C;AAC7C,2CAAwC;AACxC,yDAAsD;AACtD,yCAAsC;AACtC,iDAA8C;AAC9C,uCAAoC;AACpC,mDAAgD;AAChD,yDAAsD;AACtD,qCAAkC;AAClC,2CAAwC;AACxC,6DAA0D;AAC1D,+DAA4D;AAC5D,uCAAoC;AACpC,mCAAgC;AAChC,+CAA4C;AAC5C,2CAA+F;AAG/F;;;GAGG;AACH,MAAa,mBAAmB;IAiB9B,gBAAgB;IAChB,uDAAuD;IAEvD;;;OAGG;IACH,YAAY,aAA4B;QAtBxB,aAAQ,GAAG,IAAI,mBAAQ,CAAC,IAAI,CAAC,CAAC;QAC9B,WAAM,GAAG,IAAI,eAAM,CAAC,IAAI,CAAC,CAAC;QAC1B,YAAO,GAAG,IAAI,iBAAO,CAAC,IAAI,CAAC,CAAC;QAC5B,qBAAgB,GAAG,IAAI,mCAAgB,CAAC,IAAI,CAAC,CAAC;QAC9C,kBAAa,GAAG,IAAI,yCAAmB,CAAC,IAAI,CAAC,CAAC;QAC9C,cAAS,GAAG,IAAI,qBAAS,CAAC,IAAI,CAAC,CAAC;QAChC,iBAAY,GAAG,IAAI,2BAAY,CAAC,IAAI,CAAC,CAAC;QACtC,YAAO,GAAG,IA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AAS,CAAC,CAAC,CAAC;QAExF,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA1KD,kDA0KC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Editing\r\n */\r\n\r\nimport * as Rules from \"../Validation/ECRules\";\r\nimport { CustomAttribute, Schema, SchemaContext, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\r\nimport { MutableSchema } from \"./Mutable/MutableSchema\";\r\nimport { assert } from \"@itwin/core-bentley\";\r\nimport { Constants } from \"./Constants\";\r\nimport { CustomAttributes } from \"./CustomAttributes\";\r\nimport { Entities } from \"./Entities\";\r\nimport { Enumerations } from \"./Enumerations\";\r\nimport { Formats } from \"./Formats\";\r\nimport { InvertedUnits } from \"./InvertedUnits\";\r\nimport { KindOfQuantities } from \"./KindOfQuantities\";\r\nimport { Mixins } from \"./Mixins\";\r\nimport { Phenomena } from \"./Phenomena\";\r\nimport { PropertyCategories } from \"./PropertyCategories\";\r\nimport { RelationshipClasses } from \"./RelationshipClasses\";\r\nimport { Structs } from \"./Structs\";\r\nimport { Units } from \"./Units\";\r\nimport { UnitSystems } from \"./UnitSystems\";\r\nimport { CustomAttributeId, ECEditingStatus, SchemaEditingError, SchemaId } from \"./Exception\";\r\nimport { AnyDiagnostic } from \"../Validation/Diagnostic\";\r\n\r\n/**\r\n * A class that allows you to edit and create schemas, classes, and items from the SchemaContext level.\r\n * @alpha\r\n */\r\nexport class SchemaContextEditor {\r\n private _schemaContext: SchemaContext;\r\n public readonly entities = new Entities(this);\r\n public readonly mixins = new Mixins(this);\r\n public readonly structs = new Structs(this);\r\n public readonly customAttributes = new CustomAttributes(this);\r\n public readonly relationships = new RelationshipClasses(this);\r\n public readonly constants = new Constants(this);\r\n public readonly enumerations = new Enumerations(this);\r\n public readonly formats = new Formats(this);\r\n public readonly kindOfQuantities = new KindOfQuantities(this);\r\n public readonly units = new Units(this);\r\n public readonly phenomenons = new Phenomena(this);\r\n public readonly unitSystems = new UnitSystems(this);\r\n public readonly propertyCategories = new PropertyCategories(this);\r\n public readonly invertedUnits = new InvertedUnits(this);\r\n\r\n /** @internal */\r\n // public readonly schemaItems = new SchemaItems(this);\r\n\r\n /**\r\n * Creates a new SchemaContextEditor instance.\r\n * @param schemaContext The SchemaContext the Editor will use to edit in.\r\n */\r\n constructor(schemaContext: SchemaContext) {\r\n // TODO: Make copy\r\n this._schemaContext = schemaContext;\r\n }\r\n\r\n /** Allows you to get schema classes and items through regular SchemaContext methods. */\r\n public get schemaContext(): SchemaContext { return this._schemaContext; }\r\n\r\n public async finish(): Promise<SchemaContext> {\r\n return this._schemaContext;\r\n }\r\n\r\n /**\r\n * Helper method for retrieving a schema, previously added, from the SchemaContext.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n */\r\n public async getSchema(schemaKey: SchemaKey): Promise<MutableSchema | undefined> {\r\n const schema = await this.schemaContext.getCachedSchema<MutableSchema>(schemaKey, SchemaMatchType.Latest);\r\n if (schema === undefined)\r\n return undefined;\r\n\r\n return schema;\r\n }\r\n\r\n /**\r\n * Creates a Schema with the given properties and adds it to the current schema context.\r\n * @param name The name given to the new schema.\r\n * @param alias The alias of the new schema.\r\n * @param readVersion The read version number of the schema.\r\n * @param writeVersion The write version number of the schema.\r\n * @param minorVersion The minor version number of the schema.\r\n * @returns Resolves to the SchemaKey of created schema.\r\n */\r\n public async createSchema(name: string, alias: string, readVersion: number, writeVersion: number, minorVersion: number): Promise<SchemaKey> {\r\n const newSchema = new Schema(this._schemaContext, name, alias, readVersion, writeVersion, minorVersion);\r\n await this._schemaContext.addSchema(newSchema);\r\n return newSchema.schemaKey;\r\n }\r\n\r\n /**\r\n * Adds a referenced schema to the schema identified by the given SchemaKey.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @param refSchema The referenced schema to add.\r\n */\r\n public async addSchemaReference(schemaKey: SchemaKey, refSchema: Schema): Promise<void> {\r\n try {\r\n const schema = await this.lookupSchema(schemaKey, SchemaMatchType.Exact);\r\n await schema.addReference(refSchema);\r\n\r\n const diagnostics: AnyDiagnostic[] = [];\r\n for await (const diagnostic of Rules.validateSchemaReferences(schema)) {\r\n diagnostics.push(diagnostic);\r\n }\r\n\r\n if (diagnostics.length > 0) {\r\n this.removeReference(schema, refSchema);\r\n throw new SchemaEditingError(ECEditingStatus.RuleViolation, new SchemaId(schemaKey), undefined, diagnostics);\r\n }\r\n\r\n if (!await this.schemaContext.getCachedSchema(refSchema.schemaKey)) {\r\n await this.schemaContext.addSchema(refSchema);\r\n }\r\n } catch(e: any) {\r\n throw new SchemaEditingError(ECEditingStatus.AddSchemaReference, new SchemaId(schemaKey), e);\r\n }\r\n }\r\n\r\n /**\r\n * Adds a CustomAttribute instance to the schema identified by the given SchemaKey\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @param customAttribute The CustomAttribute instance to add.\r\n */\r\n public async addCustomAttribute(schemaKey: SchemaKey, customAttribute: CustomAttribute): Promise<void> {\r\n try {\r\n const schema = await this.lookupSchema(schemaKey);\r\n schema.addCustomAttribute(customAttribute);\r\n\r\n const diagnostics: AnyDiagnostic[] = [];\r\n for await (const diagnostic of Rules.validateCustomAttributeInstance(schema, customAttribute)) {\r\n diagnostics.push(diagnostic);\r\n }\r\n\r\n if (diagnostics.length > 0) {\r\n this.removeCustomAttribute(schema, customAttribute);\r\n throw new SchemaEditingError(ECEditingStatus.RuleViolation, new CustomAttributeId(customAttribute.className, schema), undefined, diagnostics);\r\n }\r\n } catch(e: any) {\r\n throw new SchemaEditingError(ECEditingStatus.AddCustomAttributeToClass, new SchemaId(schemaKey), e);\r\n }\r\n }\r\n\r\n /**\r\n * Sets the schema version.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @param readVersion The read version of the schema. If not specified, the existing read version will be maintained.\r\n * @param writeVersion The write version of the schema. If not specified, the existing write version will be maintained.\r\n * @param minorVersion The minor version of the schema. If not specified, the existing minor version will be maintained.\r\n * @returns Resolves to the new SchemaKey containing version updates.\r\n */\r\n public async setVersion(schemaKey: SchemaKey, readVersion?: number, writeVersion?: number, minorVersion?: number): Promise<SchemaKey> {\r\n try {\r\n const schema = await this.lookupSchema(schemaKey);\r\n schema.setVersion(readVersion || schema.readVersion, writeVersion || schema.writeVersion, minorVersion || schema.minorVersion);\r\n\r\n return schema.schemaKey;\r\n } catch(e: any) {\r\n throw new SchemaEditingError(ECEditingStatus.SetSchemaVersion, new SchemaId(schemaKey), e);\r\n }\r\n }\r\n\r\n /**\r\n * Increments the minor version of a schema.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @returns Resolves to the new SchemaKey containing version updates.\r\n */\r\n public async incrementMinorVersion(schemaKey: SchemaKey): Promise<SchemaKey> {\r\n try {\r\n const schema = await this.lookupSchema(schemaKey);\r\n schema.setVersion(schema.readVersion, schema.writeVersion, schema.minorVersion + 1);\r\n\r\n return schema.schemaKey;\r\n } catch (e: any) {\r\n throw new SchemaEditingError(ECEditingStatus.IncrementSchemaMinorVersion, new SchemaId(schemaKey), e);\r\n }\r\n }\r\n\r\n private removeReference(schema: Schema, refSchema: Schema) {\r\n const index: number = schema.references.indexOf(refSchema);\r\n if (index !== -1) {\r\n schema.references.splice(index, 1);\r\n }\r\n }\r\n\r\n private removeCustomAttribute(schema: Schema, customAttribute: CustomAttribute) {\r\n assert(schema.customAttributes !== undefined);\r\n const map = schema.customAttributes as Map<string, CustomAttribute>;\r\n map.delete(customAttribute.className);\r\n }\r\n\r\n private async lookupSchema(schemaKey: SchemaKey, matchType: SchemaMatchType = SchemaMatchType.Latest): Promise<MutableSchema> {\r\n const schema = await this.schemaContext.getCachedSchema<MutableSchema>(schemaKey, matchType);\r\n if (schema === undefined)\r\n throw new SchemaEditingError(ECEditingStatus.SchemaNotFound, new SchemaId(schemaKey));\r\n\r\n return schema;\r\n }\r\n}\r\n\r\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @module Editing
|
|
3
3
|
*/
|
|
4
4
|
import { ECClassModifier, EntityClassProps, Mixin, NavigationPropertyProps, RelationshipClass, SchemaItemKey, SchemaKey, StrengthDirection } from "@itwin/ecschema-metadata";
|
|
5
|
-
import {
|
|
5
|
+
import { SchemaContextEditor } from "./Editor";
|
|
6
6
|
import { ECClasses } from "./ECClasses";
|
|
7
7
|
import { NavigationProperties } from "./Properties";
|
|
8
8
|
/**
|
|
@@ -15,23 +15,23 @@ export declare class Entities extends ECClasses {
|
|
|
15
15
|
* Allows access for editing of NavigationProperty attributes.
|
|
16
16
|
*/
|
|
17
17
|
readonly navigationProperties: NavigationProperties;
|
|
18
|
-
createElement(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<
|
|
19
|
-
createElementUniqueAspect(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<
|
|
20
|
-
createElementMultiAspect(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<
|
|
21
|
-
create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, displayLabel?: string, baseClassKey?: SchemaItemKey, mixins?: Mixin[]): Promise<
|
|
18
|
+
createElement(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemKey>;
|
|
19
|
+
createElementUniqueAspect(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemKey>;
|
|
20
|
+
createElementMultiAspect(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemKey>;
|
|
21
|
+
create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, displayLabel?: string, baseClassKey?: SchemaItemKey, mixins?: Mixin[]): Promise<SchemaItemKey>;
|
|
22
22
|
/**
|
|
23
23
|
* Creates an EntityClass through an EntityClassProps.
|
|
24
24
|
* @param schemaKey a SchemaKey of the Schema that will house the new object.
|
|
25
25
|
* @param entityProps a json object that will be used to populate the new EntityClass. Needs a name value passed in.
|
|
26
26
|
*/
|
|
27
|
-
createFromProps(schemaKey: SchemaKey, entityProps: EntityClassProps): Promise<
|
|
28
|
-
addMixin(entityKey: SchemaItemKey, mixinKey: SchemaItemKey): Promise<
|
|
29
|
-
createNavigationProperty(entityKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<
|
|
27
|
+
createFromProps(schemaKey: SchemaKey, entityProps: EntityClassProps): Promise<SchemaItemKey>;
|
|
28
|
+
addMixin(entityKey: SchemaItemKey, mixinKey: SchemaItemKey): Promise<void>;
|
|
29
|
+
createNavigationProperty(entityKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<void>;
|
|
30
30
|
/**
|
|
31
31
|
* Creates a Navigation Property through a NavigationPropertyProps.
|
|
32
32
|
* @param classKey a SchemaItemKey of the Entity Class that will house the new property.
|
|
33
33
|
* @param navigationProps a json object that will be used to populate the new Navigation Property.
|
|
34
34
|
*/
|
|
35
|
-
createNavigationPropertyFromProps(classKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<
|
|
35
|
+
createNavigationPropertyFromProps(classKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<void>;
|
|
36
36
|
}
|
|
37
37
|
//# sourceMappingURL=Entities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Entities.d.ts","sourceRoot":"","sources":["../../../src/Editing/Entities.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"Entities.d.ts","sour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EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAgBjL;;;;OAIG;IACU,eAAe,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC;IAS5F,QAAQ,CAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAU1E,wBAAwB,CAAC,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,iBAAiB,EAAE,SAAS,EAAE,MAAM,GAAG,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7K;;;;OAIG;IACU,iCAAiC,CAAC,QAAQ,EAAE,aAAa,EAAE,eAAe,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;CASjI"}
|
|
@@ -11,6 +11,7 @@ exports.Entities = void 0;
|
|
|
11
11
|
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
12
12
|
const ECClasses_1 = require("./ECClasses");
|
|
13
13
|
const Properties_1 = require("./Properties");
|
|
14
|
+
const Exception_1 = require("./Exception");
|
|
14
15
|
/**
|
|
15
16
|
* @alpha
|
|
16
17
|
* A class extending ECClasses allowing you to create schema items of type EntityClass.
|
|
@@ -21,66 +22,56 @@ class Entities extends ECClasses_1.ECClasses {
|
|
|
21
22
|
/**
|
|
22
23
|
* Allows access for editing of NavigationProperty attributes.
|
|
23
24
|
*/
|
|
24
|
-
this.navigationProperties = new Properties_1.NavigationProperties(
|
|
25
|
+
this.navigationProperties = new Properties_1.NavigationProperties(ecschema_metadata_1.SchemaItemType.EntityClass, this.schemaEditor);
|
|
25
26
|
}
|
|
26
27
|
async createElement(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
try {
|
|
29
|
+
const baseClass = await this.getSchemaItem(baseClassKey);
|
|
30
|
+
if (!(await baseClass.is("Element", "BisCore"))) {
|
|
31
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.BaseClassIsNotElement, new Exception_1.ClassId(this.schemaItemType, baseClassKey));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.CreateElement, new Exception_1.ClassId(this.schemaItemType, name, schemaKey), e);
|
|
34
36
|
}
|
|
35
37
|
return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);
|
|
36
38
|
}
|
|
37
39
|
async createElementUniqueAspect(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
try {
|
|
41
|
+
const baseClass = await this.getSchemaItem(baseClassKey);
|
|
42
|
+
if (!(await baseClass.is("ElementUniqueAspect", "BisCore"))) {
|
|
43
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.BaseClassIsNotElementUniqueAspect, new Exception_1.ClassId(this.schemaItemType, baseClassKey));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.CreateElement, new Exception_1.ClassId(this.schemaItemType, name, schemaKey), e);
|
|
45
48
|
}
|
|
46
49
|
return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);
|
|
47
50
|
}
|
|
48
51
|
async createElementMultiAspect(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
try {
|
|
53
|
+
const baseClass = await this.getSchemaItem(baseClassKey);
|
|
54
|
+
if (!(await baseClass.is("ElementMultiAspect", "BisCore"))) {
|
|
55
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.BaseClassIsNotElementMultiAspect, new Exception_1.ClassId(this.schemaItemType, baseClassKey));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.CreateElement, new Exception_1.ClassId(this.schemaItemType, name, schemaKey), e);
|
|
56
60
|
}
|
|
57
61
|
return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);
|
|
58
62
|
}
|
|
59
63
|
async create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
const baseClassItem = await baseClassSchema.lookupItem(baseClassKey);
|
|
73
|
-
if (baseClassItem === undefined)
|
|
74
|
-
return { errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };
|
|
75
|
-
if (baseClassItem.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
|
|
76
|
-
return { errorMessage: `${baseClassItem.fullName} is not of type Entity Class.` };
|
|
77
|
-
newClass.baseClass = new ecschema_metadata_1.DelayedPromiseWithProps(baseClassKey, async () => baseClassItem);
|
|
78
|
-
}
|
|
79
|
-
if (mixins !== undefined)
|
|
80
|
-
mixins.forEach((m) => newClass.addMixin(m));
|
|
81
|
-
if (displayLabel)
|
|
82
|
-
newClass.setDisplayLabel(displayLabel);
|
|
83
|
-
return { itemKey: newClass.key };
|
|
64
|
+
try {
|
|
65
|
+
const newClass = await this.createClass(schemaKey, this.schemaItemType, (schema) => schema.createEntityClass.bind(schema), name, baseClassKey, modifier);
|
|
66
|
+
if (mixins !== undefined)
|
|
67
|
+
mixins.forEach((m) => newClass.addMixin(m));
|
|
68
|
+
if (displayLabel)
|
|
69
|
+
newClass.setDisplayLabel(displayLabel);
|
|
70
|
+
return newClass.key;
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.CreateSchemaItemFailed, new Exception_1.ClassId(this.schemaItemType, name, schemaKey), e);
|
|
74
|
+
}
|
|
84
75
|
}
|
|
85
76
|
/**
|
|
86
77
|
* Creates an EntityClass through an EntityClassProps.
|
|
@@ -88,43 +79,32 @@ class Entities extends ECClasses_1.ECClasses {
|
|
|
88
79
|
* @param entityProps a json object that will be used to populate the new EntityClass. Needs a name value passed in.
|
|
89
80
|
*/
|
|
90
81
|
async createFromProps(schemaKey, entityProps) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return
|
|
94
|
-
if (entityProps.name === undefined)
|
|
95
|
-
return { errorMessage: `No name was supplied within props.` };
|
|
96
|
-
const newClass = (await schema.createEntityClass(entityProps.name));
|
|
97
|
-
if (newClass === undefined)
|
|
98
|
-
return { errorMessage: `Failed to create class ${entityProps.name} in schema ${schemaKey.toString(true)}.` };
|
|
99
|
-
await newClass.fromJSON(entityProps);
|
|
100
|
-
return { itemKey: newClass.key };
|
|
101
|
-
}
|
|
102
|
-
async addMixin(entityKey, mixinKey) {
|
|
103
|
-
const entity = (await this._schemaEditor.schemaContext.getSchemaItem(entityKey));
|
|
104
|
-
if (entity === undefined) {
|
|
105
|
-
return { errorMessage: `Entity Class ${entityKey.fullName} not found in schema context.` };
|
|
82
|
+
try {
|
|
83
|
+
const newClass = await this.createSchemaItemFromProps(schemaKey, this.schemaItemType, (schema) => schema.createEntityClass.bind(schema), entityProps);
|
|
84
|
+
return newClass.key;
|
|
106
85
|
}
|
|
107
|
-
|
|
108
|
-
|
|
86
|
+
catch (e) {
|
|
87
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.CreateSchemaItemFromProps, new Exception_1.ClassId(this.schemaItemType, entityProps.name, schemaKey), e);
|
|
109
88
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
89
|
+
}
|
|
90
|
+
async addMixin(entityKey, mixinKey) {
|
|
91
|
+
try {
|
|
92
|
+
const entity = await this.getSchemaItem(entityKey);
|
|
93
|
+
const mixin = await this.getSchemaItem(mixinKey, ecschema_metadata_1.SchemaItemType.Mixin);
|
|
94
|
+
entity.addMixin(mixin);
|
|
113
95
|
}
|
|
114
|
-
|
|
115
|
-
|
|
96
|
+
catch (e) {
|
|
97
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.AddMixin, new Exception_1.ClassId(ecschema_metadata_1.SchemaItemType.EntityClass, entityKey), e);
|
|
116
98
|
}
|
|
117
|
-
entity.addMixin(mixin);
|
|
118
|
-
return { itemKey: entityKey };
|
|
119
99
|
}
|
|
120
100
|
async createNavigationProperty(entityKey, name, relationship, direction) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
101
|
+
try {
|
|
102
|
+
const entity = await this.getSchemaItem(entityKey);
|
|
103
|
+
await entity.createNavigationProperty(name, relationship, direction);
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.CreateNavigationProperty, new Exception_1.ClassId(ecschema_metadata_1.SchemaItemType.RelationshipClass, entityKey), e);
|
|
107
|
+
}
|
|
128
108
|
}
|
|
129
109
|
/**
|
|
130
110
|
* Creates a Navigation Property through a NavigationPropertyProps.
|
|
@@ -132,14 +112,14 @@ class Entities extends ECClasses_1.ECClasses {
|
|
|
132
112
|
* @param navigationProps a json object that will be used to populate the new Navigation Property.
|
|
133
113
|
*/
|
|
134
114
|
async createNavigationPropertyFromProps(classKey, navigationProps) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
115
|
+
try {
|
|
116
|
+
const entity = await this.getSchemaItem(classKey);
|
|
117
|
+
const property = await entity.createNavigationProperty(navigationProps.name, navigationProps.relationshipName, navigationProps.direction);
|
|
118
|
+
await property.fromJSON(navigationProps);
|
|
119
|
+
}
|
|
120
|
+
catch (e) {
|
|
121
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.CreateNavigationPropertyFromProps, new Exception_1.ClassId(ecschema_metadata_1.SchemaItemType.EntityClass, classKey), e);
|
|
122
|
+
}
|
|
143
123
|
}
|
|
144
124
|
}
|
|
145
125
|
exports.Entities = Entities;
|