@itwin/ecschema-metadata
Version:
ECObjects core concepts in typescript
104 lines • 4.49 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { containerTypeToString, CustomAttributeContainerType } from "../ECObjects";
import { SchemaItemParser } from "./SchemaItemParsers";
import { parseCustomAttribute } from "./SchemaParser";
/**
* Parses ClassProps JSON returned from an ECSql query and returns the correct ClassProps JSON.
* This is necessary as a small amount information (ie. CustomAttribute data) returned from the
* iModelDb is in a different format than is required for a ClassProps JSON object.
* @internal
*/
export class ClassParser extends SchemaItemParser {
/**
* Parses the given ClassProps JSON returned from an ECSql query.
* @param data The ClassProps JSON as returned from an iModelDb.
* @returns The corrected ClassProps Json.
*/
async parse(data) {
const props = await super.parse(data);
if (props.properties) {
if (props.properties.length === 0)
delete props.properties;
else
this.parseProperties(props.properties);
}
return props;
}
parseProperties(propertyProps) {
for (const props of propertyProps) {
props.customAttributes = props.customAttributes && props.customAttributes.length > 0 ? props.customAttributes.map((attr) => { return parseCustomAttribute(attr); }) : undefined;
if (!props.customAttributes)
delete props.customAttributes;
}
}
}
/**
* Parses the given MixinProps JSON returned from an ECSql query.
* @param data The MixinProps JSON as returned from an iModelDb.
* @returns The corrected MixinProps Json.
* @internal
*/
export class MixinParser extends ClassParser {
/**
* Parses the given MixinProps JSON returned from an ECSql query.
* @param data The MixinProps JSON as returned from an iModelDb.
* @returns The corrected MixinProps Json.
*/
async parse(data) {
const props = await super.parse(data);
if (!props.customAttributes)
delete props.customAttributes;
return props;
}
}
/**
* Parses the given CustomAttributeClassProps JSON returned from an ECSql query.
* @param data The CustomAttributeClassProps JSON as returned from an iModelDb.
* @returns The corrected CustomAttributeClassProps Json.
* @internal
*/
export class CustomAttributeClassParser extends ClassParser {
/**
* Parses the given CustomAttributeClassProps JSON returned from an ECSql query.
* @param data The CustomAttributeClassProps JSON as returned from an iModelDb.
* @returns The corrected CustomAttributeClassProps Json.
*/
async parse(data) {
const props = await super.parse(data);
props.appliesTo = props.appliesTo ? containerTypeToString(props.appliesTo) : CustomAttributeContainerType[CustomAttributeContainerType.Any];
return props;
}
}
/**
* Parses the given RelationshipClassProps JSON returned from an ECSql query.
* @param data The RelationshipClassProps JSON as returned from an iModelDb.
* @returns The corrected RelationshipClassProps Json.
* @internal
*/
export class RelationshipClassParser extends ClassParser {
/**
* Parses the given RelationshipClassProps JSON returned from an ECSql query.
* @param data The RelationshipClassProps JSON as returned from an iModelDb.
* @returns The corrected RelationshipClassProps Json.
*/
async parse(data) {
const props = await super.parse(data);
const source = props.source;
const target = props.target;
if (source) {
source.customAttributes = source.customAttributes ? source.customAttributes.map((attr) => { return parseCustomAttribute(attr); }) : undefined;
if (!source.customAttributes)
delete source.customAttributes;
}
if (target) {
target.customAttributes = target.customAttributes ? target.customAttributes.map((attr) => { return parseCustomAttribute(attr); }) : undefined;
if (!target.customAttributes)
delete target.customAttributes;
}
return props;
}
}
//# sourceMappingURL=ClassParsers.js.map