Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/api/ecschema-metadata.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2215,7 +2215,7 @@ export class SchemaReadHelper<T = unknown> {
constructor(parserType: AbstractParserConstructor<T>, context?: SchemaContext, visitor?: ISchemaPartVisitor);
// (undocumented)
static isECSpecVersionNewer(ecSpecVersion?: ECSpecVersion): boolean;
protected isSchemaItemLoaded(schemaItem: SchemaItem | undefined): boolean;
protected isSchemaItemLoaded(schemaItem: SchemaItem | undefined): schemaItem is SchemaItem;
protected loadCustomAttributes(container: AnyCAContainer, caProviders: Iterable<CAProviderTuple>): Promise<void>;
protected loadSchemaItem(schema: Schema, name: string, itemType: string, schemaItemObject?: Readonly<unknown>): Promise<SchemaItem | undefined>;
readSchema(schema: Schema, rawSchema: T, addSchemaToCache?: boolean): Promise<Schema>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/ecschema-editing",
"comment": "",
"type": "none"
}
],
"packageName": "@itwin/ecschema-editing"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/ecschema-locaters",
"comment": "",
"type": "none"
}
],
"packageName": "@itwin/ecschema-locaters"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/ecschema-metadata",
"comment": "",
"type": "none"
}
],
"packageName": "@itwin/ecschema-metadata"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/ecsql-common",
"comment": "",
"type": "none"
}
],
"packageName": "@itwin/ecsql-common"
}
2 changes: 1 addition & 1 deletion core/ecschema-editing/src/Editing/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class Constants extends SchemaItems {
const newConstant = await this.createSchemaItemFromProps(schemaKey, this.schemaItemType, (schema) => schema.createConstant.bind(schema), constantProps);
return newConstant.key;
} catch (e: any) {
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new SchemaItemId(this.schemaItemType, constantProps.name!, schemaKey), e);
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new SchemaItemId(this.schemaItemType, constantProps.name ?? "<unknown>", schemaKey), e);
}
}
}
2 changes: 1 addition & 1 deletion core/ecschema-editing/src/Editing/CustomAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class CustomAttributes extends ECClasses {
const newClass = await this.createSchemaItemFromProps(schemaKey, this.schemaItemType, (schema) => schema.createCustomAttributeClass.bind(schema), caProps);
return newClass.key;
} catch (e: any) {
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new ClassId(this.schemaItemType, caProps.name!, schemaKey), e);
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new ClassId(this.schemaItemType, caProps.name ?? "<unknown>", schemaKey), e);
}
}
}
2 changes: 1 addition & 1 deletion core/ecschema-editing/src/Editing/Entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class Entities extends ECClasses {
const newClass = await this.createSchemaItemFromProps(schemaKey, this.schemaItemType, (schema) => schema.createEntityClass.bind(schema), entityProps);
return newClass.key;
} catch (e: any) {
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new ClassId(this.schemaItemType, entityProps.name!, schemaKey), e);
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new ClassId(this.schemaItemType, entityProps.name ?? "<unknown>", schemaKey), e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/ecschema-editing/src/Editing/Enumerations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class Enumerations extends SchemaItems {
const newEnum = await this.createSchemaItemFromProps(schemaKey, this.schemaItemType, (schema) => schema.createEnumeration.bind(schema), enumProps);
return newEnum.key;
} catch (e: any) {
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new SchemaItemId(this.schemaItemType, enumProps.name!, schemaKey), e);
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new SchemaItemId(this.schemaItemType, enumProps.name ?? "<unknown>", schemaKey), e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/ecschema-editing/src/Editing/Exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export class SchemaItemId implements ISchemaItemIdentifier {
if (!schemaKey)
throw new Error("schemaKey if required if the specified schemaItem the name of the schema item.");

this.schemaKey = schemaKey!;
this.schemaKey = schemaKey;
this.schemaItemKey = new SchemaItemKey(schemaItemKeyOrName, schemaKey);
} else {
this.schemaKey = schemaItemKeyOrName.schemaKey;
Expand Down
2 changes: 1 addition & 1 deletion core/ecschema-editing/src/Editing/Formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class Formats extends SchemaItems {
const newFormat = await this.createSchemaItemFromProps(schemaKey, this.schemaItemType, (schema) => schema.createFormat.bind(schema), formatProps);
return newFormat.key;
} catch (e: any) {
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new SchemaItemId(this.schemaItemType, formatProps.name!, schemaKey), e);
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new SchemaItemId(this.schemaItemType, formatProps.name ?? "<unknown>", schemaKey), e);
}
}
}
2 changes: 1 addition & 1 deletion core/ecschema-editing/src/Editing/InvertedUnits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class InvertedUnits extends SchemaItems {
const newUnit = await this.createSchemaItemFromProps(schemaKey, this.schemaItemType, (schema) => schema.createInvertedUnit.bind(schema), invertedUnitProps);
return newUnit.key;
} catch (e: any) {
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new SchemaItemId(this.schemaItemType, invertedUnitProps.name!, schemaKey), e);
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new SchemaItemId(this.schemaItemType, invertedUnitProps.name ?? "<unknown>", schemaKey), e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/ecschema-editing/src/Editing/KindOfQuantities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class KindOfQuantities extends SchemaItems {
const koqItem = await this.createSchemaItemFromProps(schemaKey, this.schemaItemType, (schema) => schema.createKindOfQuantity.bind(schema), koqProps);
return koqItem.key;
} catch (e: any) {
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new SchemaItemId(this.schemaItemType, koqProps.name!, schemaKey), e);
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new SchemaItemId(this.schemaItemType, koqProps.name ?? "<unknown>", schemaKey), e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/ecschema-editing/src/Editing/Mixins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class Mixins extends ECClasses {
const newClass = await this.createSchemaItemFromProps(schemaKey, this.schemaItemType, (schema) => schema.createMixinClass.bind(schema), mixinProps);
return newClass.key;
} catch (e: any) {
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new ClassId(this.schemaItemType, mixinProps.name!, schemaKey), e);
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new ClassId(this.schemaItemType, mixinProps.name ?? "<unknown>", schemaKey), e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/ecschema-editing/src/Editing/Phenomena.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Phenomena extends SchemaItems {
const newPhenomenon = await this.createSchemaItemFromProps(schemaKey, this.schemaItemType, (schema) => schema.createPhenomenon.bind(schema), phenomenonProps);
return newPhenomenon.key;
} catch (e: any) {
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new SchemaItemId(this.schemaItemType, phenomenonProps.name!, schemaKey), e);
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new SchemaItemId(this.schemaItemType, phenomenonProps.name ?? "<unknown>", schemaKey), e);
}
}
}
2 changes: 1 addition & 1 deletion core/ecschema-editing/src/Editing/PropertyCategories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class PropertyCategories extends SchemaItems {
const newPropCategory = await this.createSchemaItemFromProps(schemaKey, this.schemaItemType, (schema) => schema.createPropertyCategory.bind(schema), propertyCategoryProps);
return newPropCategory.key;
} catch (e: any) {
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new SchemaItemId(this.schemaItemType, propertyCategoryProps.name!, schemaKey), e);
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new SchemaItemId(this.schemaItemType, propertyCategoryProps.name ?? "<unknown>", schemaKey), e);
}
}

