@itwin/ecschema-editing 4.0.0-dev.52 → 4.0.0-dev.55
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/Editing/Constants.d.ts +20 -20
- package/lib/cjs/Editing/Constants.js +60 -60
- package/lib/cjs/Editing/CustomAttributes.d.ts +20 -20
- package/lib/cjs/Editing/CustomAttributes.js +59 -59
- package/lib/cjs/Editing/ECClasses.d.ts +54 -54
- package/lib/cjs/Editing/ECClasses.js +269 -269
- package/lib/cjs/Editing/Editor.d.ts +112 -112
- package/lib/cjs/Editing/Editor.js +166 -166
- package/lib/cjs/Editing/Entities.d.ts +25 -25
- package/lib/cjs/Editing/Entities.js +116 -116
- package/lib/cjs/Editing/Enumerations.d.ts +21 -21
- package/lib/cjs/Editing/Enumerations.js +66 -66
- package/lib/cjs/Editing/Formats.d.ts +21 -21
- package/lib/cjs/Editing/Formats.js +61 -61
- package/lib/cjs/Editing/InvertedUnits.d.ts +17 -17
- package/lib/cjs/Editing/InvertedUnits.js +82 -82
- package/lib/cjs/Editing/KindOfQuantities.d.ts +28 -28
- package/lib/cjs/Editing/KindOfQuantities.js +78 -78
- package/lib/cjs/Editing/Mixins.d.ts +22 -22
- package/lib/cjs/Editing/Mixins.js +84 -84
- package/lib/cjs/Editing/Mutable/MutableCAClass.d.ts +9 -9
- package/lib/cjs/Editing/Mutable/MutableCAClass.js +15 -15
- package/lib/cjs/Editing/Mutable/MutableClass.d.ts +34 -34
- package/lib/cjs/Editing/Mutable/MutableClass.js +22 -22
- package/lib/cjs/Editing/Mutable/MutableConstant.d.ts +12 -12
- package/lib/cjs/Editing/Mutable/MutableConstant.js +15 -15
- package/lib/cjs/Editing/Mutable/MutableEntityClass.d.ts +15 -15
- package/lib/cjs/Editing/Mutable/MutableEntityClass.js +59 -59
- package/lib/cjs/Editing/Mutable/MutableEnumeration.d.ts +9 -9
- package/lib/cjs/Editing/Mutable/MutableEnumeration.js +14 -14
- package/lib/cjs/Editing/Mutable/MutableFormat.d.ts +18 -18
- package/lib/cjs/Editing/Mutable/MutableFormat.js +15 -15
- package/lib/cjs/Editing/Mutable/MutableInvertedUnit.d.ts +10 -10
- package/lib/cjs/Editing/Mutable/MutableInvertedUnit.js +15 -15
- package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.d.ts +10 -10
- package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.js +15 -15
- package/lib/cjs/Editing/Mutable/MutableMixin.d.ts +11 -11
- package/lib/cjs/Editing/Mutable/MutableMixin.js +15 -15
- package/lib/cjs/Editing/Mutable/MutablePhenomenon.d.ts +9 -9
- package/lib/cjs/Editing/Mutable/MutablePhenomenon.js +15 -15
- package/lib/cjs/Editing/Mutable/MutableProperty.d.ts +8 -8
- package/lib/cjs/Editing/Mutable/MutableProperty.js +15 -15
- package/lib/cjs/Editing/Mutable/MutablePropertyCategory.d.ts +9 -9
- package/lib/cjs/Editing/Mutable/MutablePropertyCategory.js +15 -15
- package/lib/cjs/Editing/Mutable/MutableRelationshipClass.d.ts +21 -21
- package/lib/cjs/Editing/Mutable/MutableRelationshipClass.js +24 -24
- package/lib/cjs/Editing/Mutable/MutableSchema.d.ts +45 -45
- package/lib/cjs/Editing/Mutable/MutableSchema.js +17 -17
- package/lib/cjs/Editing/Mutable/MutableUnit.d.ts +11 -11
- package/lib/cjs/Editing/Mutable/MutableUnit.js +15 -15
- package/lib/cjs/Editing/Mutable/MutableUnitSystem.d.ts +8 -8
- package/lib/cjs/Editing/Mutable/MutableUnitSystem.js +15 -15
- package/lib/cjs/Editing/Phenomena.d.ts +15 -15
- package/lib/cjs/Editing/Phenomena.js +44 -44
- package/lib/cjs/Editing/PropertyCategories.d.ts +16 -16
- package/lib/cjs/Editing/PropertyCategories.js +51 -51
- package/lib/cjs/Editing/RelationshipClasses.d.ts +21 -21
- package/lib/cjs/Editing/RelationshipClasses.js +68 -68
- package/lib/cjs/Editing/Structs.d.ts +19 -19
- package/lib/cjs/Editing/Structs.js +57 -57
- package/lib/cjs/Editing/UnitSystems.d.ts +15 -15
- package/lib/cjs/Editing/UnitSystems.js +41 -41
- package/lib/cjs/Editing/Units.d.ts +15 -15
- package/lib/cjs/Editing/Units.js +58 -58
- package/lib/cjs/Validation/Diagnostic.d.ts +321 -321
- package/lib/cjs/Validation/Diagnostic.d.ts.map +1 -1
- package/lib/cjs/Validation/Diagnostic.js +310 -310
- package/lib/cjs/Validation/Diagnostic.js.map +1 -1
- package/lib/cjs/Validation/DiagnosticReporter.d.ts +96 -96
- package/lib/cjs/Validation/DiagnosticReporter.js +106 -106
- package/lib/cjs/Validation/ECRules.d.ts +448 -448
- package/lib/cjs/Validation/ECRules.js +593 -593
- package/lib/cjs/Validation/LoggingDiagnosticReporter.d.ts +13 -13
- package/lib/cjs/Validation/LoggingDiagnosticReporter.js +40 -40
- package/lib/cjs/Validation/RuleSuppressionSet.d.ts +59 -59
- package/lib/cjs/Validation/RuleSuppressionSet.d.ts.map +1 -1
- package/lib/cjs/Validation/RuleSuppressionSet.js +9 -9
- package/lib/cjs/Validation/Rules.d.ts +64 -64
- package/lib/cjs/Validation/Rules.d.ts.map +1 -1
- package/lib/cjs/Validation/Rules.js +9 -9
- package/lib/cjs/Validation/SchemaChanges.d.ts +607 -607
- package/lib/cjs/Validation/SchemaChanges.js +1135 -1135
- package/lib/cjs/Validation/SchemaCompareDiagnostics.d.ts +422 -422
- package/lib/cjs/Validation/SchemaCompareDiagnostics.js +111 -111
- package/lib/cjs/Validation/SchemaCompareReporter.d.ts +11 -11
- package/lib/cjs/Validation/SchemaCompareReporter.js +9 -9
- package/lib/cjs/Validation/SchemaCompareResultDelegate.d.ts +236 -236
- package/lib/cjs/Validation/SchemaCompareResultDelegate.js +348 -348
- package/lib/cjs/Validation/SchemaCompareVisitor.d.ts +119 -119
- package/lib/cjs/Validation/SchemaCompareVisitor.js +206 -206
- package/lib/cjs/Validation/SchemaComparer.d.ts +171 -171
- package/lib/cjs/Validation/SchemaComparer.js +666 -666
- package/lib/cjs/Validation/SchemaValidater.d.ts +19 -19
- package/lib/cjs/Validation/SchemaValidater.js +61 -61
- package/lib/cjs/Validation/SchemaValidationVisitor.d.ts +170 -170
- package/lib/cjs/Validation/SchemaValidationVisitor.js +492 -492
- package/lib/cjs/Validation/SchemaWalker.d.ts +22 -22
- package/lib/cjs/Validation/SchemaWalker.js +51 -51
- package/lib/cjs/ecschema-editing.d.ts +33 -33
- package/lib/cjs/ecschema-editing.js +58 -54
- package/lib/cjs/ecschema-editing.js.map +1 -1
- package/package.json +11 -11
|
@@ -1,117 +1,117 @@
|
|
|
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 Editing
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.Entities = void 0;
|
|
11
|
-
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
12
|
-
const ECClasses_1 = require("./ECClasses");
|
|
13
|
-
/**
|
|
14
|
-
* @alpha
|
|
15
|
-
* A class extending ECClasses allowing you to create schema items of type EntityClass.
|
|
16
|
-
*/
|
|
17
|
-
class Entities extends ECClasses_1.ECClasses {
|
|
18
|
-
constructor(_schemaEditor) {
|
|
19
|
-
super(_schemaEditor);
|
|
20
|
-
}
|
|
21
|
-
async createElement(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
|
|
22
|
-
const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);
|
|
23
|
-
if (!baseClass)
|
|
24
|
-
throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could be found.`);
|
|
25
|
-
if (baseClass?.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
|
|
26
|
-
throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);
|
|
27
|
-
if (!(await baseClass.is("Element", "BisCore"))) {
|
|
28
|
-
throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an Element.`);
|
|
29
|
-
}
|
|
30
|
-
return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);
|
|
31
|
-
}
|
|
32
|
-
async createElementUniqueAspect(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
|
|
33
|
-
const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);
|
|
34
|
-
if (!baseClass)
|
|
35
|
-
throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could be found.`);
|
|
36
|
-
if (baseClass?.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
|
|
37
|
-
throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);
|
|
38
|
-
if (!(await baseClass.is("ElementUniqueAspect", "BisCore"))) {
|
|
39
|
-
throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an ElementUniqueAspect.`);
|
|
40
|
-
}
|
|
41
|
-
return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);
|
|
42
|
-
}
|
|
43
|
-
async createElementMultiAspect(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
|
|
44
|
-
const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);
|
|
45
|
-
if (!baseClass)
|
|
46
|
-
throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could be found.`);
|
|
47
|
-
if (baseClass?.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
|
|
48
|
-
throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);
|
|
49
|
-
if (!(await baseClass.is("ElementMultiAspect", "BisCore"))) {
|
|
50
|
-
throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an ElementMultiAspect.`);
|
|
51
|
-
}
|
|
52
|
-
return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);
|
|
53
|
-
}
|
|
54
|
-
async create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins) {
|
|
55
|
-
const schema = await this._schemaEditor.getSchema(schemaKey);
|
|
56
|
-
if (schema === undefined)
|
|
57
|
-
return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
|
|
58
|
-
const newClass = (await schema.createEntityClass(name, modifier));
|
|
59
|
-
if (newClass === undefined)
|
|
60
|
-
return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };
|
|
61
|
-
// Add a deserializing method.
|
|
62
|
-
if (baseClassKey !== undefined) {
|
|
63
|
-
let baseClassSchema = schema;
|
|
64
|
-
if (!baseClassKey.schemaKey.matches(schema.schemaKey))
|
|
65
|
-
baseClassSchema = await this._schemaEditor.getSchema(baseClassKey.schemaKey);
|
|
66
|
-
const baseClassItem = await baseClassSchema.lookupItem(baseClassKey);
|
|
67
|
-
if (baseClassItem === undefined)
|
|
68
|
-
return { errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };
|
|
69
|
-
if (baseClassItem.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
|
|
70
|
-
return { errorMessage: `${baseClassItem.fullName} is not of type Entity Class.` };
|
|
71
|
-
newClass.baseClass = new ecschema_metadata_1.DelayedPromiseWithProps(baseClassKey, async () => baseClassItem);
|
|
72
|
-
}
|
|
73
|
-
if (mixins !== undefined)
|
|
74
|
-
mixins.forEach((m) => newClass.addMixin(m));
|
|
75
|
-
if (displayLabel)
|
|
76
|
-
newClass.setDisplayLabel(displayLabel);
|
|
77
|
-
return { itemKey: newClass.key };
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Creates an EntityClass through an EntityClassProps.
|
|
81
|
-
* @param schemaKey a SchemaKey of the Schema that will house the new object.
|
|
82
|
-
* @param entityProps a json object that will be used to populate the new EntityClass. Needs a name value passed in.
|
|
83
|
-
*/
|
|
84
|
-
async createFromProps(schemaKey, entityProps) {
|
|
85
|
-
const schema = await this._schemaEditor.getSchema(schemaKey);
|
|
86
|
-
if (schema === undefined)
|
|
87
|
-
return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
|
|
88
|
-
if (entityProps.name === undefined)
|
|
89
|
-
return { errorMessage: `No name was supplied within props.` };
|
|
90
|
-
const newClass = (await schema.createEntityClass(entityProps.name));
|
|
91
|
-
if (newClass === undefined)
|
|
92
|
-
return { errorMessage: `Failed to create class ${entityProps.name} in schema ${schemaKey.toString(true)}.` };
|
|
93
|
-
await newClass.fromJSON(entityProps);
|
|
94
|
-
return { itemKey: newClass.key };
|
|
95
|
-
}
|
|
96
|
-
async addMixin(entityKey, mixinKey) {
|
|
97
|
-
const entity = (await this._schemaEditor.schemaContext.getSchemaItem(entityKey));
|
|
98
|
-
const mixin = (await this._schemaEditor.schemaContext.getSchemaItem(mixinKey));
|
|
99
|
-
// TODO: have a helpful returns
|
|
100
|
-
if (!entity || entity.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
|
|
101
|
-
return;
|
|
102
|
-
if (!mixin || mixin.schemaItemType !== ecschema_metadata_1.SchemaItemType.Mixin)
|
|
103
|
-
return;
|
|
104
|
-
entity.addMixin(mixin);
|
|
105
|
-
}
|
|
106
|
-
async createNavigationProperty(entityKey, name, relationship, direction) {
|
|
107
|
-
const entity = (await this._schemaEditor.schemaContext.getSchemaItem(entityKey));
|
|
108
|
-
if (entity === undefined)
|
|
109
|
-
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.ClassNotFound, `Entity Class ${entityKey.fullName} not found in schema context.`);
|
|
110
|
-
if (entity.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
|
|
111
|
-
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaItemType, `Expected ${entityKey.fullName} to be of type Entity Class.`);
|
|
112
|
-
await entity.createNavigationProperty(name, relationship, direction);
|
|
113
|
-
return { itemKey: entityKey, propertyName: name };
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
exports.Entities = Entities;
|
|
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 Editing
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.Entities = void 0;
|
|
11
|
+
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
12
|
+
const ECClasses_1 = require("./ECClasses");
|
|
13
|
+
/**
|
|
14
|
+
* @alpha
|
|
15
|
+
* A class extending ECClasses allowing you to create schema items of type EntityClass.
|
|
16
|
+
*/
|
|
17
|
+
class Entities extends ECClasses_1.ECClasses {
|
|
18
|
+
constructor(_schemaEditor) {
|
|
19
|
+
super(_schemaEditor);
|
|
20
|
+
}
|
|
21
|
+
async createElement(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
|
|
22
|
+
const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);
|
|
23
|
+
if (!baseClass)
|
|
24
|
+
throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could be found.`);
|
|
25
|
+
if (baseClass?.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
|
|
26
|
+
throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);
|
|
27
|
+
if (!(await baseClass.is("Element", "BisCore"))) {
|
|
28
|
+
throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an Element.`);
|
|
29
|
+
}
|
|
30
|
+
return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);
|
|
31
|
+
}
|
|
32
|
+
async createElementUniqueAspect(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
|
|
33
|
+
const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);
|
|
34
|
+
if (!baseClass)
|
|
35
|
+
throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could be found.`);
|
|
36
|
+
if (baseClass?.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
|
|
37
|
+
throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);
|
|
38
|
+
if (!(await baseClass.is("ElementUniqueAspect", "BisCore"))) {
|
|
39
|
+
throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an ElementUniqueAspect.`);
|
|
40
|
+
}
|
|
41
|
+
return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);
|
|
42
|
+
}
|
|
43
|
+
async createElementMultiAspect(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
|
|
44
|
+
const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);
|
|
45
|
+
if (!baseClass)
|
|
46
|
+
throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could be found.`);
|
|
47
|
+
if (baseClass?.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
|
|
48
|
+
throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);
|
|
49
|
+
if (!(await baseClass.is("ElementMultiAspect", "BisCore"))) {
|
|
50
|
+
throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an ElementMultiAspect.`);
|
|
51
|
+
}
|
|
52
|
+
return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);
|
|
53
|
+
}
|
|
54
|
+
async create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins) {
|
|
55
|
+
const schema = await this._schemaEditor.getSchema(schemaKey);
|
|
56
|
+
if (schema === undefined)
|
|
57
|
+
return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
|
|
58
|
+
const newClass = (await schema.createEntityClass(name, modifier));
|
|
59
|
+
if (newClass === undefined)
|
|
60
|
+
return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };
|
|
61
|
+
// Add a deserializing method.
|
|
62
|
+
if (baseClassKey !== undefined) {
|
|
63
|
+
let baseClassSchema = schema;
|
|
64
|
+
if (!baseClassKey.schemaKey.matches(schema.schemaKey))
|
|
65
|
+
baseClassSchema = await this._schemaEditor.getSchema(baseClassKey.schemaKey);
|
|
66
|
+
const baseClassItem = await baseClassSchema.lookupItem(baseClassKey);
|
|
67
|
+
if (baseClassItem === undefined)
|
|
68
|
+
return { errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };
|
|
69
|
+
if (baseClassItem.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
|
|
70
|
+
return { errorMessage: `${baseClassItem.fullName} is not of type Entity Class.` };
|
|
71
|
+
newClass.baseClass = new ecschema_metadata_1.DelayedPromiseWithProps(baseClassKey, async () => baseClassItem);
|
|
72
|
+
}
|
|
73
|
+
if (mixins !== undefined)
|
|
74
|
+
mixins.forEach((m) => newClass.addMixin(m));
|
|
75
|
+
if (displayLabel)
|
|
76
|
+
newClass.setDisplayLabel(displayLabel);
|
|
77
|
+
return { itemKey: newClass.key };
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Creates an EntityClass through an EntityClassProps.
|
|
81
|
+
* @param schemaKey a SchemaKey of the Schema that will house the new object.
|
|
82
|
+
* @param entityProps a json object that will be used to populate the new EntityClass. Needs a name value passed in.
|
|
83
|
+
*/
|
|
84
|
+
async createFromProps(schemaKey, entityProps) {
|
|
85
|
+
const schema = await this._schemaEditor.getSchema(schemaKey);
|
|
86
|
+
if (schema === undefined)
|
|
87
|
+
return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
|
|
88
|
+
if (entityProps.name === undefined)
|
|
89
|
+
return { errorMessage: `No name was supplied within props.` };
|
|
90
|
+
const newClass = (await schema.createEntityClass(entityProps.name));
|
|
91
|
+
if (newClass === undefined)
|
|
92
|
+
return { errorMessage: `Failed to create class ${entityProps.name} in schema ${schemaKey.toString(true)}.` };
|
|
93
|
+
await newClass.fromJSON(entityProps);
|
|
94
|
+
return { itemKey: newClass.key };
|
|
95
|
+
}
|
|
96
|
+
async addMixin(entityKey, mixinKey) {
|
|
97
|
+
const entity = (await this._schemaEditor.schemaContext.getSchemaItem(entityKey));
|
|
98
|
+
const mixin = (await this._schemaEditor.schemaContext.getSchemaItem(mixinKey));
|
|
99
|
+
// TODO: have a helpful returns
|
|
100
|
+
if (!entity || entity.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
|
|
101
|
+
return;
|
|
102
|
+
if (!mixin || mixin.schemaItemType !== ecschema_metadata_1.SchemaItemType.Mixin)
|
|
103
|
+
return;
|
|
104
|
+
entity.addMixin(mixin);
|
|
105
|
+
}
|
|
106
|
+
async createNavigationProperty(entityKey, name, relationship, direction) {
|
|
107
|
+
const entity = (await this._schemaEditor.schemaContext.getSchemaItem(entityKey));
|
|
108
|
+
if (entity === undefined)
|
|
109
|
+
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.ClassNotFound, `Entity Class ${entityKey.fullName} not found in schema context.`);
|
|
110
|
+
if (entity.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
|
|
111
|
+
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaItemType, `Expected ${entityKey.fullName} to be of type Entity Class.`);
|
|
112
|
+
await entity.createNavigationProperty(name, relationship, direction);
|
|
113
|
+
return { itemKey: entityKey, propertyName: name };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.Entities = Entities;
|
|
117
117
|
//# sourceMappingURL=Entities.js.map
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
/** @packageDocumentation
|
|
2
|
-
* @module Editing
|
|
3
|
-
*/
|
|
4
|
-
import { AnyEnumerator, EnumerationProps, PrimitiveType, SchemaItemKey, SchemaKey } from "@itwin/ecschema-metadata";
|
|
5
|
-
import { SchemaContextEditor, SchemaItemEditResults } from "./Editor";
|
|
6
|
-
/**
|
|
7
|
-
* @alpha
|
|
8
|
-
* A class allowing you to create schema items of type Enumeration.
|
|
9
|
-
*/
|
|
10
|
-
export declare class Enumerations {
|
|
11
|
-
protected _schemaEditor: SchemaContextEditor;
|
|
12
|
-
constructor(_schemaEditor: SchemaContextEditor);
|
|
13
|
-
create(schemaKey: SchemaKey, name: string, type: PrimitiveType.Integer | PrimitiveType.String, displayLabel?: string, isStrict?: boolean, enumerators?: AnyEnumerator[]): Promise<SchemaItemEditResults>;
|
|
14
|
-
/**
|
|
15
|
-
* Creates an Enumeration through an EnumeratorProps.
|
|
16
|
-
* @param schemaKey a SchemaKey of the Schema that will house the new object.
|
|
17
|
-
* @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.
|
|
18
|
-
*/
|
|
19
|
-
createFromProps(schemaKey: SchemaKey, enumProps: EnumerationProps): Promise<SchemaItemEditResults>;
|
|
20
|
-
addEnumerator(enumerationKey: SchemaItemKey, enumerator: AnyEnumerator): Promise<void>;
|
|
21
|
-
}
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Editing
|
|
3
|
+
*/
|
|
4
|
+
import { AnyEnumerator, EnumerationProps, PrimitiveType, SchemaItemKey, SchemaKey } from "@itwin/ecschema-metadata";
|
|
5
|
+
import { SchemaContextEditor, SchemaItemEditResults } from "./Editor";
|
|
6
|
+
/**
|
|
7
|
+
* @alpha
|
|
8
|
+
* A class allowing you to create schema items of type Enumeration.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Enumerations {
|
|
11
|
+
protected _schemaEditor: SchemaContextEditor;
|
|
12
|
+
constructor(_schemaEditor: SchemaContextEditor);
|
|
13
|
+
create(schemaKey: SchemaKey, name: string, type: PrimitiveType.Integer | PrimitiveType.String, displayLabel?: string, isStrict?: boolean, enumerators?: AnyEnumerator[]): Promise<SchemaItemEditResults>;
|
|
14
|
+
/**
|
|
15
|
+
* Creates an Enumeration through an EnumeratorProps.
|
|
16
|
+
* @param schemaKey a SchemaKey of the Schema that will house the new object.
|
|
17
|
+
* @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.
|
|
18
|
+
*/
|
|
19
|
+
createFromProps(schemaKey: SchemaKey, enumProps: EnumerationProps): Promise<SchemaItemEditResults>;
|
|
20
|
+
addEnumerator(enumerationKey: SchemaItemKey, enumerator: AnyEnumerator): Promise<void>;
|
|
21
|
+
}
|
|
22
22
|
//# sourceMappingURL=Enumerations.d.ts.map
|
|
@@ -1,67 +1,67 @@
|
|
|
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 Editing
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.Enumerations = void 0;
|
|
11
|
-
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
12
|
-
/**
|
|
13
|
-
* @alpha
|
|
14
|
-
* A class allowing you to create schema items of type Enumeration.
|
|
15
|
-
*/
|
|
16
|
-
class Enumerations {
|
|
17
|
-
constructor(_schemaEditor) {
|
|
18
|
-
this._schemaEditor = _schemaEditor;
|
|
19
|
-
}
|
|
20
|
-
async create(schemaKey, name, type, displayLabel, isStrict, enumerators) {
|
|
21
|
-
const schema = await this._schemaEditor.getSchema(schemaKey);
|
|
22
|
-
if (schema === undefined)
|
|
23
|
-
return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
|
|
24
|
-
const newEnum = (await schema.createEnumeration(name, type));
|
|
25
|
-
if (newEnum === undefined)
|
|
26
|
-
return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };
|
|
27
|
-
if (undefined !== isStrict)
|
|
28
|
-
newEnum.setIsStrict(isStrict);
|
|
29
|
-
if (undefined !== enumerators)
|
|
30
|
-
for (const enumerator of enumerators)
|
|
31
|
-
await this.addEnumerator(newEnum.key, enumerator);
|
|
32
|
-
if (displayLabel)
|
|
33
|
-
newEnum.setDisplayLabel(displayLabel);
|
|
34
|
-
return { itemKey: newEnum.key };
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Creates an Enumeration through an EnumeratorProps.
|
|
38
|
-
* @param schemaKey a SchemaKey of the Schema that will house the new object.
|
|
39
|
-
* @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.
|
|
40
|
-
*/
|
|
41
|
-
async createFromProps(schemaKey, enumProps) {
|
|
42
|
-
const schema = await this._schemaEditor.getSchema(schemaKey);
|
|
43
|
-
if (schema === undefined)
|
|
44
|
-
return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
|
|
45
|
-
if (enumProps.name === undefined)
|
|
46
|
-
return { errorMessage: `No name was supplied within props.` };
|
|
47
|
-
const newEnum = (await schema.createEnumeration(enumProps.name));
|
|
48
|
-
if (newEnum === undefined)
|
|
49
|
-
return { errorMessage: `Failed to create class ${enumProps.name} in schema ${schemaKey.toString(true)}.` };
|
|
50
|
-
await newEnum.fromJSON(enumProps);
|
|
51
|
-
return { itemKey: newEnum.key };
|
|
52
|
-
}
|
|
53
|
-
async addEnumerator(enumerationKey, enumerator) {
|
|
54
|
-
const enumeration = (await this._schemaEditor.schemaContext.getSchemaItem(enumerationKey));
|
|
55
|
-
if (enumeration === undefined)
|
|
56
|
-
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.ClassNotFound, `Unable to locate Enumeration class ${enumerationKey.fullName}.`);
|
|
57
|
-
if (enumeration.schemaItemType !== ecschema_metadata_1.SchemaItemType.Enumeration)
|
|
58
|
-
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidType, `${enumeration.fullName} is not of type Enumerator class.`);
|
|
59
|
-
if (enumeration.isInt && typeof (enumerator.value) !== "number")
|
|
60
|
-
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidPrimitiveType, `The Enumeration ${enumeration.name} has type integer, while ${enumerator.name} has type ${typeof (enumerator.value)}.`);
|
|
61
|
-
if (enumeration.isString && typeof (enumerator.value) !== "string")
|
|
62
|
-
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidPrimitiveType, `The Enumeration ${enumeration.name} has type string, while ${enumerator.name} has type ${typeof (enumerator.value)}.`);
|
|
63
|
-
enumeration.addEnumerator(enumerator);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
exports.Enumerations = Enumerations;
|
|
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 Editing
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.Enumerations = void 0;
|
|
11
|
+
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
12
|
+
/**
|
|
13
|
+
* @alpha
|
|
14
|
+
* A class allowing you to create schema items of type Enumeration.
|
|
15
|
+
*/
|
|
16
|
+
class Enumerations {
|
|
17
|
+
constructor(_schemaEditor) {
|
|
18
|
+
this._schemaEditor = _schemaEditor;
|
|
19
|
+
}
|
|
20
|
+
async create(schemaKey, name, type, displayLabel, isStrict, enumerators) {
|
|
21
|
+
const schema = await this._schemaEditor.getSchema(schemaKey);
|
|
22
|
+
if (schema === undefined)
|
|
23
|
+
return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
|
|
24
|
+
const newEnum = (await schema.createEnumeration(name, type));
|
|
25
|
+
if (newEnum === undefined)
|
|
26
|
+
return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };
|
|
27
|
+
if (undefined !== isStrict)
|
|
28
|
+
newEnum.setIsStrict(isStrict);
|
|
29
|
+
if (undefined !== enumerators)
|
|
30
|
+
for (const enumerator of enumerators)
|
|
31
|
+
await this.addEnumerator(newEnum.key, enumerator);
|
|
32
|
+
if (displayLabel)
|
|
33
|
+
newEnum.setDisplayLabel(displayLabel);
|
|
34
|
+
return { itemKey: newEnum.key };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Creates an Enumeration through an EnumeratorProps.
|
|
38
|
+
* @param schemaKey a SchemaKey of the Schema that will house the new object.
|
|
39
|
+
* @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.
|
|
40
|
+
*/
|
|
41
|
+
async createFromProps(schemaKey, enumProps) {
|
|
42
|
+
const schema = await this._schemaEditor.getSchema(schemaKey);
|
|
43
|
+
if (schema === undefined)
|
|
44
|
+
return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
|
|
45
|
+
if (enumProps.name === undefined)
|
|
46
|
+
return { errorMessage: `No name was supplied within props.` };
|
|
47
|
+
const newEnum = (await schema.createEnumeration(enumProps.name));
|
|
48
|
+
if (newEnum === undefined)
|
|
49
|
+
return { errorMessage: `Failed to create class ${enumProps.name} in schema ${schemaKey.toString(true)}.` };
|
|
50
|
+
await newEnum.fromJSON(enumProps);
|
|
51
|
+
return { itemKey: newEnum.key };
|
|
52
|
+
}
|
|
53
|
+
async addEnumerator(enumerationKey, enumerator) {
|
|
54
|
+
const enumeration = (await this._schemaEditor.schemaContext.getSchemaItem(enumerationKey));
|
|
55
|
+
if (enumeration === undefined)
|
|
56
|
+
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.ClassNotFound, `Unable to locate Enumeration class ${enumerationKey.fullName}.`);
|
|
57
|
+
if (enumeration.schemaItemType !== ecschema_metadata_1.SchemaItemType.Enumeration)
|
|
58
|
+
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidType, `${enumeration.fullName} is not of type Enumerator class.`);
|
|
59
|
+
if (enumeration.isInt && typeof (enumerator.value) !== "number")
|
|
60
|
+
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidPrimitiveType, `The Enumeration ${enumeration.name} has type integer, while ${enumerator.name} has type ${typeof (enumerator.value)}.`);
|
|
61
|
+
if (enumeration.isString && typeof (enumerator.value) !== "string")
|
|
62
|
+
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidPrimitiveType, `The Enumeration ${enumeration.name} has type string, while ${enumerator.name} has type ${typeof (enumerator.value)}.`);
|
|
63
|
+
enumeration.addEnumerator(enumerator);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.Enumerations = Enumerations;
|
|
67
67
|
//# sourceMappingURL=Enumerations.js.map
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
/** @packageDocumentation
|
|
2
|
-
* @module Editing
|
|
3
|
-
*/
|
|
4
|
-
import { FormatProps, SchemaItemKey, SchemaKey } from "@itwin/ecschema-metadata";
|
|
5
|
-
import { FormatType } from "@itwin/core-quantity";
|
|
6
|
-
import { SchemaContextEditor, SchemaItemEditResults } from "./Editor";
|
|
7
|
-
/**
|
|
8
|
-
* @alpha
|
|
9
|
-
* A class allowing you to create schema items of type Format.
|
|
10
|
-
*/
|
|
11
|
-
export declare class Formats {
|
|
12
|
-
protected _schemaEditor: SchemaContextEditor;
|
|
13
|
-
constructor(_schemaEditor: SchemaContextEditor);
|
|
14
|
-
create(schemaKey: SchemaKey, name: string, formatType: FormatType, displayLabel?: string, units?: SchemaItemKey[]): Promise<SchemaItemEditResults>;
|
|
15
|
-
/**
|
|
16
|
-
* Creates a format through a FormatProps.
|
|
17
|
-
* @param schemaKey a SchemaKey of the Schema that will house the new object.
|
|
18
|
-
* @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.
|
|
19
|
-
*/
|
|
20
|
-
createFromProps(schemaKey: SchemaKey, formatProps: FormatProps): Promise<SchemaItemEditResults>;
|
|
21
|
-
}
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Editing
|
|
3
|
+
*/
|
|
4
|
+
import { FormatProps, SchemaItemKey, SchemaKey } from "@itwin/ecschema-metadata";
|
|
5
|
+
import { FormatType } from "@itwin/core-quantity";
|
|
6
|
+
import { SchemaContextEditor, SchemaItemEditResults } from "./Editor";
|
|
7
|
+
/**
|
|
8
|
+
* @alpha
|
|
9
|
+
* A class allowing you to create schema items of type Format.
|
|
10
|
+
*/
|
|
11
|
+
export declare class Formats {
|
|
12
|
+
protected _schemaEditor: SchemaContextEditor;
|
|
13
|
+
constructor(_schemaEditor: SchemaContextEditor);
|
|
14
|
+
create(schemaKey: SchemaKey, name: string, formatType: FormatType, displayLabel?: string, units?: SchemaItemKey[]): Promise<SchemaItemEditResults>;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a format through a FormatProps.
|
|
17
|
+
* @param schemaKey a SchemaKey of the Schema that will house the new object.
|
|
18
|
+
* @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.
|
|
19
|
+
*/
|
|
20
|
+
createFromProps(schemaKey: SchemaKey, formatProps: FormatProps): Promise<SchemaItemEditResults>;
|
|
21
|
+
}
|
|
22
22
|
//# sourceMappingURL=Formats.d.ts.map
|
|
@@ -1,62 +1,62 @@
|
|
|
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 Editing
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.Formats = void 0;
|
|
11
|
-
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
12
|
-
/**
|
|
13
|
-
* @alpha
|
|
14
|
-
* A class allowing you to create schema items of type Format.
|
|
15
|
-
*/
|
|
16
|
-
class Formats {
|
|
17
|
-
constructor(_schemaEditor) {
|
|
18
|
-
this._schemaEditor = _schemaEditor;
|
|
19
|
-
}
|
|
20
|
-
async create(schemaKey, name, formatType, displayLabel, units) {
|
|
21
|
-
const schema = await this._schemaEditor.getSchema(schemaKey);
|
|
22
|
-
const newFormat = (await schema.createFormat(name));
|
|
23
|
-
if (newFormat === undefined) {
|
|
24
|
-
return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };
|
|
25
|
-
}
|
|
26
|
-
if (units !== undefined) {
|
|
27
|
-
for (const unit of units) {
|
|
28
|
-
const unitItem = await this._schemaEditor.schemaContext.getSchemaItem(unit);
|
|
29
|
-
if (unitItem === undefined) {
|
|
30
|
-
return { errorMessage: `Failed to locate unit ${unit.name} in Schema Context.` };
|
|
31
|
-
}
|
|
32
|
-
if (unitItem.schemaItemType !== ecschema_metadata_1.SchemaItemType.Unit && unitItem.schemaItemType !== ecschema_metadata_1.SchemaItemType.InvertedUnit)
|
|
33
|
-
return { errorMessage: `${unitItem.fullName} is not of type Unit or InvertedUnit.` };
|
|
34
|
-
newFormat.addUnit(unitItem);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (displayLabel)
|
|
38
|
-
newFormat.setDisplayLabel(displayLabel);
|
|
39
|
-
// TODO: Handle the setting of format traits, separators, etc....
|
|
40
|
-
newFormat.setFormatType(formatType);
|
|
41
|
-
return { itemKey: newFormat.key };
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Creates a format through a FormatProps.
|
|
45
|
-
* @param schemaKey a SchemaKey of the Schema that will house the new object.
|
|
46
|
-
* @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.
|
|
47
|
-
*/
|
|
48
|
-
async createFromProps(schemaKey, formatProps) {
|
|
49
|
-
const schema = await this._schemaEditor.getSchema(schemaKey);
|
|
50
|
-
if (schema === undefined)
|
|
51
|
-
return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
|
|
52
|
-
if (formatProps.name === undefined)
|
|
53
|
-
return { errorMessage: `No name was supplied within props.` };
|
|
54
|
-
const newFormat = (await schema.createFormat(formatProps.name));
|
|
55
|
-
if (newFormat === undefined)
|
|
56
|
-
return { errorMessage: `Failed to create class ${formatProps.name} in schema ${schemaKey.toString(true)}.` };
|
|
57
|
-
await newFormat.fromJSON(formatProps);
|
|
58
|
-
return { itemKey: newFormat.key };
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
exports.Formats = Formats;
|
|
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 Editing
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.Formats = void 0;
|
|
11
|
+
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
12
|
+
/**
|
|
13
|
+
* @alpha
|
|
14
|
+
* A class allowing you to create schema items of type Format.
|
|
15
|
+
*/
|
|
16
|
+
class Formats {
|
|
17
|
+
constructor(_schemaEditor) {
|
|
18
|
+
this._schemaEditor = _schemaEditor;
|
|
19
|
+
}
|
|
20
|
+
async create(schemaKey, name, formatType, displayLabel, units) {
|
|
21
|
+
const schema = await this._schemaEditor.getSchema(schemaKey);
|
|
22
|
+
const newFormat = (await schema.createFormat(name));
|
|
23
|
+
if (newFormat === undefined) {
|
|
24
|
+
return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };
|
|
25
|
+
}
|
|
26
|
+
if (units !== undefined) {
|
|
27
|
+
for (const unit of units) {
|
|
28
|
+
const unitItem = await this._schemaEditor.schemaContext.getSchemaItem(unit);
|
|
29
|
+
if (unitItem === undefined) {
|
|
30
|
+
return { errorMessage: `Failed to locate unit ${unit.name} in Schema Context.` };
|
|
31
|
+
}
|
|
32
|
+
if (unitItem.schemaItemType !== ecschema_metadata_1.SchemaItemType.Unit && unitItem.schemaItemType !== ecschema_metadata_1.SchemaItemType.InvertedUnit)
|
|
33
|
+
return { errorMessage: `${unitItem.fullName} is not of type Unit or InvertedUnit.` };
|
|
34
|
+
newFormat.addUnit(unitItem);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (displayLabel)
|
|
38
|
+
newFormat.setDisplayLabel(displayLabel);
|
|
39
|
+
// TODO: Handle the setting of format traits, separators, etc....
|
|
40
|
+
newFormat.setFormatType(formatType);
|
|
41
|
+
return { itemKey: newFormat.key };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates a format through a FormatProps.
|
|
45
|
+
* @param schemaKey a SchemaKey of the Schema that will house the new object.
|
|
46
|
+
* @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.
|
|
47
|
+
*/
|
|
48
|
+
async createFromProps(schemaKey, formatProps) {
|
|
49
|
+
const schema = await this._schemaEditor.getSchema(schemaKey);
|
|
50
|
+
if (schema === undefined)
|
|
51
|
+
return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
|
|
52
|
+
if (formatProps.name === undefined)
|
|
53
|
+
return { errorMessage: `No name was supplied within props.` };
|
|
54
|
+
const newFormat = (await schema.createFormat(formatProps.name));
|
|
55
|
+
if (newFormat === undefined)
|
|
56
|
+
return { errorMessage: `Failed to create class ${formatProps.name} in schema ${schemaKey.toString(true)}.` };
|
|
57
|
+
await newFormat.fromJSON(formatProps);
|
|
58
|
+
return { itemKey: newFormat.key };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.Formats = Formats;
|
|
62
62
|
//# sourceMappingURL=Formats.js.map
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/** @packageDocumentation
|
|
2
|
-
* @module Editing
|
|
3
|
-
*/
|
|
4
|
-
import { InvertedUnitProps, SchemaItemKey, SchemaKey } from "@itwin/ecschema-metadata";
|
|
5
|
-
import { SchemaContextEditor, SchemaItemEditResults } from "./Editor";
|
|
6
|
-
/**
|
|
7
|
-
* @alpha
|
|
8
|
-
* A class allowing you to create schema items of type Inverted Unit.
|
|
9
|
-
*/
|
|
10
|
-
export declare class InvertedUnits {
|
|
11
|
-
protected _schemaEditor: SchemaContextEditor;
|
|
12
|
-
constructor(_schemaEditor: SchemaContextEditor);
|
|
13
|
-
create(schemaKey: SchemaKey, name: string, invertsUnitKey: SchemaItemKey, unitSystemKey: SchemaItemKey, displayLabel?: string): Promise<SchemaItemEditResults>;
|
|
14
|
-
createFromProps(schemaKey: SchemaKey, invertedUnitProps: InvertedUnitProps): Promise<SchemaItemEditResults>;
|
|
15
|
-
setInvertsUnit(invertedUnitKey: SchemaItemKey, invertsUnitKey: SchemaItemKey): Promise<void>;
|
|
16
|
-
setUnitSystem(invertedUnitKey: SchemaItemKey, unitSystemKey: SchemaItemKey): Promise<void>;
|
|
17
|
-
}
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Editing
|
|
3
|
+
*/
|
|
4
|
+
import { InvertedUnitProps, SchemaItemKey, SchemaKey } from "@itwin/ecschema-metadata";
|
|
5
|
+
import { SchemaContextEditor, SchemaItemEditResults } from "./Editor";
|
|
6
|
+
/**
|
|
7
|
+
* @alpha
|
|
8
|
+
* A class allowing you to create schema items of type Inverted Unit.
|
|
9
|
+
*/
|
|
10
|
+
export declare class InvertedUnits {
|
|
11
|
+
protected _schemaEditor: SchemaContextEditor;
|
|
12
|
+
constructor(_schemaEditor: SchemaContextEditor);
|
|
13
|
+
create(schemaKey: SchemaKey, name: string, invertsUnitKey: SchemaItemKey, unitSystemKey: SchemaItemKey, displayLabel?: string): Promise<SchemaItemEditResults>;
|
|
14
|
+
createFromProps(schemaKey: SchemaKey, invertedUnitProps: InvertedUnitProps): Promise<SchemaItemEditResults>;
|
|
15
|
+
setInvertsUnit(invertedUnitKey: SchemaItemKey, invertsUnitKey: SchemaItemKey): Promise<void>;
|
|
16
|
+
setUnitSystem(invertedUnitKey: SchemaItemKey, unitSystemKey: SchemaItemKey): Promise<void>;
|
|
17
|
+
}
|
|
18
18
|
//# sourceMappingURL=InvertedUnits.d.ts.map
|