@itwin/ecschema-metadata
Version:
ECObjects core concepts in typescript
111 lines • 4.94 kB
JavaScript
;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.RelationshipClassParser = exports.CustomAttributeClassParser = exports.MixinParser = exports.ClassParser = void 0;
const ECObjects_1 = require("../ECObjects");
const SchemaItemParsers_1 = require("./SchemaItemParsers");
const SchemaParser_1 = require("./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
*/
class ClassParser extends SchemaItemParsers_1.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 (0, SchemaParser_1.parseCustomAttribute)(attr); }) : undefined;
if (!props.customAttributes)
delete props.customAttributes;
}
}
}
exports.ClassParser = 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.
* @internal
*/
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;
}
}
exports.MixinParser = MixinParser;
/**
* 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
*/
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 ? (0, ECObjects_1.containerTypeToString)(props.appliesTo) : ECObjects_1.CustomAttributeContainerType[ECObjects_1.CustomAttributeContainerType.Any];
return props;
}
}
exports.CustomAttributeClassParser = CustomAttributeClassParser;
/**
* 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
*/
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 (0, SchemaParser_1.parseCustomAttribute)(attr); }) : undefined;
if (!source.customAttributes)
delete source.customAttributes;
}
if (target) {
target.customAttributes = target.customAttributes ? target.customAttributes.map((attr) => { return (0, SchemaParser_1.parseCustomAttribute)(attr); }) : undefined;
if (!target.customAttributes)
delete target.customAttributes;
}
return props;
}
}
exports.RelationshipClassParser = RelationshipClassParser;
//# sourceMappingURL=ClassParsers.js.map