Expand Down
13 changes: 9 additions & 4 deletions core/ecschema-editing/src/Editing/RelationshipClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class RelationshipClasses extends ECClasses {

return newClass.key;
} catch (e: any) {
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new ClassId(this.schemaItemType, relationshipProps.name!, schemaKey), e);
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new ClassId(this.schemaItemType, relationshipProps.name ?? "<unknown>", schemaKey), e);
}
}

Expand All @@ -116,14 +116,19 @@ export class RelationshipClasses extends ECClasses {
.catch((e) => {
throw new SchemaEditingError(ECEditingStatus.SetBaseClass, new ClassId(this.schemaItemType, itemKey), e);
});
const baseClass = relClass?.baseClass;

if (!relClass) {
throw new SchemaEditingError(ECEditingStatus.SetBaseClass, new ClassId(SchemaItemType.RelationshipClass, itemKey), new SchemaEditingError(ECEditingStatus.SchemaItemNotFoundInContext, new ClassId(this.schemaItemType, itemKey)));
}

const baseClass = relClass.baseClass;

await super.setBaseClass(itemKey, baseClassKey);

try {
await this.validate(relClass!);
await this.validate(relClass);
} catch(e: any) {
await (relClass! as ECClass as MutableClass).setBaseClass(baseClass);
await (relClass as ECClass as MutableClass).setBaseClass(baseClass);
throw new SchemaEditingError(ECEditingStatus.SetBaseClass, new ClassId(SchemaItemType.RelationshipClass, itemKey), e);
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/ecschema-editing/src/Editing/Structs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class Structs extends ECClasses {
const newClass = await this.createSchemaItemFromProps(schemaKey, this.schemaItemType, (schema) => schema.createStructClass.bind(schema), structProps);
return newClass.key;
} catch (e: any) {
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new ClassId(this.schemaItemType, structProps.name!, schemaKey), e);
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new ClassId(this.schemaItemType, structProps.name ?? "<unknown>", schemaKey), e);
}
}
}
2 changes: 1 addition & 1 deletion core/ecschema-editing/src/Editing/UnitSystems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class UnitSystems extends SchemaItems {
const newUnitSystem = await this.createSchemaItemFromProps(schemaKey, this.schemaItemType, (schema) => schema.createUnitSystem.bind(schema), unitSystemProps);
return newUnitSystem.key;
} catch (e: any) {
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new SchemaItemId(this.schemaItemType, unitSystemProps.name!, schemaKey), e);
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new SchemaItemId(this.schemaItemType, unitSystemProps.name ?? "<unknown>", schemaKey), e);
}
}
}
2 changes: 1 addition & 1 deletion core/ecschema-editing/src/Editing/Units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class Units extends SchemaItems {
const newUnit = await this.createSchemaItemFromProps(schemaKey, this.schemaItemType, (schema) => schema.createUnit.bind(schema), unitProps);
return newUnit.key;
} catch (e: any) {
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new SchemaItemId(this.schemaItemType, unitProps.name!, schemaKey), e);
throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new SchemaItemId(this.schemaItemType, unitProps.name ?? "<unknown>", schemaKey), e);
}
}
}
2 changes: 1 addition & 1 deletion core/ecschema-editing/src/Merging/EnumerationMerger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function addEnumeration(context: SchemaMergeContext, change: Enumer
export async function modifyEnumeration(context: SchemaMergeContext, change: EnumerationDifference, itemKey: SchemaItemKey) {
const enumeration = await context.targetSchema.lookupItem(itemKey) as MutableEnumeration;
if(change.difference.type !== undefined) {
throw new Error(`The Enumeration ${itemKey.name} has an incompatible type. It must be "${primitiveTypeToString(enumeration.type!)}", not "${change.difference.type}".`);
throw new Error(`The Enumeration ${itemKey.name} has an incompatible type. It must be "${enumeration.type ? primitiveTypeToString(enumeration.type) : "<unknown>"}", not "${change.difference.type}".`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the underlying Enumeration._type property possibly undefined? Any valid enumeration MUST have a type set so we should not force callers to test if the type is null.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ColinKerr The constructor also has this as optional. It's internal so we can change this. Should we require the parameter or have a default (int or string)?

}
if(change.difference.label !== undefined) {
await context.editor.enumerations.setDisplayLabel(itemKey, change.difference.label);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export async function mergeRelationshipConstraint(context: SchemaMergeContext, c
*/
export async function mergeRelationshipClassConstraint(context: SchemaMergeContext, change: RelationshipConstraintClassDifference): Promise<void> {
if(change.changeType !== "add") {
throw new Error(`Change type ${change.changeType} is not supported for Relationship constraint classes.`);
throw new Error(`Change type ${String(change.changeType)} is not supported for Relationship constraint classes.`);
}

const item = await locateSchemaItem(context, change.itemName, SchemaItemType.RelationshipClass) as MutableRelationshipClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function modifySchemaReferences(context: SchemaMergeContext, change
}

if(!latest.matches(older, SchemaMatchType.LatestWriteCompatible)) {
throw new Error(`Schemas references of ${change.difference.name} have incompatible versions: ${older.version} and ${latest.version}`);
throw new Error(`Schemas references of ${change.difference.name} have incompatible versions: ${older.version.toString()} and ${latest.version.toString()}`);
}

const index = context.targetSchema.references.findIndex((reference) => reference === existingSchema);
Expand Down
8 changes: 3 additions & 5 deletions core/ecschema-editing/src/Validation/DiagnosticReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,9 @@ export abstract class SuppressionDiagnosticReporter implements IDiagnosticReport
* @param diagnostic The diagnostic to report.
*/
public report(diagnostic: AnyDiagnostic) {
if (this._suppressions && this._suppressions.has(diagnostic.schema.fullName)) {
const suppressedCodes = this._suppressions.get(diagnostic.schema.fullName);
if (suppressedCodes!.includes(diagnostic.code))
return;
}
const suppressedCodes = this._suppressions ? this._suppressions.get(diagnostic.schema.fullName) : undefined;
if (suppressedCodes && suppressedCodes.includes(diagnostic.code))
return;

this.reportInternal(diagnostic);
}
Expand Down
10 changes: 5 additions & 5 deletions core/ecschema-editing/src/Validation/ECRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,10 @@ export async function* incompatibleValueTypePropertyOverride(property: AnyProper
return;

const primitiveType = getPrimitiveType(property);
if (!primitiveType)
if (undefined === primitiveType)
return;

async function callback(baseClass: ECClass): Promise<PropertyDiagnostic<any[]> | undefined> {
async function callback(baseClass: ECClass, childType: PrimitiveType): Promise<PropertyDiagnostic<any[]> | undefined> {
const baseProperty = await baseClass.getProperty(property.name, true);
if (!baseProperty)
return;
Expand All @@ -325,14 +325,14 @@ export async function* incompatibleValueTypePropertyOverride(property: AnyProper
const baseType = getPrimitiveType(baseProperty);

// Return if rule passed
if (!baseType || primitiveType === baseType)
if (!baseType || childType === baseType)
return;

return new Diagnostics.IncompatibleValueTypePropertyOverride(property, [property.class.fullName, property.name, baseClass.fullName, primitiveTypeToString(baseType), primitiveTypeToString(primitiveType!)]);
return new Diagnostics.IncompatibleValueTypePropertyOverride(property, [property.class.fullName, property.name, baseClass.fullName, primitiveTypeToString(baseType), primitiveTypeToString(childType)]);
}

for await (const baseClass of property.class.getAllBaseClasses()) {
const result = await callback(baseClass);
const result = await callback(baseClass, primitiveType);
if (result)
yield result;
}
Expand Down
Loading
Loading