@itwin/ecschema-metadata 5.9.0-dev.8 → 5.10.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.
Files changed (102) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/lib/cjs/Deserialization/Helper.d.ts +1 -1
  3. package/lib/cjs/Deserialization/Helper.d.ts.map +1 -1
  4. package/lib/cjs/Deserialization/Helper.js +35 -21
  5. package/lib/cjs/Deserialization/Helper.js.map +1 -1
  6. package/lib/cjs/Deserialization/JsonParser.js +7 -7
  7. package/lib/cjs/Deserialization/JsonParser.js.map +1 -1
  8. package/lib/cjs/Deserialization/XmlParser.js.map +1 -1
  9. package/lib/cjs/Deserialization/XmlSerializationUtils.d.ts.map +1 -1
  10. package/lib/cjs/Deserialization/XmlSerializationUtils.js +1 -1
  11. package/lib/cjs/Deserialization/XmlSerializationUtils.js.map +1 -1
  12. package/lib/cjs/ECObjects.js.map +1 -1
  13. package/lib/cjs/Formatting/FormatSetFormatsProvider.d.ts +3 -2
  14. package/lib/cjs/Formatting/FormatSetFormatsProvider.d.ts.map +1 -1
  15. package/lib/cjs/Formatting/FormatSetFormatsProvider.js +7 -6
  16. package/lib/cjs/Formatting/FormatSetFormatsProvider.js.map +1 -1
  17. package/lib/cjs/Formatting/SchemaFormatsProvider.d.ts +1 -1
  18. package/lib/cjs/Formatting/SchemaFormatsProvider.d.ts.map +1 -1
  19. package/lib/cjs/Formatting/SchemaFormatsProvider.js +6 -5
  20. package/lib/cjs/Formatting/SchemaFormatsProvider.js.map +1 -1
  21. package/lib/cjs/IncrementalLoading/ECSqlSchemaLocater.js.map +1 -1
  22. package/lib/cjs/IncrementalLoading/IncrementalSchemaLocater.js +1 -1
  23. package/lib/cjs/IncrementalLoading/IncrementalSchemaLocater.js.map +1 -1
  24. package/lib/cjs/Metadata/Class.d.ts.map +1 -1
  25. package/lib/cjs/Metadata/Class.js +6 -4
  26. package/lib/cjs/Metadata/Class.js.map +1 -1
  27. package/lib/cjs/Metadata/EntityClass.d.ts.map +1 -1
  28. package/lib/cjs/Metadata/EntityClass.js +2 -2
  29. package/lib/cjs/Metadata/EntityClass.js.map +1 -1
  30. package/lib/cjs/Metadata/InvertedUnit.js +2 -2
  31. package/lib/cjs/Metadata/InvertedUnit.js.map +1 -1
  32. package/lib/cjs/Metadata/KindOfQuantity.js +1 -1
  33. package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
  34. package/lib/cjs/Metadata/Property.d.ts.map +1 -1
  35. package/lib/cjs/Metadata/Property.js +6 -3
  36. package/lib/cjs/Metadata/Property.js.map +1 -1
  37. package/lib/cjs/Metadata/RelationshipClass.d.ts.map +1 -1
  38. package/lib/cjs/Metadata/RelationshipClass.js +5 -4
  39. package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
  40. package/lib/cjs/Metadata/Schema.js +1 -1
  41. package/lib/cjs/Metadata/Schema.js.map +1 -1
  42. package/lib/cjs/Metadata/SchemaItem.js +2 -2
  43. package/lib/cjs/Metadata/SchemaItem.js.map +1 -1
  44. package/lib/cjs/Metadata/Unit.js +2 -2
  45. package/lib/cjs/Metadata/Unit.js.map +1 -1
  46. package/lib/cjs/SchemaPartVisitorDelegate.js.map +1 -1
  47. package/lib/cjs/UnitConversion/Parser.d.ts.map +1 -1
  48. package/lib/cjs/UnitConversion/Parser.js +4 -2
  49. package/lib/cjs/UnitConversion/Parser.js.map +1 -1
  50. package/lib/cjs/UnitConversion/UnitTree.js +1 -1
  51. package/lib/cjs/UnitConversion/UnitTree.js.map +1 -1
  52. package/lib/esm/Deserialization/Helper.d.ts +1 -1
  53. package/lib/esm/Deserialization/Helper.d.ts.map +1 -1
  54. package/lib/esm/Deserialization/Helper.js +35 -21
  55. package/lib/esm/Deserialization/Helper.js.map +1 -1
  56. package/lib/esm/Deserialization/JsonParser.js +7 -7
  57. package/lib/esm/Deserialization/JsonParser.js.map +1 -1
  58. package/lib/esm/Deserialization/XmlParser.js.map +1 -1
  59. package/lib/esm/Deserialization/XmlSerializationUtils.d.ts.map +1 -1
  60. package/lib/esm/Deserialization/XmlSerializationUtils.js +1 -1
  61. package/lib/esm/Deserialization/XmlSerializationUtils.js.map +1 -1
  62. package/lib/esm/ECObjects.js.map +1 -1
  63. package/lib/esm/Formatting/FormatSetFormatsProvider.d.ts +3 -2
  64. package/lib/esm/Formatting/FormatSetFormatsProvider.d.ts.map +1 -1
  65. package/lib/esm/Formatting/FormatSetFormatsProvider.js +7 -6
  66. package/lib/esm/Formatting/FormatSetFormatsProvider.js.map +1 -1
  67. package/lib/esm/Formatting/SchemaFormatsProvider.d.ts +1 -1
  68. package/lib/esm/Formatting/SchemaFormatsProvider.d.ts.map +1 -1
  69. package/lib/esm/Formatting/SchemaFormatsProvider.js +6 -5
  70. package/lib/esm/Formatting/SchemaFormatsProvider.js.map +1 -1
  71. package/lib/esm/IncrementalLoading/ECSqlSchemaLocater.js.map +1 -1
  72. package/lib/esm/IncrementalLoading/IncrementalSchemaLocater.js +1 -1
  73. package/lib/esm/IncrementalLoading/IncrementalSchemaLocater.js.map +1 -1
  74. package/lib/esm/Metadata/Class.d.ts.map +1 -1
  75. package/lib/esm/Metadata/Class.js +6 -4
  76. package/lib/esm/Metadata/Class.js.map +1 -1
  77. package/lib/esm/Metadata/EntityClass.d.ts.map +1 -1
  78. package/lib/esm/Metadata/EntityClass.js +2 -2
  79. package/lib/esm/Metadata/EntityClass.js.map +1 -1
  80. package/lib/esm/Metadata/InvertedUnit.js +2 -2
  81. package/lib/esm/Metadata/InvertedUnit.js.map +1 -1
  82. package/lib/esm/Metadata/KindOfQuantity.js +1 -1
  83. package/lib/esm/Metadata/KindOfQuantity.js.map +1 -1
  84. package/lib/esm/Metadata/Property.d.ts.map +1 -1
  85. package/lib/esm/Metadata/Property.js +6 -3
  86. package/lib/esm/Metadata/Property.js.map +1 -1
  87. package/lib/esm/Metadata/RelationshipClass.d.ts.map +1 -1
  88. package/lib/esm/Metadata/RelationshipClass.js +5 -4
  89. package/lib/esm/Metadata/RelationshipClass.js.map +1 -1
  90. package/lib/esm/Metadata/Schema.js +1 -1
  91. package/lib/esm/Metadata/Schema.js.map +1 -1
  92. package/lib/esm/Metadata/SchemaItem.js +2 -2
  93. package/lib/esm/Metadata/SchemaItem.js.map +1 -1
  94. package/lib/esm/Metadata/Unit.js +2 -2
  95. package/lib/esm/Metadata/Unit.js.map +1 -1
  96. package/lib/esm/SchemaPartVisitorDelegate.js.map +1 -1
  97. package/lib/esm/UnitConversion/Parser.d.ts.map +1 -1
  98. package/lib/esm/UnitConversion/Parser.js +4 -2
  99. package/lib/esm/UnitConversion/Parser.js.map +1 -1
  100. package/lib/esm/UnitConversion/UnitTree.js +1 -1
  101. package/lib/esm/UnitConversion/UnitTree.js.map +1 -1
  102. package/package.json +7 -7
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaItem.js","sourceRoot":"","sources":["../../../src/Metadata/SchemaItem.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,4CAAqD;AAGrD,4CAA0H;AAC1H,4CAA6D;AAC7D,4CAAwD;AAGxD;;;GAGG;AACH,MAAsB,UAAU;IAC9B;;;OAGG;IACI,MAAM,KAAK,cAAc,KAA8B,OAAO,kCAAsB,CAAC,UAAU,CAAA,CAAC,CAAC;IAMxF,MAAM,CAAS;IACvB,IAAI,CAAgB;IACpB,YAAY,CAAU;IACtB,MAAM,CAAU;IAChB,kBAAkB,CAA2B;IAErD,gBAAgB;IAChB,YAAY,MAAc,EAAE,IAAY;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,yBAAa,CAAC,IAAI,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;QACtD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,IAAW,IAAI,KAAK,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3C,IAAW,QAAQ,KAAK,OAAO,IAAI,CAAC,GAAG,CAA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UAAmC;QAC7D,IAAI,CAAC,kBAAkB,GAAG,UAAU,CAAC;IACvC,CAAC;CACF;AAzKD,gCAyKC","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 Metadata\r\n */\r\n\r\nimport { ECSchemaNamespaceUris } from \"../Constants\";\r\nimport { SchemaItemProps } from \"../Deserialization/JsonProps\";\r\nimport { SchemaLoadingController } from \"../utils/SchemaLoadingController\";\r\nimport { AbstractSchemaItemType, SchemaItemType, schemaItemTypeToXmlString, SupportedSchemaItemType } from \"../ECObjects\";\r\nimport { ECSchemaError, ECSchemaStatus } from \"../Exception\";\r\nimport { ECVersion, SchemaItemKey } from \"../SchemaKey\";\r\nimport { Schema } from \"./Schema\";\r\n\r\n/**\r\n * An abstract class that supplies all of the common parts of a SchemaItem.\r\n * @public @preview\r\n */\r\nexport abstract class SchemaItem {\r\n /**\r\n * Get the type of item represented by this class\r\n * @internal\r\n */\r\n public static get schemaItemType(): SupportedSchemaItemType { return AbstractSchemaItemType.SchemaItem }\r\n\r\n /**\r\n * Get the type of item represented by this instance\r\n */\r\n public abstract get schemaItemType(): SchemaItemType;\r\n public readonly schema: Schema;\r\n private _key: SchemaItemKey;\r\n private _description?: string;\r\n private _label?: string;\r\n private _loadingController?: SchemaLoadingController;\r\n\r\n /** @internal */\r\n constructor(schema: Schema, name: string) {\r\n this._key = new SchemaItemKey(name, schema.schemaKey);\r\n this.schema = schema;\r\n }\r\n\r\n public get name() { return this.key.name; }\r\n public get fullName() { return this.key.schemaKey ? `${this.key.schemaName}.${this.name}` : this.name; }\r\n public get key() { return this._key; }\r\n public get label() { return this._label; }\r\n public get description() { return this._description; }\r\n\r\n /**\r\n * Returns the SchemaLoadingController for this Schema. This would only be set if the schema is\r\n * loaded incrementally.\r\n * @internal\r\n */\r\n public get loadingController(): SchemaLoadingController | undefined{\r\n return this._loadingController;\r\n }\r\n\r\n // Proposal: Create protected setter methods for description and label? For UnitSystems as an example, where using createFromProps isn't that necessary and can just use basic create().\r\n /**\r\n * Save this SchemaItem's properties to an object for serializing to JSON.\r\n * @param standalone Serialization includes only this object (as opposed to the full schema).\r\n * @param includeSchemaVersion Include the Schema's version information in the serialized object.\r\n */\r\n public toJSON(standalone: boolean = false, includeSchemaVersion: boolean = false) {\r\n const itemJson: { [value: string]: any } = {};\r\n if (standalone) {\r\n itemJson.$schema = ECSchemaNamespaceUris.SCHEMAITEMURL3_2; // $schema is required\r\n itemJson.schema = this.schema.name;\r\n itemJson.name = this.name; // name is required\r\n if (includeSchemaVersion) // check flag to see if we should output version\r\n itemJson.schemaVersion = this.key.schemaKey.version.toString();\r\n }\r\n itemJson.schemaItemType = this.schemaItemType;\r\n if (undefined !== this.label)\r\n itemJson.label = this.label;\r\n if (undefined !== this.description)\r\n itemJson.description = this.description;\r\n\r\n return itemJson as SchemaItemProps;\r\n }\r\n\r\n /** @internal */\r\n public async toXml(schemaXml: Document): Promise<Element> {\r\n const itemType = schemaItemTypeToXmlString(this.schemaItemType);\r\n const itemElement = schemaXml.createElement(itemType);\r\n itemElement.setAttribute(\"typeName\", this.name);\r\n if (undefined !== this.label)\r\n itemElement.setAttribute(\"displayLabel\", this.label);\r\n if (undefined !== this.description)\r\n itemElement.setAttribute(\"description\", this.description);\r\n\r\n // When all schema items support custom attributes they should be added here rather than in ECClass\r\n\r\n return itemElement;\r\n }\r\n\r\n public fromJSONSync(schemaItemProps: SchemaItemProps) {\r\n if (undefined !== schemaItemProps.label)\r\n this._label = schemaItemProps.label;\r\n\r\n this._description = schemaItemProps.description;\r\n\r\n if (undefined !== schemaItemProps.schema) {\r\n if (schemaItemProps.schema.toLowerCase() !== this.schema.name.toLowerCase())\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Unable to deserialize the SchemaItem '${this.fullName}' with a different schema name, ${schemaItemProps.schema}, than the current Schema of this SchemaItem, ${this.schema.fullName}.`);\r\n }\r\n\r\n if (undefined !== schemaItemProps.schemaVersion) {\r\n if (this.key.schemaKey.version.compare(ECVersion.fromString(schemaItemProps.schemaVersion)))\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Unable to deserialize the SchemaItem '${this.fullName}' with a different schema version, ${schemaItemProps.schemaVersion}, than the current Schema version of this SchemaItem, ${this.key.schemaKey.version}.`);\r\n }\r\n }\r\n\r\n public async fromJSON(schemaItemProps: SchemaItemProps) {\r\n if (undefined !== schemaItemProps.label)\r\n this._label = schemaItemProps.label;\r\n\r\n this._description = schemaItemProps.description;\r\n\r\n if (undefined !== schemaItemProps.schema) {\r\n if (schemaItemProps.schema.toLowerCase() !== this.schema.name.toLowerCase())\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Unable to deserialize the SchemaItem ${this.fullName}' with a different schema name, ${schemaItemProps.schema}, than the current Schema of this SchemaItem, ${this.schema.fullName}`);\r\n }\r\n\r\n if (undefined !== schemaItemProps.schemaVersion) {\r\n if (this.key.schemaKey.version.compare(ECVersion.fromString(schemaItemProps.schemaVersion)))\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Unable to deserialize the SchemaItem '${this.fullName}' with a different schema version, ${schemaItemProps.schemaVersion}, than the current Schema version of this SchemaItem, ${this.key.schemaKey.version}.`);\r\n }\r\n }\r\n\r\n /**\r\n * Parses the given full name, {schemaName}.{schemaItemName} or {schemaName}:{schemaItemName}, into two separate strings.\r\n * @note The schema name can be a schema alias.\r\n * @param fullName The full name to be parsed.\r\n * @returns A tuple of the parsed Schema name and Schema Item name. If the full name does not contain a '.' or ':', the second string in the tuple will returned the exact string pass in.\r\n */\r\n public static parseFullName(fullName: string): [string, string] {\r\n const matches = /^([a-zA-Z_]+[a-zA-Z0-9_]*(\\.\\d+\\.\\d+\\.\\d+)?)[.:]([a-zA-Z_]+[a-zA-Z0-9_]*)$/.exec(fullName);\r\n\r\n // The first match will be the full string match, the second three will be the three groups\r\n if (matches === null || matches.length !== 4)\r\n return [\"\", fullName];\r\n\r\n return [matches[1], matches[3]];\r\n }\r\n\r\n /**\r\n * Indicates if the two SchemaItem objects are equal by comparing their respective [[key]] properties.\r\n * @param thisSchemaItem The first SchemaItem.\r\n * @param thatSchemaItemOrKey The second SchemaItem or SchemaItemKey.\r\n */\r\n public static equalByKey(thisSchemaItem: SchemaItem, thatSchemaItemOrKey?: SchemaItem | SchemaItemKey): boolean {\r\n if (!thatSchemaItemOrKey)\r\n return true;\r\n SchemaItemType.EntityClass\r\n const key = SchemaItem.isSchemaItem(thatSchemaItemOrKey) ? thatSchemaItemOrKey.key : thatSchemaItemOrKey;\r\n return thisSchemaItem.key.matches(key);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static isSchemaItem(item: unknown): item is SchemaItem {\r\n const schemaItem = item as Partial<SchemaItem>;\r\n\r\n return schemaItem !== undefined && schemaItem.key !== undefined && schemaItem.schema !== undefined\r\n && schemaItem.schemaItemType !== undefined;\r\n }\r\n\r\n /** @internal */\r\n protected setName(name: string) {\r\n this._key = new SchemaItemKey(name, this.schema.schemaKey);\r\n }\r\n\r\n /** @internal */\r\n protected setDisplayLabel(displayLabel: string) {\r\n this._label = displayLabel;\r\n }\r\n\r\n /** @internal */\r\n protected setDescription(description: string) {\r\n this._description = description;\r\n }\r\n\r\n /** @internal */\r\n public setLoadingController(controller: SchemaLoadingController) {\r\n this._loadingController = controller;\r\n }\r\n}\r\n\r\n"]}
1
+ {"version":3,"file":"SchemaItem.js","sourceRoot":"","sources":["../../../src/Metadata/SchemaItem.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,4CAAqD;AAGrD,4CAA0H;AAC1H,4CAA6D;AAC7D,4CAAwD;AAGxD;;;GAGG;AACH,MAAsB,UAAU;IAC9B;;;OAGG;IACI,MAAM,KAAK,cAAc,KAA8B,OAAO,kCAAsB,CAAC,UAAU,CAAA,CAAC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AAU,CAAC,MAAM,KAAK,SAAS;eAC7F,UAAU,CAAC,cAAc,KAAK,SAAS,CAAC;IAC/C,CAAC;IAED,gBAAgB;IACN,OAAO,CAAC,IAAY;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,yBAAa,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAC7D,CAAC;IAED,gBAAgB;IACN,eAAe,CAAC,YAAoB;QAC5C,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC;IAC7B,CAAC;IAED,gBAAgB;IACN,cAAc,CAAC,WAAmB;QAC1C,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IAClC,CAAC;IAED,gBAAgB;IACT,oBAAoB,CAAC,UAAmC;QAC7D,IAAI,CAAC,kBAAkB,GAAG,UAAU,CAAC;IACvC,CAAC;CACF;AAzKD,gCAyKC","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 Metadata\r\n */\r\n\r\nimport { ECSchemaNamespaceUris } from \"../Constants\";\r\nimport { SchemaItemProps } from \"../Deserialization/JsonProps\";\r\nimport { SchemaLoadingController } from \"../utils/SchemaLoadingController\";\r\nimport { AbstractSchemaItemType, SchemaItemType, schemaItemTypeToXmlString, SupportedSchemaItemType } from \"../ECObjects\";\r\nimport { ECSchemaError, ECSchemaStatus } from \"../Exception\";\r\nimport { ECVersion, SchemaItemKey } from \"../SchemaKey\";\r\nimport { Schema } from \"./Schema\";\r\n\r\n/**\r\n * An abstract class that supplies all of the common parts of a SchemaItem.\r\n * @public @preview\r\n */\r\nexport abstract class SchemaItem {\r\n /**\r\n * Get the type of item represented by this class\r\n * @internal\r\n */\r\n public static get schemaItemType(): SupportedSchemaItemType { return AbstractSchemaItemType.SchemaItem }\r\n\r\n /**\r\n * Get the type of item represented by this instance\r\n */\r\n public abstract get schemaItemType(): SchemaItemType;\r\n public readonly schema: Schema;\r\n private _key: SchemaItemKey;\r\n private _description?: string;\r\n private _label?: string;\r\n private _loadingController?: SchemaLoadingController;\r\n\r\n /** @internal */\r\n constructor(schema: Schema, name: string) {\r\n this._key = new SchemaItemKey(name, schema.schemaKey);\r\n this.schema = schema;\r\n }\r\n\r\n public get name() { return this.key.name; }\r\n public get fullName() { return this.key.schemaKey ? `${this.key.schemaName}.${this.name}` : this.name; }\r\n public get key() { return this._key; }\r\n public get label() { return this._label; }\r\n public get description() { return this._description; }\r\n\r\n /**\r\n * Returns the SchemaLoadingController for this Schema. This would only be set if the schema is\r\n * loaded incrementally.\r\n * @internal\r\n */\r\n public get loadingController(): SchemaLoadingController | undefined {\r\n return this._loadingController;\r\n }\r\n\r\n // Proposal: Create protected setter methods for description and label? For UnitSystems as an example, where using createFromProps isn't that necessary and can just use basic create().\r\n /**\r\n * Save this SchemaItem's properties to an object for serializing to JSON.\r\n * @param standalone Serialization includes only this object (as opposed to the full schema).\r\n * @param includeSchemaVersion Include the Schema's version information in the serialized object.\r\n */\r\n public toJSON(standalone: boolean = false, includeSchemaVersion: boolean = false) {\r\n const itemJson: { [value: string]: any } = {};\r\n if (standalone) {\r\n itemJson.$schema = ECSchemaNamespaceUris.SCHEMAITEMURL3_2; // $schema is required\r\n itemJson.schema = this.schema.name;\r\n itemJson.name = this.name; // name is required\r\n if (includeSchemaVersion) // check flag to see if we should output version\r\n itemJson.schemaVersion = this.key.schemaKey.version.toString();\r\n }\r\n itemJson.schemaItemType = this.schemaItemType;\r\n if (undefined !== this.label)\r\n itemJson.label = this.label;\r\n if (undefined !== this.description)\r\n itemJson.description = this.description;\r\n\r\n return itemJson as SchemaItemProps;\r\n }\r\n\r\n /** @internal */\r\n public async toXml(schemaXml: Document): Promise<Element> {\r\n const itemType = schemaItemTypeToXmlString(this.schemaItemType);\r\n const itemElement = schemaXml.createElement(itemType);\r\n itemElement.setAttribute(\"typeName\", this.name);\r\n if (undefined !== this.label)\r\n itemElement.setAttribute(\"displayLabel\", this.label);\r\n if (undefined !== this.description)\r\n itemElement.setAttribute(\"description\", this.description);\r\n\r\n // When all schema items support custom attributes they should be added here rather than in ECClass\r\n\r\n return itemElement;\r\n }\r\n\r\n public fromJSONSync(schemaItemProps: SchemaItemProps) {\r\n if (undefined !== schemaItemProps.label)\r\n this._label = schemaItemProps.label;\r\n\r\n this._description = schemaItemProps.description;\r\n\r\n if (undefined !== schemaItemProps.schema) {\r\n if (schemaItemProps.schema.toLowerCase() !== this.schema.name.toLowerCase())\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Unable to deserialize the SchemaItem '${this.fullName}' with a different schema name, ${schemaItemProps.schema}, than the current Schema of this SchemaItem, ${this.schema.fullName}.`);\r\n }\r\n\r\n if (undefined !== schemaItemProps.schemaVersion) {\r\n if (this.key.schemaKey.version.compare(ECVersion.fromString(schemaItemProps.schemaVersion)))\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Unable to deserialize the SchemaItem '${this.fullName}' with a different schema version, ${schemaItemProps.schemaVersion}, than the current Schema version of this SchemaItem, ${this.key.schemaKey.version.toString()}.`);\r\n }\r\n }\r\n\r\n public async fromJSON(schemaItemProps: SchemaItemProps) {\r\n if (undefined !== schemaItemProps.label)\r\n this._label = schemaItemProps.label;\r\n\r\n this._description = schemaItemProps.description;\r\n\r\n if (undefined !== schemaItemProps.schema) {\r\n if (schemaItemProps.schema.toLowerCase() !== this.schema.name.toLowerCase())\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Unable to deserialize the SchemaItem ${this.fullName}' with a different schema name, ${schemaItemProps.schema}, than the current Schema of this SchemaItem, ${this.schema.fullName}`);\r\n }\r\n\r\n if (undefined !== schemaItemProps.schemaVersion) {\r\n if (this.key.schemaKey.version.compare(ECVersion.fromString(schemaItemProps.schemaVersion)))\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Unable to deserialize the SchemaItem '${this.fullName}' with a different schema version, ${schemaItemProps.schemaVersion}, than the current Schema version of this SchemaItem, ${this.key.schemaKey.version.toString()}.`);\r\n }\r\n }\r\n\r\n /**\r\n * Parses the given full name, {schemaName}.{schemaItemName} or {schemaName}:{schemaItemName}, into two separate strings.\r\n * @note The schema name can be a schema alias.\r\n * @param fullName The full name to be parsed.\r\n * @returns A tuple of the parsed Schema name and Schema Item name. If the full name does not contain a '.' or ':', the second string in the tuple will returned the exact string pass in.\r\n */\r\n public static parseFullName(fullName: string): [string, string] {\r\n const matches = /^([a-zA-Z_]+[a-zA-Z0-9_]*(\\.\\d+\\.\\d+\\.\\d+)?)[.:]([a-zA-Z_]+[a-zA-Z0-9_]*)$/.exec(fullName);\r\n\r\n // The first match will be the full string match, the second three will be the three groups\r\n if (matches === null || matches.length !== 4)\r\n return [\"\", fullName];\r\n\r\n return [matches[1], matches[3]];\r\n }\r\n\r\n /**\r\n * Indicates if the two SchemaItem objects are equal by comparing their respective [[key]] properties.\r\n * @param thisSchemaItem The first SchemaItem.\r\n * @param thatSchemaItemOrKey The second SchemaItem or SchemaItemKey.\r\n */\r\n public static equalByKey(thisSchemaItem: SchemaItem, thatSchemaItemOrKey?: SchemaItem | SchemaItemKey): boolean {\r\n if (!thatSchemaItemOrKey)\r\n return true;\r\n SchemaItemType.EntityClass\r\n const key = SchemaItem.isSchemaItem(thatSchemaItemOrKey) ? thatSchemaItemOrKey.key : thatSchemaItemOrKey;\r\n return thisSchemaItem.key.matches(key);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static isSchemaItem(item: unknown): item is SchemaItem {\r\n const schemaItem = item as Partial<SchemaItem>;\r\n\r\n return schemaItem !== undefined && schemaItem.key !== undefined && schemaItem.schema !== undefined\r\n && schemaItem.schemaItemType !== undefined;\r\n }\r\n\r\n /** @internal */\r\n protected setName(name: string) {\r\n this._key = new SchemaItemKey(name, this.schema.schemaKey);\r\n }\r\n\r\n /** @internal */\r\n protected setDisplayLabel(displayLabel: string) {\r\n this._label = displayLabel;\r\n }\r\n\r\n /** @internal */\r\n protected setDescription(description: string) {\r\n this._description = description;\r\n }\r\n\r\n /** @internal */\r\n public setLoadingController(controller: SchemaLoadingController) {\r\n this._loadingController = controller;\r\n }\r\n}\r\n\r\n"]}
@@ -72,8 +72,8 @@ class Unit extends SchemaItem_1.SchemaItem {
72
72
  */
73
73
  toJSON(standalone = false, includeSchemaVersion = false) {
74
74
  const schemaJson = super.toJSON(standalone, includeSchemaVersion);
75
- schemaJson.phenomenon = this.phenomenon.fullName;
76
- schemaJson.unitSystem = this.unitSystem.fullName;
75
+ schemaJson.phenomenon = this.phenomenon?.fullName ?? "";
76
+ schemaJson.unitSystem = this.unitSystem?.fullName ?? "";
77
77
  schemaJson.definition = this.definition;
78
78
  if (this.hasNumerator)
79
79
  schemaJson.numerator = this.numerator;
@@ -1 +1 @@
1
- {"version":3,"file":"Unit.js","sourceRoot":"","sources":["../../../src/Metadata/Unit.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA4D;AAE5D,oFAAiF;AACjF,4CAA8C;AAC9C,4CAA6D;AAG7D,6CAA0C;AAE1C,6CAA0C;AAC1C,6CAA0C;AAE1C;;;;GAIG;AACH,MAAa,IAAK,SAAQ,uBAAU;IACT,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;IAC9D,gBAAgB;IACT,MAAM,KAAc,cAAc,KAAK,OAAO,0BAAc,CAAC,IAAI,CAAC,CAAC,CAAC;IACnE,WAAW,CAAwB;IACnC,WAAW,CAAwB;IACnC,WAAW,CAAS;IACpB,UAAU,CAAU;IACpB,YAAY,CAAU;IACtB,OAAO,CAAU;IAEzB,gBAAgB;IAChB,YAAY,MAAc,EAAE,IAAY;QACtC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;IACxB,CAAC;IAED,IAAW,UAAU,KAAuC,OAAO,IAAI,CAAC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AAC,WAAW,CAAC;QAC9C,CAAC;QAED,IAAI,SAAS,KAAK,SAAS,CAAC,MAAM,EAAE,CAAC;YACnC,IAAI,SAAS,CAAC,MAAM,KAAK,IAAI,CAAC,OAAO;gBACnC,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC;QACpC,CAAC;IACH,CAAC;IAEe,KAAK,CAAC,QAAQ,CAAC,SAA8B;QAC3D,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IAC/B,CAAC;IAED,gBAAgB;IACN,KAAK,CAAC,aAAa,CAAC,UAAgC;QAC5D,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAED,gBAAgB;IACN,KAAK,CAAC,aAAa,CAAC,UAAgC;QAC5D,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAED,gBAAgB;IACN,KAAK,CAAC,aAAa,CAAC,UAAkB;QAC9C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,YAAY,CAAC,IAAiB;QAC1C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YACpB,MAAM,IAAI,yBAAa,CAAC,0BAAc,CAAC,qBAAqB,EAAE,aAAa,0BAAc,CAAC,IAAI,UAAU,CAAC,CAAC;IAC9G,CAAC;CACF;AA7KD,oBA6KC;AACD;;;GAGG;AACH,MAAsB,WAAY,SAAQ,IAAI;CAK7C;AALD,kCAKC","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 Metadata\r\n */\r\n\r\nimport { DelayedPromiseWithProps } from \"../DelayedPromise\";\r\nimport { SchemaItemUnitProps } from \"../Deserialization/JsonProps\";\r\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\r\nimport { SchemaItemType } from \"../ECObjects\";\r\nimport { ECSchemaError, ECSchemaStatus } from \"../Exception\";\r\nimport { LazyLoadedPhenomenon, LazyLoadedUnitSystem } from \"../Interfaces\";\r\nimport { SchemaItemKey } from \"../SchemaKey\";\r\nimport { Phenomenon } from \"./Phenomenon\";\r\nimport { Schema } from \"./Schema\";\r\nimport { SchemaItem } from \"./SchemaItem\";\r\nimport { UnitSystem } from \"./UnitSystem\";\r\n\r\n/**\r\n * An abstract class that adds the ability to define Units and everything that goes with them, within an ECSchema as a\r\n * first-class concept is to allow the iModel to not be dependent on any hard-coded Units\r\n * @public @preview\r\n */\r\nexport class Unit extends SchemaItem {\r\n public override readonly schemaItemType = Unit.schemaItemType;\r\n /** @internal */\r\n public static override get schemaItemType() { return SchemaItemType.Unit; }\r\n private _phenomenon?: LazyLoadedPhenomenon;\r\n private _unitSystem?: LazyLoadedUnitSystem;\r\n private _definition: string;\r\n private _numerator?: number;\r\n private _denominator?: number;\r\n private _offset?: number;\r\n\r\n /** @internal */\r\n constructor(schema: Schema, name: string) {\r\n super(schema, name);\r\n this._definition = \"\";\r\n }\r\n\r\n public get phenomenon(): LazyLoadedPhenomenon | undefined { return this._phenomenon; }\r\n public get unitSystem(): LazyLoadedUnitSystem | undefined { return this._unitSystem; }\r\n public get definition(): string { return this._definition; }\r\n public get numerator(): number { return this._numerator ?? 1.0; }\r\n public get offset(): number { return this._offset ?? 0.0; }\r\n public get denominator(): number { return this._denominator ?? 1.0; }\r\n public get hasNumerator(): boolean { return (this._numerator !== undefined); }\r\n public get hasOffset(): boolean { return (this._offset !== undefined); }\r\n public get hasDenominator(): boolean { return (this._denominator !== undefined); }\r\n\r\n /**\r\n * Returns true if a conversion can be calculated between the input units\r\n * @alpha\r\n */\r\n public static async areCompatible(unitA: Unit, unitB: Unit): Promise<boolean> {\r\n const unitAPhenomenon = await unitA.phenomenon;\r\n const unitBPhenomenon = await unitB.phenomenon;\r\n\r\n if (!unitAPhenomenon || !unitBPhenomenon || !unitAPhenomenon.key.matches(unitBPhenomenon.key))\r\n return false;\r\n return true;\r\n }\r\n\r\n /**\r\n * Type guard to check if the SchemaItem is of type Unit.\r\n * @param item The SchemaItem to check.\r\n * @returns True if the item is a Unit, false otherwise.\r\n */\r\n public static isUnit(item?: SchemaItem): item is Unit {\r\n if (item && item.schemaItemType === SchemaItemType.Unit)\r\n return true;\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Save this Unit's properties to an object for serializing to JSON.\r\n * @param standalone Serialization includes only this object (as opposed to the full schema).\r\n * @param includeSchemaVersion Include the Schema's version information in the serialized object.\r\n */\r\n public override toJSON(standalone: boolean = false, includeSchemaVersion: boolean = false): SchemaItemUnitProps {\r\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\r\n schemaJson.phenomenon = this.phenomenon!.fullName;\r\n schemaJson.unitSystem = this.unitSystem!.fullName;\r\n schemaJson.definition = this.definition;\r\n if (this.hasNumerator)\r\n schemaJson.numerator = this.numerator;\r\n if (this.hasDenominator)\r\n schemaJson.denominator = this.denominator;\r\n if (this.hasOffset)\r\n schemaJson.offset = this.offset;\r\n return schemaJson;\r\n }\r\n\r\n /** @internal */\r\n public override async toXml(schemaXml: Document): Promise<Element> {\r\n const itemElement = await super.toXml(schemaXml);\r\n\r\n const phenomenon = await this.phenomenon;\r\n if (undefined !== phenomenon) {\r\n const phenomenonName = XmlSerializationUtils.createXmlTypedName(this.schema, phenomenon.schema, phenomenon.name);\r\n itemElement.setAttribute(\"phenomenon\", phenomenonName);\r\n }\r\n\r\n const unitSystem = await this.unitSystem;\r\n if (undefined !== unitSystem) {\r\n const unitSystemName = XmlSerializationUtils.createXmlTypedName(this.schema, unitSystem.schema, unitSystem.name);\r\n itemElement.setAttribute(\"unitSystem\", unitSystemName);\r\n }\r\n\r\n itemElement.setAttribute(\"definition\", this.definition);\r\n if (this.hasNumerator)\r\n itemElement.setAttribute(\"numerator\", this.numerator.toString());\r\n if (this.hasDenominator)\r\n itemElement.setAttribute(\"denominator\", this.denominator.toString());\r\n if (this.hasOffset)\r\n itemElement.setAttribute(\"offset\", this.offset.toString());\r\n\r\n return itemElement;\r\n }\r\n\r\n public override fromJSONSync(unitProps: SchemaItemUnitProps) {\r\n super.fromJSONSync(unitProps);\r\n\r\n const phenomenonSchemaItemKey = this.schema.getSchemaItemKey(unitProps.phenomenon);\r\n if (!phenomenonSchemaItemKey)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Unable to locate the phenomenon ${unitProps.phenomenon}.`);\r\n this._phenomenon = new DelayedPromiseWithProps<SchemaItemKey, Phenomenon>(phenomenonSchemaItemKey,\r\n async () => {\r\n const phenom = await this.schema.lookupItem(phenomenonSchemaItemKey, Phenomenon);\r\n if (undefined === phenom)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Unable to locate the phenomenon ${unitProps.phenomenon}.`);\r\n return phenom;\r\n });\r\n\r\n const unitSystemSchemaItemKey = this.schema.getSchemaItemKey(unitProps.unitSystem);\r\n if (!unitSystemSchemaItemKey)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Unable to locate the unitSystem ${unitProps.unitSystem}.`);\r\n this._unitSystem = new DelayedPromiseWithProps<SchemaItemKey, UnitSystem>(unitSystemSchemaItemKey,\r\n async () => {\r\n const unitSystem = await this.schema.lookupItem(unitSystemSchemaItemKey, UnitSystem);\r\n if (undefined === unitSystem)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Unable to locate the unitSystem ${unitProps.unitSystem}.`);\r\n return unitSystem;\r\n });\r\n\r\n if (this._definition !== \"\" && unitProps.definition.toLowerCase() !== this._definition.toLowerCase())\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Unit ${this.name} has an invalid 'definition' attribute.`);\r\n else if (this._definition === \"\")\r\n this._definition = unitProps.definition;\r\n\r\n if (undefined !== unitProps.numerator) {\r\n if (unitProps.numerator !== this._numerator)\r\n this._numerator = unitProps.numerator;\r\n }\r\n\r\n if (undefined !== unitProps.denominator) {\r\n if (unitProps.denominator !== this._denominator)\r\n this._denominator = unitProps.denominator;\r\n }\r\n\r\n if (undefined !== unitProps.offset) {\r\n if (unitProps.offset !== this._offset)\r\n this._offset = unitProps.offset;\r\n }\r\n }\r\n\r\n public override async fromJSON(unitProps: SchemaItemUnitProps) {\r\n this.fromJSONSync(unitProps);\r\n }\r\n\r\n /** @internal */\r\n protected async setPhenomenon(phenomenon: LazyLoadedPhenomenon) {\r\n this._phenomenon = phenomenon;\r\n }\r\n\r\n /** @internal */\r\n protected async setUnitSystem(unitSystem: LazyLoadedUnitSystem) {\r\n this._unitSystem = unitSystem;\r\n }\r\n\r\n /** @internal */\r\n protected async setDefinition(definition: string) {\r\n this._definition = definition;\r\n }\r\n\r\n /**\r\n * Type assertion to check if the SchemaItem is of type Unit.\r\n * @param item The SchemaItem to check.\r\n * @returns The item cast to Unit if it is a Unit, undefined otherwise.\r\n * @internal\r\n */\r\n public static assertIsUnit(item?: SchemaItem): asserts item is Unit {\r\n if (!this.isUnit(item))\r\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.Unit}' (Unit)`);\r\n }\r\n}\r\n/**\r\n * @internal\r\n * An abstract class used for schema editing.\r\n */\r\nexport abstract class MutableUnit extends Unit {\r\n public abstract override setPhenomenon(phenomenon: LazyLoadedPhenomenon): Promise<void>;\r\n public abstract override setUnitSystem(unitSystem: LazyLoadedUnitSystem): Promise<void>;\r\n public abstract override setDefinition(definition: string): Promise<void>;\r\n public abstract override setDisplayLabel(displayLabel: string): void;\r\n}\r\n"]}
1
+ {"version":3,"file":"Unit.js","sourceRoot":"","sources":["../../../src/Metadata/Unit.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA4D;AAE5D,oFAAiF;AACjF,4CAA8C;AAC9C,4CAA6D;AAG7D,6CAA0C;AAE1C,6CAA0C;AAC1C,6CAA0C;AAE1C;;;;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,MAAM,IAAI,yBAAa,CAAC,0BAAc,CAAC,qBAAqB,EAAE,aAAa,0BAAc,CAAC,IAAI,UAAU,CAAC,CAAC;IAC9G,CAAC;CACF;AA7KD,oBA6KC;AACD;;;GAGG;AACH,MAAsB,WAAY,SAAQ,IAAI;CAK7C;AALD,kCAKC","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 Metadata\r\n */\r\n\r\nimport { DelayedPromiseWithProps } from \"../DelayedPromise\";\r\nimport { SchemaItemUnitProps } from \"../Deserialization/JsonProps\";\r\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\r\nimport { SchemaItemType } from \"../ECObjects\";\r\nimport { ECSchemaError, ECSchemaStatus } from \"../Exception\";\r\nimport { LazyLoadedPhenomenon, LazyLoadedUnitSystem } from \"../Interfaces\";\r\nimport { SchemaItemKey } from \"../SchemaKey\";\r\nimport { Phenomenon } from \"./Phenomenon\";\r\nimport { Schema } from \"./Schema\";\r\nimport { SchemaItem } from \"./SchemaItem\";\r\nimport { UnitSystem } from \"./UnitSystem\";\r\n\r\n/**\r\n * An abstract class that adds the ability to define Units and everything that goes with them, within an ECSchema as a\r\n * first-class concept is to allow the iModel to not be dependent on any hard-coded Units\r\n * @public @preview\r\n */\r\nexport class Unit extends SchemaItem {\r\n public override readonly schemaItemType = Unit.schemaItemType;\r\n /** @internal */\r\n public static override get schemaItemType() { return SchemaItemType.Unit; }\r\n private _phenomenon?: LazyLoadedPhenomenon;\r\n private _unitSystem?: LazyLoadedUnitSystem;\r\n private _definition: string;\r\n private _numerator?: number;\r\n private _denominator?: number;\r\n private _offset?: number;\r\n\r\n /** @internal */\r\n constructor(schema: Schema, name: string) {\r\n super(schema, name);\r\n this._definition = \"\";\r\n }\r\n\r\n public get phenomenon(): LazyLoadedPhenomenon | undefined { return this._phenomenon; }\r\n public get unitSystem(): LazyLoadedUnitSystem | undefined { return this._unitSystem; }\r\n public get definition(): string { return this._definition; }\r\n public get numerator(): number { return this._numerator ?? 1.0; }\r\n public get offset(): number { return this._offset ?? 0.0; }\r\n public get denominator(): number { return this._denominator ?? 1.0; }\r\n public get hasNumerator(): boolean { return (this._numerator !== undefined); }\r\n public get hasOffset(): boolean { return (this._offset !== undefined); }\r\n public get hasDenominator(): boolean { return (this._denominator !== undefined); }\r\n\r\n /**\r\n * Returns true if a conversion can be calculated between the input units\r\n * @alpha\r\n */\r\n public static async areCompatible(unitA: Unit, unitB: Unit): Promise<boolean> {\r\n const unitAPhenomenon = await unitA.phenomenon;\r\n const unitBPhenomenon = await unitB.phenomenon;\r\n\r\n if (!unitAPhenomenon || !unitBPhenomenon || !unitAPhenomenon.key.matches(unitBPhenomenon.key))\r\n return false;\r\n return true;\r\n }\r\n\r\n /**\r\n * Type guard to check if the SchemaItem is of type Unit.\r\n * @param item The SchemaItem to check.\r\n * @returns True if the item is a Unit, false otherwise.\r\n */\r\n public static isUnit(item?: SchemaItem): item is Unit {\r\n if (item && item.schemaItemType === SchemaItemType.Unit)\r\n return true;\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Save this Unit's properties to an object for serializing to JSON.\r\n * @param standalone Serialization includes only this object (as opposed to the full schema).\r\n * @param includeSchemaVersion Include the Schema's version information in the serialized object.\r\n */\r\n public override toJSON(standalone: boolean = false, includeSchemaVersion: boolean = false): SchemaItemUnitProps {\r\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\r\n schemaJson.phenomenon = this.phenomenon?.fullName ?? \"\";\r\n schemaJson.unitSystem = this.unitSystem?.fullName ?? \"\";\r\n schemaJson.definition = this.definition;\r\n if (this.hasNumerator)\r\n schemaJson.numerator = this.numerator;\r\n if (this.hasDenominator)\r\n schemaJson.denominator = this.denominator;\r\n if (this.hasOffset)\r\n schemaJson.offset = this.offset;\r\n return schemaJson;\r\n }\r\n\r\n /** @internal */\r\n public override async toXml(schemaXml: Document): Promise<Element> {\r\n const itemElement = await super.toXml(schemaXml);\r\n\r\n const phenomenon = await this.phenomenon;\r\n if (undefined !== phenomenon) {\r\n const phenomenonName = XmlSerializationUtils.createXmlTypedName(this.schema, phenomenon.schema, phenomenon.name);\r\n itemElement.setAttribute(\"phenomenon\", phenomenonName);\r\n }\r\n\r\n const unitSystem = await this.unitSystem;\r\n if (undefined !== unitSystem) {\r\n const unitSystemName = XmlSerializationUtils.createXmlTypedName(this.schema, unitSystem.schema, unitSystem.name);\r\n itemElement.setAttribute(\"unitSystem\", unitSystemName);\r\n }\r\n\r\n itemElement.setAttribute(\"definition\", this.definition);\r\n if (this.hasNumerator)\r\n itemElement.setAttribute(\"numerator\", this.numerator.toString());\r\n if (this.hasDenominator)\r\n itemElement.setAttribute(\"denominator\", this.denominator.toString());\r\n if (this.hasOffset)\r\n itemElement.setAttribute(\"offset\", this.offset.toString());\r\n\r\n return itemElement;\r\n }\r\n\r\n public override fromJSONSync(unitProps: SchemaItemUnitProps) {\r\n super.fromJSONSync(unitProps);\r\n\r\n const phenomenonSchemaItemKey = this.schema.getSchemaItemKey(unitProps.phenomenon);\r\n if (!phenomenonSchemaItemKey)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Unable to locate the phenomenon ${unitProps.phenomenon}.`);\r\n this._phenomenon = new DelayedPromiseWithProps<SchemaItemKey, Phenomenon>(phenomenonSchemaItemKey,\r\n async () => {\r\n const phenom = await this.schema.lookupItem(phenomenonSchemaItemKey, Phenomenon);\r\n if (undefined === phenom)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Unable to locate the phenomenon ${unitProps.phenomenon}.`);\r\n return phenom;\r\n });\r\n\r\n const unitSystemSchemaItemKey = this.schema.getSchemaItemKey(unitProps.unitSystem);\r\n if (!unitSystemSchemaItemKey)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Unable to locate the unitSystem ${unitProps.unitSystem}.`);\r\n this._unitSystem = new DelayedPromiseWithProps<SchemaItemKey, UnitSystem>(unitSystemSchemaItemKey,\r\n async () => {\r\n const unitSystem = await this.schema.lookupItem(unitSystemSchemaItemKey, UnitSystem);\r\n if (undefined === unitSystem)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Unable to locate the unitSystem ${unitProps.unitSystem}.`);\r\n return unitSystem;\r\n });\r\n\r\n if (this._definition !== \"\" && unitProps.definition.toLowerCase() !== this._definition.toLowerCase())\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Unit ${this.name} has an invalid 'definition' attribute.`);\r\n else if (this._definition === \"\")\r\n this._definition = unitProps.definition;\r\n\r\n if (undefined !== unitProps.numerator) {\r\n if (unitProps.numerator !== this._numerator)\r\n this._numerator = unitProps.numerator;\r\n }\r\n\r\n if (undefined !== unitProps.denominator) {\r\n if (unitProps.denominator !== this._denominator)\r\n this._denominator = unitProps.denominator;\r\n }\r\n\r\n if (undefined !== unitProps.offset) {\r\n if (unitProps.offset !== this._offset)\r\n this._offset = unitProps.offset;\r\n }\r\n }\r\n\r\n public override async fromJSON(unitProps: SchemaItemUnitProps) {\r\n this.fromJSONSync(unitProps);\r\n }\r\n\r\n /** @internal */\r\n protected async setPhenomenon(phenomenon: LazyLoadedPhenomenon) {\r\n this._phenomenon = phenomenon;\r\n }\r\n\r\n /** @internal */\r\n protected async setUnitSystem(unitSystem: LazyLoadedUnitSystem) {\r\n this._unitSystem = unitSystem;\r\n }\r\n\r\n /** @internal */\r\n protected async setDefinition(definition: string) {\r\n this._definition = definition;\r\n }\r\n\r\n /**\r\n * Type assertion to check if the SchemaItem is of type Unit.\r\n * @param item The SchemaItem to check.\r\n * @returns The item cast to Unit if it is a Unit, undefined otherwise.\r\n * @internal\r\n */\r\n public static assertIsUnit(item?: SchemaItem): asserts item is Unit {\r\n if (!this.isUnit(item))\r\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.Unit}' (Unit)`);\r\n }\r\n}\r\n/**\r\n * @internal\r\n * An abstract class used for schema editing.\r\n */\r\nexport abstract class MutableUnit extends Unit {\r\n public abstract override setPhenomenon(phenomenon: LazyLoadedPhenomenon): Promise<void>;\r\n public abstract override setUnitSystem(unitSystem: LazyLoadedUnitSystem): Promise<void>;\r\n public abstract override setDefinition(definition: string): Promise<void>;\r\n public abstract override setDisplayLabel(displayLabel: string): void;\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaPartVisitorDelegate.js","sourceRoot":"","sources":["../../src/SchemaPartVisitorDelegate.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,2CAA6C;AAE7C,4CAAwD;AAWxD,kDAA4D;AAE5D,oEAAyF;AAEzF,sDAAmD;AA2QnD,SAAS,0BAA0B,CAAC,MAAW;IAC7C,OAAO,kBAAkB,IAAI,MAAM,CAAC;AACtC,CAAC;AAED;;;GAGG;AACH,MAAa,yBAAyB;IAC5B,QAAQ,CAAqB;IAErC,YAAY,OAA2B;QACrC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,WAAW,CAAC,MAAc,EAAE,aAAsB,IAAI;QACjE,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,QAAQ,CAAC,gBAAgB;YAC/C,MAAM,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;QAE/C,IAAI,UAAU,IAAI,IAAI,CAAC,QAAQ,CAAC,eAAe;YAC7C,MAAM,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;IAED;;;;OAIG;IACI,eAAe,CAAC,MAAc,EAAE,aAAsB,IAAI;QAC/D,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,QAAQ,CAAC,oBAAoB;YACnD,IAAI,CAAC,QAAQ,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;QAE7C,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,0BAA0B;oBAC1C,IAAI,CAAC,QAAQ,CAAC,0BAA0B,CAAC,UAA+B,CAAC,CAAC;gBAC5E,MAAM;YACR,KAAK,0BAAc,CAAC,WAAW;gBAC7B,IAAI,IAAI,CAAC,QAAQ,CAAC,oBAAoB;oBACpC,IAAI,CAAC,QAAQ,CAAC,oBAAoB,CAAC,UAAyB,CAAC,CAAC;gBAChE,MAAM;YACR,KAAK,0BAAc,CAAC,IAAI;gBACtB,IAAI,IAAI,CAAC,QAAQ,CAAC,aAAa;oBAC7B,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAkB,CAAC,CAAC;gBAClD,MAAM;YACR,KAAK,0BAAc,CAAC,UAAU;gBAC5B,IAAI,IAAI,CAAC,QAAQ,CAAC,mBAAmB;oBACnC,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,UAAwB,CAAC,CAAC;gBAC9D,MAAM;QACV,CAAC;IACH,CAAC;CACF;AA3MD,8DA2MC","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\r\nimport { SchemaItemType } from \"./ECObjects\";\r\nimport { AnyClass, AnyECType } from \"./Interfaces\";\r\nimport { ECClass, StructClass } from \"./Metadata/Class\";\r\nimport { Constant } from \"./Metadata/Constant\";\r\nimport { CustomAttributeContainerProps } from \"./Metadata/CustomAttribute\";\r\nimport { CustomAttributeClass } from \"./Metadata/CustomAttributeClass\";\r\nimport { EntityClass } from \"./Metadata/EntityClass\";\r\nimport { Enumeration } from \"./Metadata/Enumeration\";\r\nimport { Format } from \"./Metadata/Format\";\r\nimport { InvertedUnit } from \"./Metadata/InvertedUnit\";\r\nimport { KindOfQuantity } from \"./Metadata/KindOfQuantity\";\r\nimport { Mixin } from \"./Metadata/Mixin\";\r\nimport { Phenomenon } from \"./Metadata/Phenomenon\";\r\nimport { AnyProperty, Property } from \"./Metadata/Property\";\r\nimport { PropertyCategory } from \"./Metadata/PropertyCategory\";\r\nimport { RelationshipClass, RelationshipConstraint } from \"./Metadata/RelationshipClass\";\r\nimport { Schema } from \"./Metadata/Schema\";\r\nimport { SchemaItem } from \"./Metadata/SchemaItem\";\r\nimport { Unit } from \"./Metadata/Unit\";\r\nimport { UnitSystem } from \"./Metadata/UnitSystem\";\r\n\r\n/**\r\n * Interface to allow schema traversal/deserialization workflows to visit\r\n * each part, item, class, etc. that exists in a given schema.\r\n * @public @preview\r\n */\r\nexport interface ISchemaPartVisitor {\r\n /**\r\n * Called for a partially loaded schema. During deserialization, this would\r\n * be after a schema and all its references are deserialized, but _before_\r\n * any of its items or custom attributes have been deserialized.\r\n * @param schema A partially-loaded Schema.\r\n */\r\n /* async */ visitEmptySchema?: (schema: Schema) => Promise<void>;\r\n\r\n /**\r\n * Called for a partially loaded schema. During deserialization, this would\r\n * be after a schema and all its references are deserialized, but _before_\r\n * any of its items or custom attributes have been deserialized.\r\n * @param schema A partially-loaded Schema.\r\n */\r\n visitEmptySchemaSync?: (schema: Schema) => void;\r\n\r\n /**\r\n * Called for a fully loaded schema.\r\n * @param schema A fully-loaded Schema.\r\n */\r\n /* async */ visitFullSchema?: (schema: Schema) => Promise<void>;\r\n\r\n /**\r\n * Called for a fully loaded schema.\r\n * @param schema A fully-loaded Schema.\r\n */\r\n visitFullSchemaSync?: (schema: Schema) => void;\r\n\r\n /**\r\n * Called for each [[SchemaItem]] instance.\r\n * @param schemaItem a SchemaItem object.\r\n */\r\n /* async */ visitSchemaItem?: (schemaItem: SchemaItem) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[SchemaItem]] instance.\r\n * @param schemaItem a SchemaItem object.\r\n */\r\n visitSchemaItemSync?: (schemaItem: SchemaItem) => void;\r\n\r\n /**\r\n * Called for each [[AnyClass]] instance.\r\n * @param ecClass an ECClass object.\r\n */\r\n /* async */ visitClass?: (ecClass: AnyClass) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[AnyClass]] instance.\r\n * @param ecClass an ECClass object.\r\n */\r\n visitClassSync?: (ecClass: AnyClass) => void;\r\n\r\n /**\r\n * Called for each [[AnyProperty]] instance of an ECClass.\r\n * @param property an AnyProperty object.\r\n */\r\n /* async */ visitProperty?: (property: AnyProperty) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[AnyProperty]] instance of an ECClass.\r\n * @param property an AnyProperty object.\r\n */\r\n visitPropertySync?: (property: AnyProperty) => void;\r\n\r\n /**\r\n * Called for each [[EntityClass]] instance.\r\n * @param entityClass an EntityClass object.\r\n */\r\n /* async */ visitEntityClass?: (entityClass: EntityClass) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[EntityClass]] instance.\r\n * @param entityClass an EntityClass object.\r\n */\r\n visitEntityClassSync?: (entityClass: EntityClass) => void;\r\n\r\n /**\r\n * Called for each [[StructClass]] instance.\r\n * @param structClass a StructClass object.\r\n */\r\n /* async */ visitStructClass?: (structClass: StructClass) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[StructClass]] instance.\r\n * @param structClass a StructClass object.\r\n */\r\n visitStructClassSync?: (structClass: StructClass) => void;\r\n\r\n /**\r\n * Called for each [[Mixin]] instance.\r\n * @param mixin a Mixin object.\r\n */\r\n /* async */ visitMixin?: (mixin: Mixin) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[Mixin]] instance.\r\n * @param mixin a Mixin object.\r\n */\r\n visitMixinSync?: (mixin: Mixin) => void;\r\n\r\n /**\r\n * Called for each [[RelationshipClass]] instance.\r\n * @param relationshipClass a RelationshipClass object.\r\n */\r\n /* async */ visitRelationshipClass?: (relationshipClass: RelationshipClass) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[RelationshipClass]] instance.\r\n * @param relationshipClass a RelationshipClass object.\r\n */\r\n visitRelationshipClassSync?: (relationshipClass: RelationshipClass) => void;\r\n\r\n /**\r\n * Called for each [[RelationshipConstraint]] of each RelationshipClass.\r\n * @param relationshipConstraint a RelationshipConstraint object.\r\n */\r\n /* async */ visitRelationshipConstraint?: (relationshipConstraint: RelationshipConstraint) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[RelationshipConstraint]] of each RelationshipClass.\r\n * @param relationshipConstraint a RelationshipConstraint object.\r\n */\r\n visitRelationshipConstraintSync?: (relationshipConstraint: RelationshipConstraint) => void;\r\n\r\n /**\r\n * Called for each [[CustomAttributeClass]] instance.\r\n * @param customAttributeClass a CustomAttributeClass object.\r\n */\r\n /* async */ visitCustomAttributeClass?: (customAttributeClass: CustomAttributeClass) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[CustomAttributeClass]] instance.\r\n * @param customAttributeClass a CustomAttributeClass object.\r\n */\r\n visitCustomAttributeClassSync?: (customAttributeClass: CustomAttributeClass) => void;\r\n\r\n /**\r\n * Called for each CustomAttribute container in the schema.\r\n * @param customAttributeContainer a CustomAttributeContainerProps object.\r\n */\r\n /* async */ visitCustomAttributeContainer?: (customAttributeContainer: CustomAttributeContainerProps) => Promise<void>;\r\n\r\n /**\r\n * Called for each CustomAttribute container in the schema.\r\n * @param customAttributeContainer a CustomAttributeContainerProps object.\r\n */\r\n visitCustomAttributeContainerSync?: (customAttributeContainer: CustomAttributeContainerProps) => void;\r\n\r\n /**\r\n * Called for each [[Enumeration]] instance.\r\n * @param enumeration an Enumeration object.\r\n */\r\n /* async */ visitEnumeration?: (enumeration: Enumeration) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[Enumeration]] instance.\r\n * @param enumeration an Enumeration object.\r\n */\r\n visitEnumerationSync?: (enumeration: Enumeration) => void;\r\n\r\n /**\r\n * Called for each [[KindOfQuantity]] instance.\r\n * @param koq a KindOfQuantity object.\r\n */\r\n /* async */ visitKindOfQuantity?: (koq: KindOfQuantity) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[KindOfQuantity]] instance.\r\n * @param koq a KindOfQuantity object.\r\n */\r\n visitKindOfQuantitySync?: (koq: KindOfQuantity) => void;\r\n\r\n /**\r\n * Called for each [[PropertyCategory]] instance.\r\n * @param category a PropertyCategory object.\r\n */\r\n /* async */ visitPropertyCategory?: (category: PropertyCategory) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[PropertyCategory]] instance.\r\n * @param category a PropertyCategory object.\r\n */\r\n visitPropertyCategorySync?: (category: PropertyCategory) => void;\r\n\r\n /**\r\n * Called for each [[Format]] instance.\r\n * @param format a Format object.\r\n */\r\n /* async */ visitFormat?: (format: Format) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[Format]] instance.\r\n * @param format a Format object.\r\n */\r\n visitFormatSync?: (format: Format) => void;\r\n\r\n /**\r\n * Called for each [[Unit]] instance.\r\n * @param unit a Unit object.\r\n */\r\n /* async */ visitUnit?: (unit: Unit) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[Unit]] instance.\r\n * @param unit a Unit object.\r\n */\r\n visitUnitSync?: (unit: Unit) => void;\r\n\r\n /**\r\n * Called for each [[InvertedUnit]] instance.\r\n * @param invertedUnit an InvertedUnit object.\r\n */\r\n /* async */ visitInvertedUnit?: (invertedUnit: InvertedUnit) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[InvertedUnit]] instance.\r\n * @param invertedUnit an InvertedUnit object.\r\n */\r\n visitInvertedUnitSync?: (invertedUnit: InvertedUnit) => void;\r\n\r\n /**\r\n * Called for each [[UnitSystem]] instance.\r\n * @param unitSystem a UnitSystem object.\r\n */\r\n /* async */ visitUnitSystem?: (unitSystem: UnitSystem) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[UnitSystem]] instance.\r\n * @param unitSystem a UnitSystem object.\r\n */\r\n visitUnitSystemSync?: (unitSystem: UnitSystem) => void;\r\n\r\n /**\r\n * Called for each [[Phenomenon]] instance.\r\n * @param phenomena a Phenomenon object.\r\n */\r\n /* async */ visitPhenomenon?: (phenomena: Phenomenon) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[Phenomenon]] instance.\r\n * @param phenomena a Phenomenon object.\r\n */\r\n visitPhenomenonSync?: (phenomena: Phenomenon) => void;\r\n\r\n /**\r\n * Called for each [[Constant]] instance.\r\n * @param constant a Constant object.\r\n */\r\n /* async */ visitConstant?: (constant: Constant) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[Constant]] instance.\r\n * @param constant a Constant object.\r\n */\r\n visitConstantSync?: (constant: Constant) => void;\r\n}\r\n\r\nfunction isCustomAttributeContainer(object: any): object is CustomAttributeContainerProps {\r\n return \"customAttributes\" in object;\r\n}\r\n\r\n/**\r\n * A helper class to call methods on the provided [[ISchemaPartVisitor]].\r\n * @public @preview\r\n */\r\nexport class SchemaPartVisitorDelegate {\r\n private _visitor: ISchemaPartVisitor;\r\n\r\n constructor(visitor: ISchemaPartVisitor) {\r\n this._visitor = visitor;\r\n }\r\n\r\n /**\r\n * Calls (async) visitEmptySchema or visitFullSchema on the configured [[ISchemaPartVisitor]].\r\n * @param schema The schema to pass to the visitor.\r\n * @param fullSchema Indicates if the schema is partially or fully-loaded.\r\n */\r\n public async visitSchema(schema: Schema, fullSchema: boolean = true): Promise<void> {\r\n if (!fullSchema && this._visitor.visitEmptySchema)\r\n await this._visitor.visitEmptySchema(schema);\r\n\r\n if (fullSchema && this._visitor.visitFullSchema)\r\n await this._visitor.visitFullSchema(schema);\r\n }\r\n\r\n /**\r\n * Calls (synchronously) visitEmptySchema or visitFullSchema on the configured [[ISchemaPartVisitor]].\r\n * @param schema The schema to pass to the visitor.\r\n * @param fullSchema Indicates if the schema is partially or fully-loaded.\r\n */\r\n public visitSchemaSync(schema: Schema, fullSchema: boolean = true): void {\r\n if (!fullSchema && this._visitor.visitEmptySchemaSync)\r\n this._visitor.visitEmptySchemaSync(schema);\r\n\r\n if (fullSchema && this._visitor.visitFullSchemaSync)\r\n this._visitor.visitFullSchemaSync(schema);\r\n }\r\n\r\n /**\r\n * Calls (async) the appropriate visit methods on the configured [[ISchemaPartVisitor]]\r\n * based on the type of the part specified.\r\n * @param schemaPart The schema part to pass to the visitor methods.\r\n */\r\n public async visitSchemaPart(schemaPart: AnyECType): Promise<void> {\r\n if (SchemaItem.isSchemaItem(schemaPart)) {\r\n await this.visitSchemaItem(schemaPart);\r\n } else if (Property.isProperty(schemaPart) && this._visitor.visitProperty) {\r\n await this._visitor.visitProperty(schemaPart);\r\n } else if (RelationshipConstraint.isRelationshipConstraint(schemaPart) && this._visitor.visitRelationshipConstraint) {\r\n await this._visitor.visitRelationshipConstraint(schemaPart);\r\n }\r\n\r\n if (isCustomAttributeContainer(schemaPart) && this._visitor.visitCustomAttributeContainer) {\r\n await this._visitor.visitCustomAttributeContainer(schemaPart);\r\n }\r\n }\r\n\r\n /**\r\n * Calls (synchronously) the appropriate visit methods on the configured [[ISchemaPartVisitor]]\r\n * based on the type of the part specified.\r\n * @param schemaPart The schema part to pass to the visitor methods.\r\n */\r\n public visitSchemaPartSync(schemaPart: AnyECType): void {\r\n if (SchemaItem.isSchemaItem(schemaPart)) {\r\n this.visitSchemaItemSync(schemaPart);\r\n } else if (Property.isProperty(schemaPart) && this._visitor.visitPropertySync) {\r\n this._visitor.visitPropertySync(schemaPart);\r\n } else if (RelationshipConstraint.isRelationshipConstraint(schemaPart) && this._visitor.visitRelationshipConstraintSync) {\r\n this._visitor.visitRelationshipConstraintSync(schemaPart);\r\n }\r\n\r\n if (isCustomAttributeContainer(schemaPart) && this._visitor.visitCustomAttributeContainerSync)\r\n this._visitor.visitCustomAttributeContainerSync(schemaPart);\r\n }\r\n\r\n private async visitSchemaItem(schemaItem: SchemaItem) {\r\n if (this._visitor.visitSchemaItem)\r\n await this._visitor.visitSchemaItem(schemaItem);\r\n\r\n if (ECClass.isECClass(schemaItem) && this._visitor.visitClass)\r\n await this._visitor.visitClass(schemaItem as AnyClass);\r\n\r\n switch (schemaItem.schemaItemType) {\r\n case SchemaItemType.Constant:\r\n if (this._visitor.visitConstant)\r\n await this._visitor.visitConstant(schemaItem as Constant);\r\n break;\r\n case SchemaItemType.CustomAttributeClass:\r\n if (this._visitor.visitCustomAttributeClass)\r\n await this._visitor.visitCustomAttributeClass(schemaItem as CustomAttributeClass);\r\n break;\r\n case SchemaItemType.EntityClass:\r\n if (this._visitor.visitEntityClass)\r\n await this._visitor.visitEntityClass(schemaItem as EntityClass);\r\n break;\r\n case SchemaItemType.Enumeration:\r\n if (this._visitor.visitEnumeration)\r\n await this._visitor.visitEnumeration(schemaItem as Enumeration);\r\n break;\r\n case SchemaItemType.Format:\r\n if (this._visitor.visitFormat)\r\n await this._visitor.visitFormat(schemaItem as Format);\r\n break;\r\n case SchemaItemType.InvertedUnit:\r\n if (this._visitor.visitInvertedUnit)\r\n await this._visitor.visitInvertedUnit(schemaItem as InvertedUnit);\r\n break;\r\n case SchemaItemType.KindOfQuantity:\r\n if (this._visitor.visitKindOfQuantity)\r\n await this._visitor.visitKindOfQuantity(schemaItem as KindOfQuantity);\r\n break;\r\n case SchemaItemType.Mixin:\r\n if (this._visitor.visitMixin)\r\n await this._visitor.visitMixin(schemaItem as Mixin);\r\n break;\r\n case SchemaItemType.Phenomenon:\r\n if (this._visitor.visitPhenomenon)\r\n await this._visitor.visitPhenomenon(schemaItem as Phenomenon);\r\n break;\r\n case SchemaItemType.PropertyCategory:\r\n if (this._visitor.visitPropertyCategory)\r\n await this._visitor.visitPropertyCategory(schemaItem as PropertyCategory);\r\n break;\r\n case SchemaItemType.RelationshipClass:\r\n if (this._visitor.visitRelationshipClass)\r\n await this._visitor.visitRelationshipClass(schemaItem as RelationshipClass);\r\n break;\r\n case SchemaItemType.StructClass:\r\n if (this._visitor.visitStructClass)\r\n await this._visitor.visitStructClass(schemaItem as StructClass);\r\n break;\r\n case SchemaItemType.Unit:\r\n if (this._visitor.visitUnit)\r\n await this._visitor.visitUnit(schemaItem as Unit);\r\n break;\r\n case SchemaItemType.UnitSystem:\r\n if (this._visitor.visitUnitSystem)\r\n await this._visitor.visitUnitSystem(schemaItem as UnitSystem);\r\n break;\r\n }\r\n }\r\n\r\n private visitSchemaItemSync(schemaItem: SchemaItem) {\r\n if (this._visitor.visitSchemaItemSync)\r\n this._visitor.visitSchemaItemSync(schemaItem);\r\n\r\n if (ECClass.isECClass(schemaItem) && this._visitor.visitClassSync)\r\n this._visitor.visitClassSync(schemaItem as AnyClass);\r\n\r\n switch (schemaItem.schemaItemType) {\r\n case SchemaItemType.Constant:\r\n if (this._visitor.visitConstantSync)\r\n this._visitor.visitConstantSync(schemaItem as Constant);\r\n break;\r\n case SchemaItemType.CustomAttributeClass:\r\n if (this._visitor.visitCustomAttributeClassSync)\r\n this._visitor.visitCustomAttributeClassSync(schemaItem as CustomAttributeClass);\r\n break;\r\n case SchemaItemType.EntityClass:\r\n if (this._visitor.visitEntityClassSync)\r\n this._visitor.visitEntityClassSync(schemaItem as EntityClass);\r\n break;\r\n case SchemaItemType.Enumeration:\r\n if (this._visitor.visitEnumerationSync)\r\n this._visitor.visitEnumerationSync(schemaItem as Enumeration);\r\n break;\r\n case SchemaItemType.Format:\r\n if (this._visitor.visitFormatSync)\r\n this._visitor.visitFormatSync(schemaItem as Format);\r\n break;\r\n case SchemaItemType.InvertedUnit:\r\n if (this._visitor.visitInvertedUnitSync)\r\n this._visitor.visitInvertedUnitSync(schemaItem as InvertedUnit);\r\n break;\r\n case SchemaItemType.KindOfQuantity:\r\n if (this._visitor.visitKindOfQuantitySync)\r\n this._visitor.visitKindOfQuantitySync(schemaItem as KindOfQuantity);\r\n break;\r\n case SchemaItemType.Mixin:\r\n if (this._visitor.visitMixinSync)\r\n this._visitor.visitMixinSync(schemaItem as Mixin);\r\n break;\r\n case SchemaItemType.Phenomenon:\r\n if (this._visitor.visitPhenomenonSync)\r\n this._visitor.visitPhenomenonSync(schemaItem as Phenomenon);\r\n break;\r\n case SchemaItemType.PropertyCategory:\r\n if (this._visitor.visitPropertyCategorySync)\r\n this._visitor.visitPropertyCategorySync(schemaItem as PropertyCategory);\r\n break;\r\n case SchemaItemType.RelationshipClass:\r\n if (this._visitor.visitRelationshipClassSync)\r\n this._visitor.visitRelationshipClassSync(schemaItem as RelationshipClass);\r\n break;\r\n case SchemaItemType.StructClass:\r\n if (this._visitor.visitStructClassSync)\r\n this._visitor.visitStructClassSync(schemaItem as StructClass);\r\n break;\r\n case SchemaItemType.Unit:\r\n if (this._visitor.visitUnitSync)\r\n this._visitor.visitUnitSync(schemaItem as Unit);\r\n break;\r\n case SchemaItemType.UnitSystem:\r\n if (this._visitor.visitUnitSystemSync)\r\n this._visitor.visitUnitSystemSync(schemaItem as UnitSystem);\r\n break;\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"SchemaPartVisitorDelegate.js","sourceRoot":"","sources":["../../src/SchemaPartVisitorDelegate.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,2CAA6C;AAE7C,4CAAwD;AAWxD,kDAA4D;AAE5D,oEAAyF;AAEzF,sDAAmD;AA2QnD,SAAS,0BAA0B,CAAC,MAAW;IAC7C,OAAO,kBAAkB,IAAI,MAAM,CAAC;AACtC,CAAC;AAED;;;GAGG;AACH,MAAa,yBAAyB;IAC5B,QAAQ,CAAqB;IAErC,YAAY,OAA2B;QACrC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,WAAW,CAAC,MAAc,EAAE,aAAsB,IAAI;QACjE,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,QAAQ,CAAC,gBAAgB;YAC/C,MAAM,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;QAE/C,IAAI,UAAU,IAAI,IAAI,CAAC,QAAQ,CAAC,eAAe;YAC7C,MAAM,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;IAED;;;;OAIG;IACI,eAAe,CAAC,MAAc,EAAE,aAAsB,IAAI;QAC/D,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,QAAQ,CAAC,oBAAoB;YACnD,IAAI,CAAC,QAAQ,CAAC,oBAAoB,CAAC,MAAM,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AC,QAAQ,CAAC,0BAA0B;oBAC1C,IAAI,CAAC,QAAQ,CAAC,0BAA0B,CAAC,UAA+B,CAAC,CAAC;gBAC5E,MAAM;YACR,KAAK,0BAAc,CAAC,WAAW;gBAC7B,IAAI,IAAI,CAAC,QAAQ,CAAC,oBAAoB;oBACpC,IAAI,CAAC,QAAQ,CAAC,oBAAoB,CAAC,UAAyB,CAAC,CAAC;gBAChE,MAAM;YACR,KAAK,0BAAc,CAAC,IAAI;gBACtB,IAAI,IAAI,CAAC,QAAQ,CAAC,aAAa;oBAC7B,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAkB,CAAC,CAAC;gBAClD,MAAM;YACR,KAAK,0BAAc,CAAC,UAAU;gBAC5B,IAAI,IAAI,CAAC,QAAQ,CAAC,mBAAmB;oBACnC,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;gBAChD,MAAM;QACV,CAAC;IACH,CAAC;CACF;AA3MD,8DA2MC","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\r\nimport { SchemaItemType } from \"./ECObjects\";\r\nimport { AnyClass, AnyECType } from \"./Interfaces\";\r\nimport { ECClass, StructClass } from \"./Metadata/Class\";\r\nimport { Constant } from \"./Metadata/Constant\";\r\nimport { CustomAttributeContainerProps } from \"./Metadata/CustomAttribute\";\r\nimport { CustomAttributeClass } from \"./Metadata/CustomAttributeClass\";\r\nimport { EntityClass } from \"./Metadata/EntityClass\";\r\nimport { Enumeration } from \"./Metadata/Enumeration\";\r\nimport { Format } from \"./Metadata/Format\";\r\nimport { InvertedUnit } from \"./Metadata/InvertedUnit\";\r\nimport { KindOfQuantity } from \"./Metadata/KindOfQuantity\";\r\nimport { Mixin } from \"./Metadata/Mixin\";\r\nimport { Phenomenon } from \"./Metadata/Phenomenon\";\r\nimport { AnyProperty, Property } from \"./Metadata/Property\";\r\nimport { PropertyCategory } from \"./Metadata/PropertyCategory\";\r\nimport { RelationshipClass, RelationshipConstraint } from \"./Metadata/RelationshipClass\";\r\nimport { Schema } from \"./Metadata/Schema\";\r\nimport { SchemaItem } from \"./Metadata/SchemaItem\";\r\nimport { Unit } from \"./Metadata/Unit\";\r\nimport { UnitSystem } from \"./Metadata/UnitSystem\";\r\n\r\n/**\r\n * Interface to allow schema traversal/deserialization workflows to visit\r\n * each part, item, class, etc. that exists in a given schema.\r\n * @public @preview\r\n */\r\nexport interface ISchemaPartVisitor {\r\n /**\r\n * Called for a partially loaded schema. During deserialization, this would\r\n * be after a schema and all its references are deserialized, but _before_\r\n * any of its items or custom attributes have been deserialized.\r\n * @param schema A partially-loaded Schema.\r\n */\r\n /* async */ visitEmptySchema?: (schema: Schema) => Promise<void>;\r\n\r\n /**\r\n * Called for a partially loaded schema. During deserialization, this would\r\n * be after a schema and all its references are deserialized, but _before_\r\n * any of its items or custom attributes have been deserialized.\r\n * @param schema A partially-loaded Schema.\r\n */\r\n visitEmptySchemaSync?: (schema: Schema) => void;\r\n\r\n /**\r\n * Called for a fully loaded schema.\r\n * @param schema A fully-loaded Schema.\r\n */\r\n /* async */ visitFullSchema?: (schema: Schema) => Promise<void>;\r\n\r\n /**\r\n * Called for a fully loaded schema.\r\n * @param schema A fully-loaded Schema.\r\n */\r\n visitFullSchemaSync?: (schema: Schema) => void;\r\n\r\n /**\r\n * Called for each [[SchemaItem]] instance.\r\n * @param schemaItem a SchemaItem object.\r\n */\r\n /* async */ visitSchemaItem?: (schemaItem: SchemaItem) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[SchemaItem]] instance.\r\n * @param schemaItem a SchemaItem object.\r\n */\r\n visitSchemaItemSync?: (schemaItem: SchemaItem) => void;\r\n\r\n /**\r\n * Called for each [[AnyClass]] instance.\r\n * @param ecClass an ECClass object.\r\n */\r\n /* async */ visitClass?: (ecClass: AnyClass) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[AnyClass]] instance.\r\n * @param ecClass an ECClass object.\r\n */\r\n visitClassSync?: (ecClass: AnyClass) => void;\r\n\r\n /**\r\n * Called for each [[AnyProperty]] instance of an ECClass.\r\n * @param property an AnyProperty object.\r\n */\r\n /* async */ visitProperty?: (property: AnyProperty) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[AnyProperty]] instance of an ECClass.\r\n * @param property an AnyProperty object.\r\n */\r\n visitPropertySync?: (property: AnyProperty) => void;\r\n\r\n /**\r\n * Called for each [[EntityClass]] instance.\r\n * @param entityClass an EntityClass object.\r\n */\r\n /* async */ visitEntityClass?: (entityClass: EntityClass) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[EntityClass]] instance.\r\n * @param entityClass an EntityClass object.\r\n */\r\n visitEntityClassSync?: (entityClass: EntityClass) => void;\r\n\r\n /**\r\n * Called for each [[StructClass]] instance.\r\n * @param structClass a StructClass object.\r\n */\r\n /* async */ visitStructClass?: (structClass: StructClass) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[StructClass]] instance.\r\n * @param structClass a StructClass object.\r\n */\r\n visitStructClassSync?: (structClass: StructClass) => void;\r\n\r\n /**\r\n * Called for each [[Mixin]] instance.\r\n * @param mixin a Mixin object.\r\n */\r\n /* async */ visitMixin?: (mixin: Mixin) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[Mixin]] instance.\r\n * @param mixin a Mixin object.\r\n */\r\n visitMixinSync?: (mixin: Mixin) => void;\r\n\r\n /**\r\n * Called for each [[RelationshipClass]] instance.\r\n * @param relationshipClass a RelationshipClass object.\r\n */\r\n /* async */ visitRelationshipClass?: (relationshipClass: RelationshipClass) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[RelationshipClass]] instance.\r\n * @param relationshipClass a RelationshipClass object.\r\n */\r\n visitRelationshipClassSync?: (relationshipClass: RelationshipClass) => void;\r\n\r\n /**\r\n * Called for each [[RelationshipConstraint]] of each RelationshipClass.\r\n * @param relationshipConstraint a RelationshipConstraint object.\r\n */\r\n /* async */ visitRelationshipConstraint?: (relationshipConstraint: RelationshipConstraint) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[RelationshipConstraint]] of each RelationshipClass.\r\n * @param relationshipConstraint a RelationshipConstraint object.\r\n */\r\n visitRelationshipConstraintSync?: (relationshipConstraint: RelationshipConstraint) => void;\r\n\r\n /**\r\n * Called for each [[CustomAttributeClass]] instance.\r\n * @param customAttributeClass a CustomAttributeClass object.\r\n */\r\n /* async */ visitCustomAttributeClass?: (customAttributeClass: CustomAttributeClass) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[CustomAttributeClass]] instance.\r\n * @param customAttributeClass a CustomAttributeClass object.\r\n */\r\n visitCustomAttributeClassSync?: (customAttributeClass: CustomAttributeClass) => void;\r\n\r\n /**\r\n * Called for each CustomAttribute container in the schema.\r\n * @param customAttributeContainer a CustomAttributeContainerProps object.\r\n */\r\n /* async */ visitCustomAttributeContainer?: (customAttributeContainer: CustomAttributeContainerProps) => Promise<void>;\r\n\r\n /**\r\n * Called for each CustomAttribute container in the schema.\r\n * @param customAttributeContainer a CustomAttributeContainerProps object.\r\n */\r\n visitCustomAttributeContainerSync?: (customAttributeContainer: CustomAttributeContainerProps) => void;\r\n\r\n /**\r\n * Called for each [[Enumeration]] instance.\r\n * @param enumeration an Enumeration object.\r\n */\r\n /* async */ visitEnumeration?: (enumeration: Enumeration) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[Enumeration]] instance.\r\n * @param enumeration an Enumeration object.\r\n */\r\n visitEnumerationSync?: (enumeration: Enumeration) => void;\r\n\r\n /**\r\n * Called for each [[KindOfQuantity]] instance.\r\n * @param koq a KindOfQuantity object.\r\n */\r\n /* async */ visitKindOfQuantity?: (koq: KindOfQuantity) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[KindOfQuantity]] instance.\r\n * @param koq a KindOfQuantity object.\r\n */\r\n visitKindOfQuantitySync?: (koq: KindOfQuantity) => void;\r\n\r\n /**\r\n * Called for each [[PropertyCategory]] instance.\r\n * @param category a PropertyCategory object.\r\n */\r\n /* async */ visitPropertyCategory?: (category: PropertyCategory) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[PropertyCategory]] instance.\r\n * @param category a PropertyCategory object.\r\n */\r\n visitPropertyCategorySync?: (category: PropertyCategory) => void;\r\n\r\n /**\r\n * Called for each [[Format]] instance.\r\n * @param format a Format object.\r\n */\r\n /* async */ visitFormat?: (format: Format) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[Format]] instance.\r\n * @param format a Format object.\r\n */\r\n visitFormatSync?: (format: Format) => void;\r\n\r\n /**\r\n * Called for each [[Unit]] instance.\r\n * @param unit a Unit object.\r\n */\r\n /* async */ visitUnit?: (unit: Unit) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[Unit]] instance.\r\n * @param unit a Unit object.\r\n */\r\n visitUnitSync?: (unit: Unit) => void;\r\n\r\n /**\r\n * Called for each [[InvertedUnit]] instance.\r\n * @param invertedUnit an InvertedUnit object.\r\n */\r\n /* async */ visitInvertedUnit?: (invertedUnit: InvertedUnit) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[InvertedUnit]] instance.\r\n * @param invertedUnit an InvertedUnit object.\r\n */\r\n visitInvertedUnitSync?: (invertedUnit: InvertedUnit) => void;\r\n\r\n /**\r\n * Called for each [[UnitSystem]] instance.\r\n * @param unitSystem a UnitSystem object.\r\n */\r\n /* async */ visitUnitSystem?: (unitSystem: UnitSystem) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[UnitSystem]] instance.\r\n * @param unitSystem a UnitSystem object.\r\n */\r\n visitUnitSystemSync?: (unitSystem: UnitSystem) => void;\r\n\r\n /**\r\n * Called for each [[Phenomenon]] instance.\r\n * @param phenomena a Phenomenon object.\r\n */\r\n /* async */ visitPhenomenon?: (phenomena: Phenomenon) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[Phenomenon]] instance.\r\n * @param phenomena a Phenomenon object.\r\n */\r\n visitPhenomenonSync?: (phenomena: Phenomenon) => void;\r\n\r\n /**\r\n * Called for each [[Constant]] instance.\r\n * @param constant a Constant object.\r\n */\r\n /* async */ visitConstant?: (constant: Constant) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[Constant]] instance.\r\n * @param constant a Constant object.\r\n */\r\n visitConstantSync?: (constant: Constant) => void;\r\n}\r\n\r\nfunction isCustomAttributeContainer(object: any): object is CustomAttributeContainerProps {\r\n return \"customAttributes\" in object;\r\n}\r\n\r\n/**\r\n * A helper class to call methods on the provided [[ISchemaPartVisitor]].\r\n * @public @preview\r\n */\r\nexport class SchemaPartVisitorDelegate {\r\n private _visitor: ISchemaPartVisitor;\r\n\r\n constructor(visitor: ISchemaPartVisitor) {\r\n this._visitor = visitor;\r\n }\r\n\r\n /**\r\n * Calls (async) visitEmptySchema or visitFullSchema on the configured [[ISchemaPartVisitor]].\r\n * @param schema The schema to pass to the visitor.\r\n * @param fullSchema Indicates if the schema is partially or fully-loaded.\r\n */\r\n public async visitSchema(schema: Schema, fullSchema: boolean = true): Promise<void> {\r\n if (!fullSchema && this._visitor.visitEmptySchema)\r\n await this._visitor.visitEmptySchema(schema);\r\n\r\n if (fullSchema && this._visitor.visitFullSchema)\r\n await this._visitor.visitFullSchema(schema);\r\n }\r\n\r\n /**\r\n * Calls (synchronously) visitEmptySchema or visitFullSchema on the configured [[ISchemaPartVisitor]].\r\n * @param schema The schema to pass to the visitor.\r\n * @param fullSchema Indicates if the schema is partially or fully-loaded.\r\n */\r\n public visitSchemaSync(schema: Schema, fullSchema: boolean = true): void {\r\n if (!fullSchema && this._visitor.visitEmptySchemaSync)\r\n this._visitor.visitEmptySchemaSync(schema);\r\n\r\n if (fullSchema && this._visitor.visitFullSchemaSync)\r\n this._visitor.visitFullSchemaSync(schema);\r\n }\r\n\r\n /**\r\n * Calls (async) the appropriate visit methods on the configured [[ISchemaPartVisitor]]\r\n * based on the type of the part specified.\r\n * @param schemaPart The schema part to pass to the visitor methods.\r\n */\r\n public async visitSchemaPart(schemaPart: AnyECType): Promise<void> {\r\n if (SchemaItem.isSchemaItem(schemaPart)) {\r\n await this.visitSchemaItem(schemaPart);\r\n } else if (Property.isProperty(schemaPart) && this._visitor.visitProperty) {\r\n await this._visitor.visitProperty(schemaPart);\r\n } else if (RelationshipConstraint.isRelationshipConstraint(schemaPart) && this._visitor.visitRelationshipConstraint) {\r\n await this._visitor.visitRelationshipConstraint(schemaPart);\r\n }\r\n\r\n if (isCustomAttributeContainer(schemaPart) && this._visitor.visitCustomAttributeContainer) {\r\n await this._visitor.visitCustomAttributeContainer(schemaPart);\r\n }\r\n }\r\n\r\n /**\r\n * Calls (synchronously) the appropriate visit methods on the configured [[ISchemaPartVisitor]]\r\n * based on the type of the part specified.\r\n * @param schemaPart The schema part to pass to the visitor methods.\r\n */\r\n public visitSchemaPartSync(schemaPart: AnyECType): void {\r\n if (SchemaItem.isSchemaItem(schemaPart)) {\r\n this.visitSchemaItemSync(schemaPart);\r\n } else if (Property.isProperty(schemaPart) && this._visitor.visitPropertySync) {\r\n this._visitor.visitPropertySync(schemaPart);\r\n } else if (RelationshipConstraint.isRelationshipConstraint(schemaPart) && this._visitor.visitRelationshipConstraintSync) {\r\n this._visitor.visitRelationshipConstraintSync(schemaPart);\r\n }\r\n\r\n if (isCustomAttributeContainer(schemaPart) && this._visitor.visitCustomAttributeContainerSync)\r\n this._visitor.visitCustomAttributeContainerSync(schemaPart);\r\n }\r\n\r\n private async visitSchemaItem(schemaItem: SchemaItem) {\r\n if (this._visitor.visitSchemaItem)\r\n await this._visitor.visitSchemaItem(schemaItem);\r\n\r\n if (ECClass.isECClass(schemaItem) && this._visitor.visitClass)\r\n await this._visitor.visitClass(schemaItem);\r\n\r\n switch (schemaItem.schemaItemType) {\r\n case SchemaItemType.Constant:\r\n if (this._visitor.visitConstant)\r\n await this._visitor.visitConstant(schemaItem as Constant);\r\n break;\r\n case SchemaItemType.CustomAttributeClass:\r\n if (this._visitor.visitCustomAttributeClass)\r\n await this._visitor.visitCustomAttributeClass(schemaItem as CustomAttributeClass);\r\n break;\r\n case SchemaItemType.EntityClass:\r\n if (this._visitor.visitEntityClass)\r\n await this._visitor.visitEntityClass(schemaItem as EntityClass);\r\n break;\r\n case SchemaItemType.Enumeration:\r\n if (this._visitor.visitEnumeration)\r\n await this._visitor.visitEnumeration(schemaItem as Enumeration);\r\n break;\r\n case SchemaItemType.Format:\r\n if (this._visitor.visitFormat)\r\n await this._visitor.visitFormat(schemaItem as Format);\r\n break;\r\n case SchemaItemType.InvertedUnit:\r\n if (this._visitor.visitInvertedUnit)\r\n await this._visitor.visitInvertedUnit(schemaItem as InvertedUnit);\r\n break;\r\n case SchemaItemType.KindOfQuantity:\r\n if (this._visitor.visitKindOfQuantity)\r\n await this._visitor.visitKindOfQuantity(schemaItem as KindOfQuantity);\r\n break;\r\n case SchemaItemType.Mixin:\r\n if (this._visitor.visitMixin)\r\n await this._visitor.visitMixin(schemaItem as Mixin);\r\n break;\r\n case SchemaItemType.Phenomenon:\r\n if (this._visitor.visitPhenomenon)\r\n await this._visitor.visitPhenomenon(schemaItem as Phenomenon);\r\n break;\r\n case SchemaItemType.PropertyCategory:\r\n if (this._visitor.visitPropertyCategory)\r\n await this._visitor.visitPropertyCategory(schemaItem as PropertyCategory);\r\n break;\r\n case SchemaItemType.RelationshipClass:\r\n if (this._visitor.visitRelationshipClass)\r\n await this._visitor.visitRelationshipClass(schemaItem as RelationshipClass);\r\n break;\r\n case SchemaItemType.StructClass:\r\n if (this._visitor.visitStructClass)\r\n await this._visitor.visitStructClass(schemaItem as StructClass);\r\n break;\r\n case SchemaItemType.Unit:\r\n if (this._visitor.visitUnit)\r\n await this._visitor.visitUnit(schemaItem as Unit);\r\n break;\r\n case SchemaItemType.UnitSystem:\r\n if (this._visitor.visitUnitSystem)\r\n await this._visitor.visitUnitSystem(schemaItem);\r\n break;\r\n }\r\n }\r\n\r\n private visitSchemaItemSync(schemaItem: SchemaItem) {\r\n if (this._visitor.visitSchemaItemSync)\r\n this._visitor.visitSchemaItemSync(schemaItem);\r\n\r\n if (ECClass.isECClass(schemaItem) && this._visitor.visitClassSync)\r\n this._visitor.visitClassSync(schemaItem);\r\n\r\n switch (schemaItem.schemaItemType) {\r\n case SchemaItemType.Constant:\r\n if (this._visitor.visitConstantSync)\r\n this._visitor.visitConstantSync(schemaItem as Constant);\r\n break;\r\n case SchemaItemType.CustomAttributeClass:\r\n if (this._visitor.visitCustomAttributeClassSync)\r\n this._visitor.visitCustomAttributeClassSync(schemaItem as CustomAttributeClass);\r\n break;\r\n case SchemaItemType.EntityClass:\r\n if (this._visitor.visitEntityClassSync)\r\n this._visitor.visitEntityClassSync(schemaItem as EntityClass);\r\n break;\r\n case SchemaItemType.Enumeration:\r\n if (this._visitor.visitEnumerationSync)\r\n this._visitor.visitEnumerationSync(schemaItem as Enumeration);\r\n break;\r\n case SchemaItemType.Format:\r\n if (this._visitor.visitFormatSync)\r\n this._visitor.visitFormatSync(schemaItem as Format);\r\n break;\r\n case SchemaItemType.InvertedUnit:\r\n if (this._visitor.visitInvertedUnitSync)\r\n this._visitor.visitInvertedUnitSync(schemaItem as InvertedUnit);\r\n break;\r\n case SchemaItemType.KindOfQuantity:\r\n if (this._visitor.visitKindOfQuantitySync)\r\n this._visitor.visitKindOfQuantitySync(schemaItem as KindOfQuantity);\r\n break;\r\n case SchemaItemType.Mixin:\r\n if (this._visitor.visitMixinSync)\r\n this._visitor.visitMixinSync(schemaItem as Mixin);\r\n break;\r\n case SchemaItemType.Phenomenon:\r\n if (this._visitor.visitPhenomenonSync)\r\n this._visitor.visitPhenomenonSync(schemaItem as Phenomenon);\r\n break;\r\n case SchemaItemType.PropertyCategory:\r\n if (this._visitor.visitPropertyCategorySync)\r\n this._visitor.visitPropertyCategorySync(schemaItem as PropertyCategory);\r\n break;\r\n case SchemaItemType.RelationshipClass:\r\n if (this._visitor.visitRelationshipClassSync)\r\n this._visitor.visitRelationshipClassSync(schemaItem as RelationshipClass);\r\n break;\r\n case SchemaItemType.StructClass:\r\n if (this._visitor.visitStructClassSync)\r\n this._visitor.visitStructClassSync(schemaItem as StructClass);\r\n break;\r\n case SchemaItemType.Unit:\r\n if (this._visitor.visitUnitSync)\r\n this._visitor.visitUnitSync(schemaItem as Unit);\r\n break;\r\n case SchemaItemType.UnitSystem:\r\n if (this._visitor.visitUnitSystemSync)\r\n this._visitor.visitUnitSystemSync(schemaItem);\r\n break;\r\n }\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Parser.d.ts","sourceRoot":"","sources":["../../../src/UnitConversion/Parser.ts"],"names":[],"mappings":"AAeA,gBAAgB;AAChB,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,gBAAgB;AAChB,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAsBnF"}
1
+ {"version":3,"file":"Parser.d.ts","sourceRoot":"","sources":["../../../src/UnitConversion/Parser.ts"],"names":[],"mappings":"AAeA,gBAAgB;AAChB,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,gBAAgB;AAChB,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAwBnF"}
@@ -26,8 +26,10 @@ function parseDefinition(definition) {
26
26
  const constant = tokens[Tokens.Bracket] !== undefined;
27
27
  if (unitMap.has(name)) {
28
28
  const currentDefinition = unitMap.get(name);
29
- currentDefinition.exponent += exponent;
30
- unitMap.set(name, currentDefinition);
29
+ if (currentDefinition) {
30
+ currentDefinition.exponent += exponent;
31
+ unitMap.set(name, currentDefinition);
32
+ }
31
33
  }
32
34
  else {
33
35
  unitMap.set(name, { name, exponent, constant });
@@ -1 +1 @@
1
- {"version":3,"file":"Parser.js","sourceRoot":"","sources":["../../../src/UnitConversion/Parser.ts"],"names":[],"mappings":";;AAuBA,0CAsBC;AA7CD;;;+FAG+F;AAC/F,MAAM,aAAa,GAAG,8EAA8E,CAAC;AACrG,MAAM,QAAQ,GAAG,uDAAuD,CAAC;AACzE,MAAM,EAAE,GAAG,GAAG,CAAC;AAEf,gBAAgB;AAChB,IAAK,MAIJ;AAJD,WAAK,MAAM;IACT,yCAAW,CAAA;IACX,mCAAQ,CAAA;IACR,2CAAY,CAAA;AACd,CAAC,EAJI,MAAM,KAAN,MAAM,QAIV;AASD,gBAAgB;AAChB,SAAgB,eAAe,CAAC,UAAkB;IAChD,MAAM,OAAO,GAAoC,IAAI,GAAG,EAAE,CAAC;IAE3D,IAAI,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QACnC,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;YACxC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YACpC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACjC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC/E,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,SAAS,CAAC;YACtD,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACtB,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;gBAC7C,iBAAiB,CAAC,QAAQ,IAAI,QAAQ,CAAC;gBACvC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;YACvC,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;YAClD,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;AACH,CAAC","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\nconst expressionRgx = /^(([A-Z]\\w*:)?([A-Z]\\w*|\\[([A-Z]\\w*:)?[A-Z]\\w*\\])(\\(-?\\d+\\))?(\\*(?!$)|$))+$/i;\r\nconst tokenRgx = /(?:(\\[)?((?:[A-Z]\\w*:)?[A-Z]\\w*)\\]?)(?:\\((-?\\d+)\\))?/i;\r\nconst sp = \"*\";\r\n\r\n/** @internal */\r\nenum Tokens {\r\n Bracket = 1,\r\n Word = 2,\r\n Exponent = 3,\r\n}\r\n\r\n/** @internal */\r\nexport interface DefinitionFragment {\r\n name: string;\r\n exponent: number;\r\n constant: boolean;\r\n}\r\n\r\n/** @internal */\r\nexport function parseDefinition(definition: string): Map<string, DefinitionFragment> {\r\n const unitMap: Map<string, DefinitionFragment> = new Map();\r\n\r\n if (expressionRgx.test(definition)) {\r\n for (const unit of definition.split(sp)) {\r\n const tokens = unit.split(tokenRgx);\r\n const name = tokens[Tokens.Word];\r\n const exponent = tokens[Tokens.Exponent] ? Number(tokens[Tokens.Exponent]) : 1;\r\n const constant = tokens[Tokens.Bracket] !== undefined;\r\n if (unitMap.has(name)) {\r\n const currentDefinition = unitMap.get(name)!;\r\n currentDefinition.exponent += exponent;\r\n unitMap.set(name, currentDefinition);\r\n } else {\r\n unitMap.set(name, { name, exponent, constant });\r\n }\r\n }\r\n\r\n return unitMap;\r\n } else {\r\n throw new Error(\"Invalid definition expression.\");\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"Parser.js","sourceRoot":"","sources":["../../../src/UnitConversion/Parser.ts"],"names":[],"mappings":";;AAuBA,0CAwBC;AA/CD;;;+FAG+F;AAC/F,MAAM,aAAa,GAAG,8EAA8E,CAAC;AACrG,MAAM,QAAQ,GAAG,uDAAuD,CAAC;AACzE,MAAM,EAAE,GAAG,GAAG,CAAC;AAEf,gBAAgB;AAChB,IAAK,MAIJ;AAJD,WAAK,MAAM;IACT,yCAAW,CAAA;IACX,mCAAQ,CAAA;IACR,2CAAY,CAAA;AACd,CAAC,EAJI,MAAM,KAAN,MAAM,QAIV;AASD,gBAAgB;AAChB,SAAgB,eAAe,CAAC,UAAkB;IAChD,MAAM,OAAO,GAAoC,IAAI,GAAG,EAAE,CAAC;IAE3D,IAAI,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QACnC,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;YACxC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YACpC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACjC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC/E,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,SAAS,CAAC;YACtD,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACtB,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBAC5C,IAAI,iBAAiB,EAAE,CAAC;oBACtB,iBAAiB,CAAC,QAAQ,IAAI,QAAQ,CAAC;oBACvC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;gBACvC,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;YAClD,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;AACH,CAAC","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\nconst expressionRgx = /^(([A-Z]\\w*:)?([A-Z]\\w*|\\[([A-Z]\\w*:)?[A-Z]\\w*\\])(\\(-?\\d+\\))?(\\*(?!$)|$))+$/i;\r\nconst tokenRgx = /(?:(\\[)?((?:[A-Z]\\w*:)?[A-Z]\\w*)\\]?)(?:\\((-?\\d+)\\))?/i;\r\nconst sp = \"*\";\r\n\r\n/** @internal */\r\nenum Tokens {\r\n Bracket = 1,\r\n Word = 2,\r\n Exponent = 3,\r\n}\r\n\r\n/** @internal */\r\nexport interface DefinitionFragment {\r\n name: string;\r\n exponent: number;\r\n constant: boolean;\r\n}\r\n\r\n/** @internal */\r\nexport function parseDefinition(definition: string): Map<string, DefinitionFragment> {\r\n const unitMap: Map<string, DefinitionFragment> = new Map();\r\n\r\n if (expressionRgx.test(definition)) {\r\n for (const unit of definition.split(sp)) {\r\n const tokens = unit.split(tokenRgx);\r\n const name = tokens[Tokens.Word];\r\n const exponent = tokens[Tokens.Exponent] ? Number(tokens[Tokens.Exponent]) : 1;\r\n const constant = tokens[Tokens.Bracket] !== undefined;\r\n if (unitMap.has(name)) {\r\n const currentDefinition = unitMap.get(name);\r\n if (currentDefinition) {\r\n currentDefinition.exponent += exponent;\r\n unitMap.set(name, currentDefinition);\r\n }\r\n } else {\r\n unitMap.set(name, { name, exponent, constant });\r\n }\r\n }\r\n\r\n return unitMap;\r\n } else {\r\n throw new Error(\"Invalid definition expression.\");\r\n }\r\n}\r\n"]}
@@ -34,7 +34,7 @@ class GraphUtils {
34
34
  }
35
35
  else {
36
36
  if (baseUnitsMap.has(key)) {
37
- const oldExponent = baseUnitsMap.get(key);
37
+ const oldExponent = baseUnitsMap.get(key) ?? 0;
38
38
  baseUnitsMap.set(key, oldExponent + accumulatedExponent);
39
39
  }
40
40
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"UnitTree.js","sourceRoot":"","sources":["../../../src/UnitConversion/UnitTree.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,sDAAkE;AAIlE,uDAAoD;AAEpD,4CAAwD;AACxD,4CAA8C;AAC9C,qDAAkD;AAClD,qCAA+D;AAC/D,mCAAgC;AAEhC,gBAAgB;AAChB,MAAa,UAAU;IACrB;;;;;;;OAOG;IACI,MAAM,CAAC,SAAS,CAAI,MAA8B,EAAE,GAAW,EAAE,EAAuC,EAAE,OAAU,EAAE,YAAiC,EAAE,mBAA2B;QACzL,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QACtC,IAAI,CAAC,GAAG,OAAO,CAAC;QAChB,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxB,CAAC,GAAG,QAAQ,CAAC,MAAM,CACjB,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE;gBACV,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC;gBACtB,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;gBAChD,OAAO,UAAU,CAAC,SAAS,CAAC,MAAM,EAAE,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,aAAa,CAAC,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,aAAa,CAAC,GAAG,CAAC,YAAY,EAAE,+BAAc,CAAC,QAAQ,CAAC,CAAC;QAC3D,CAAC;QACD,OAAO,aAAa,CAAC;IACvB,CAAC;CACF;AAlJD,8BAkJC","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\nimport { BentleyError, BentleyStatus } from \"@itwin/core-bentley\";\r\nimport { SchemaContext } from \"../Context\";\r\nimport { Constant } from \"../Metadata/Constant\";\r\nimport { Schema } from \"../Metadata/Schema\";\r\nimport { SchemaItem } from \"../Metadata/SchemaItem\";\r\nimport { Unit } from \"../Metadata/Unit\";\r\nimport { SchemaItemKey, SchemaKey } from \"../SchemaKey\";\r\nimport { SchemaItemType } from \"../ECObjects\";\r\nimport { UnitConversion } from \"./UnitConversion\";\r\nimport { DefinitionFragment, parseDefinition } from \"./Parser\";\r\nimport { Graph } from \"./Graph\";\r\n\r\n/** @internal */\r\nexport class GraphUtils {\r\n /**\r\n * DFS traversal - Post order\r\n * @param _graph Graph to traverse\r\n * @param start Starting node\r\n * @param keyFrom Get key from label\r\n * @param op Reducing function\r\n * @param initial Initial label\r\n */\r\n public static dfsReduce<T>(_graph: Graph<Unit | Constant>, key: string, op: (previous: T, current: string) => T, initial: T, baseUnitsMap: Map<string, number>, accumulatedExponent: number): T {\r\n const outEdges = _graph.outEdges(key);\r\n let t = initial;\r\n if (outEdges.length > 0) {\r\n t = outEdges.reduce<T>(\r\n (p, edge) => {\r\n const { v, w } = edge;\r\n const edgeExponent = _graph.edge(v, w).exponent;\r\n return GraphUtils.dfsReduce(_graph, edge.w, op, p, baseUnitsMap, accumulatedExponent * edgeExponent);\r\n },\r\n t,\r\n );\r\n } else {\r\n if (baseUnitsMap.has(key)) {\r\n const oldExponent = baseUnitsMap.get(key)!;\r\n baseUnitsMap.set(key, oldExponent + accumulatedExponent);\r\n } else {\r\n baseUnitsMap.set(key, accumulatedExponent);\r\n }\r\n }\r\n\r\n return op(t, key);\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class UnitGraph {\r\n private _graph = new Graph<Unit | Constant>();\r\n private _unitsInProgress = new Map<string, Promise<void>>();\r\n\r\n constructor(private _context: SchemaContext) {\r\n this._graph.setGraph(\"Unit tree processor\");\r\n }\r\n\r\n /**\r\n * Tries to find the unit/constant given by name in currentSchema\r\n * @param name SchemaItem name or parsed definition to find unit of; Could be {schemaName}:{schemaItemName} or {alias}:{schemaItemName} or {schemaItemName}\r\n * @param currentSchema schema to find name in; name could also be in a referenced schema of current schema\r\n */\r\n public async resolveUnit(name: string, currentSchema: Schema): Promise<Unit | Constant> {\r\n let [schemaName] = SchemaItem.parseFullName(name);\r\n const [, schemaItemName] = SchemaItem.parseFullName(name);\r\n\r\n if (schemaName !== \"\") {\r\n // Check if schemaName is schemaName or alias\r\n const ref = currentSchema.getReferenceSync(schemaName);\r\n const refName = currentSchema.getReferenceNameByAlias(schemaName);\r\n if (ref) {\r\n // Got schema by schemaName\r\n schemaName = ref.name;\r\n } else if (refName) {\r\n // Got schema by alias\r\n schemaName = refName;\r\n } else {\r\n // Didn't match any referenced schema, check if it is current schemaName or alias\r\n if (schemaName === currentSchema.name || schemaName === currentSchema.alias)\r\n schemaName = currentSchema.name;\r\n }\r\n\r\n // Create schema key with schema name\r\n const schemaKey = new SchemaKey(schemaName);\r\n // Get schema with schema key\r\n const schema = await this._context.getSchema(schemaKey);\r\n if (!schema) {\r\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find schema\", () => {\r\n return { schema: schemaName };\r\n });\r\n } else {\r\n // Set currentSchema to look up schemaItem to be whatever is prefixed in name\r\n currentSchema = schema;\r\n }\r\n // Update name to not have prefix\r\n name = schemaItemName;\r\n }\r\n\r\n // Create schema item key with name and schema\r\n const itemKey = new SchemaItemKey(name, currentSchema.schemaKey);\r\n // Get schema item with schema item key\r\n const item = await this._context.getSchemaItem(itemKey);\r\n if (!item)\r\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find schema item\", () => {\r\n return { item: name };\r\n });\r\n\r\n if (item.schemaItemType === SchemaItemType.Unit || item.schemaItemType === SchemaItemType.Constant)\r\n return item as Unit | Constant;\r\n\r\n throw new BentleyError(BentleyStatus.ERROR, \"Item is neither a unit or a constant\", () => {\r\n return { itemType: item.key.fullName };\r\n });\r\n }\r\n\r\n /**\r\n * Adds unit and corresponding children to graph as well as edges between units\r\n * @param unit Current unit to be added to graph\r\n */\r\n public async addUnit(unit: Unit | Constant): Promise<void> {\r\n if(this._unitsInProgress.has(unit.key.fullName))\r\n return this._unitsInProgress.get(unit.key.fullName);\r\n\r\n if (this._graph.hasNode(unit.key.fullName))\r\n return;\r\n\r\n this._graph.setNode(unit.key.fullName, unit);\r\n if (this.isIdentity(unit))\r\n return;\r\n\r\n const promise = this.addUnitToGraph(unit);\r\n this._unitsInProgress.set(unit.key.fullName, promise);\r\n\r\n await promise\r\n .finally(() => this._unitsInProgress.delete(unit.key.fullName));\r\n }\r\n\r\n private async addUnitToGraph(unit: Unit | Constant) {\r\n const umap = parseDefinition(unit.definition);\r\n\r\n const promiseArray: Promise<[Unit | Constant, DefinitionFragment]>[] = [];\r\n for (const [key, value] of umap) {\r\n promiseArray.push(\r\n this.resolveUnit(key, unit.schema).then((u) => [u, value]),\r\n );\r\n }\r\n const resolved = await Promise.all<[Unit | Constant, DefinitionFragment]>(\r\n promiseArray,\r\n );\r\n\r\n const children = resolved.map(async ([u, def]) => {\r\n await this.addUnit(u);\r\n this._graph.setEdge(unit.key.fullName, u.key.fullName, {\r\n exponent: def.exponent,\r\n });\r\n });\r\n\r\n await Promise.all(children);\r\n }\r\n\r\n private isIdentity(unit: Unit | Constant) {\r\n return unit.definition === unit.name;\r\n }\r\n\r\n /**\r\n * Reduce the tree to produce a single map\r\n * @param unit Unit to be processed\r\n * @param stopNodes The tree exploration should stop here\r\n */\r\n public reduce(unit: Unit | Constant, baseUnitsMap: Map<string, number>): Map<string, UnitConversion> {\r\n const unitFullName = unit.key.fullName;\r\n const innerMapStore = new Map<string, UnitConversion>();\r\n const outerMapStore = GraphUtils.dfsReduce(this._graph, unitFullName, (p, c) => this.reducingFunction(p, c), innerMapStore, baseUnitsMap, 1);\r\n return outerMapStore;\r\n }\r\n\r\n private reducingFunction(innermapStore: Map<string, UnitConversion>, unitFullName: string) {\r\n const outEdges = this._graph.outEdges(unitFullName);\r\n if (outEdges) {\r\n const cmap = outEdges.reduce<UnitConversion | undefined>((pm, e) => {\r\n const { exponent } = this._graph.edge(e.v, e.w);\r\n const stored = innermapStore.get(e.w);\r\n const map = stored ? stored : UnitConversion.identity;\r\n const emap = map.raise(exponent);\r\n return pm ? pm.multiply(emap) : emap;\r\n }, undefined);\r\n const thisMap = this._graph.node(unitFullName) ? UnitConversion.from(this._graph.node(unitFullName)) : UnitConversion.identity;\r\n const other = cmap || UnitConversion.identity;\r\n const result = other.compose(thisMap);\r\n innermapStore.set(unitFullName, result);\r\n } else {\r\n innermapStore.set(unitFullName, UnitConversion.identity);\r\n }\r\n return innermapStore;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"UnitTree.js","sourceRoot":"","sources":["../../../src/UnitConversion/UnitTree.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,sDAAkE;AAIlE,uDAAoD;AAEpD,4CAAwD;AACxD,4CAA8C;AAC9C,qDAAkD;AAClD,qCAA+D;AAC/D,mCAAgC;AAEhC,gBAAgB;AAChB,MAAa,UAAU;IACrB;;;;;;;OAOG;IACI,MAAM,CAAC,SAAS,CAAI,MAA8B,EAAE,GAAW,EAAE,EAAuC,EAAE,OAAU,EAAE,YAAiC,EAAE,mBAA2B;QACzL,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QACt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C,CAAC,EAAE,SAAS,CAAC,CAAC;YACd,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,+BAAc,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,+BAAc,CAAC,QAAQ,CAAC;YAC/H,MAAM,KAAK,GAAG,IAAI,IAAI,+BAAc,CAAC,QAAQ,CAAC;YAC9C,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACtC,aAAa,CAAC,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,aAAa,CAAC,GAAG,CAAC,YAAY,EAAE,+BAAc,CAAC,QAAQ,CAAC,CAAC;QAC3D,CAAC;QACD,OAAO,aAAa,CAAC;IACvB,CAAC;CACF;AAlJD,8BAkJC","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\nimport { BentleyError, BentleyStatus } from \"@itwin/core-bentley\";\r\nimport { SchemaContext } from \"../Context\";\r\nimport { Constant } from \"../Metadata/Constant\";\r\nimport { Schema } from \"../Metadata/Schema\";\r\nimport { SchemaItem } from \"../Metadata/SchemaItem\";\r\nimport { Unit } from \"../Metadata/Unit\";\r\nimport { SchemaItemKey, SchemaKey } from \"../SchemaKey\";\r\nimport { SchemaItemType } from \"../ECObjects\";\r\nimport { UnitConversion } from \"./UnitConversion\";\r\nimport { DefinitionFragment, parseDefinition } from \"./Parser\";\r\nimport { Graph } from \"./Graph\";\r\n\r\n/** @internal */\r\nexport class GraphUtils {\r\n /**\r\n * DFS traversal - Post order\r\n * @param _graph Graph to traverse\r\n * @param start Starting node\r\n * @param keyFrom Get key from label\r\n * @param op Reducing function\r\n * @param initial Initial label\r\n */\r\n public static dfsReduce<T>(_graph: Graph<Unit | Constant>, key: string, op: (previous: T, current: string) => T, initial: T, baseUnitsMap: Map<string, number>, accumulatedExponent: number): T {\r\n const outEdges = _graph.outEdges(key);\r\n let t = initial;\r\n if (outEdges.length > 0) {\r\n t = outEdges.reduce<T>(\r\n (p, edge) => {\r\n const { v, w } = edge;\r\n const edgeExponent = _graph.edge(v, w).exponent;\r\n return GraphUtils.dfsReduce(_graph, edge.w, op, p, baseUnitsMap, accumulatedExponent * edgeExponent);\r\n },\r\n t,\r\n );\r\n } else {\r\n if (baseUnitsMap.has(key)) {\r\n const oldExponent = baseUnitsMap.get(key) ?? 0;\r\n baseUnitsMap.set(key, oldExponent + accumulatedExponent);\r\n } else {\r\n baseUnitsMap.set(key, accumulatedExponent);\r\n }\r\n }\r\n\r\n return op(t, key);\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class UnitGraph {\r\n private _graph = new Graph<Unit | Constant>();\r\n private _unitsInProgress = new Map<string, Promise<void>>();\r\n\r\n constructor(private _context: SchemaContext) {\r\n this._graph.setGraph(\"Unit tree processor\");\r\n }\r\n\r\n /**\r\n * Tries to find the unit/constant given by name in currentSchema\r\n * @param name SchemaItem name or parsed definition to find unit of; Could be {schemaName}:{schemaItemName} or {alias}:{schemaItemName} or {schemaItemName}\r\n * @param currentSchema schema to find name in; name could also be in a referenced schema of current schema\r\n */\r\n public async resolveUnit(name: string, currentSchema: Schema): Promise<Unit | Constant> {\r\n let [schemaName] = SchemaItem.parseFullName(name);\r\n const [, schemaItemName] = SchemaItem.parseFullName(name);\r\n\r\n if (schemaName !== \"\") {\r\n // Check if schemaName is schemaName or alias\r\n const ref = currentSchema.getReferenceSync(schemaName);\r\n const refName = currentSchema.getReferenceNameByAlias(schemaName);\r\n if (ref) {\r\n // Got schema by schemaName\r\n schemaName = ref.name;\r\n } else if (refName) {\r\n // Got schema by alias\r\n schemaName = refName;\r\n } else {\r\n // Didn't match any referenced schema, check if it is current schemaName or alias\r\n if (schemaName === currentSchema.name || schemaName === currentSchema.alias)\r\n schemaName = currentSchema.name;\r\n }\r\n\r\n // Create schema key with schema name\r\n const schemaKey = new SchemaKey(schemaName);\r\n // Get schema with schema key\r\n const schema = await this._context.getSchema(schemaKey);\r\n if (!schema) {\r\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find schema\", () => {\r\n return { schema: schemaName };\r\n });\r\n } else {\r\n // Set currentSchema to look up schemaItem to be whatever is prefixed in name\r\n currentSchema = schema;\r\n }\r\n // Update name to not have prefix\r\n name = schemaItemName;\r\n }\r\n\r\n // Create schema item key with name and schema\r\n const itemKey = new SchemaItemKey(name, currentSchema.schemaKey);\r\n // Get schema item with schema item key\r\n const item = await this._context.getSchemaItem(itemKey);\r\n if (!item)\r\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find schema item\", () => {\r\n return { item: name };\r\n });\r\n\r\n if (item.schemaItemType === SchemaItemType.Unit || item.schemaItemType === SchemaItemType.Constant)\r\n return item as Unit | Constant;\r\n\r\n throw new BentleyError(BentleyStatus.ERROR, \"Item is neither a unit or a constant\", () => {\r\n return { itemType: item.key.fullName };\r\n });\r\n }\r\n\r\n /**\r\n * Adds unit and corresponding children to graph as well as edges between units\r\n * @param unit Current unit to be added to graph\r\n */\r\n public async addUnit(unit: Unit | Constant): Promise<void> {\r\n if (this._unitsInProgress.has(unit.key.fullName))\r\n return this._unitsInProgress.get(unit.key.fullName);\r\n\r\n if (this._graph.hasNode(unit.key.fullName))\r\n return;\r\n\r\n this._graph.setNode(unit.key.fullName, unit);\r\n if (this.isIdentity(unit))\r\n return;\r\n\r\n const promise = this.addUnitToGraph(unit);\r\n this._unitsInProgress.set(unit.key.fullName, promise);\r\n\r\n await promise\r\n .finally(() => this._unitsInProgress.delete(unit.key.fullName));\r\n }\r\n\r\n private async addUnitToGraph(unit: Unit | Constant) {\r\n const umap = parseDefinition(unit.definition);\r\n\r\n const promiseArray: Promise<[Unit | Constant, DefinitionFragment]>[] = [];\r\n for (const [key, value] of umap) {\r\n promiseArray.push(\r\n this.resolveUnit(key, unit.schema).then((u) => [u, value]),\r\n );\r\n }\r\n const resolved = await Promise.all<[Unit | Constant, DefinitionFragment]>(\r\n promiseArray,\r\n );\r\n\r\n const children = resolved.map(async ([u, def]) => {\r\n await this.addUnit(u);\r\n this._graph.setEdge(unit.key.fullName, u.key.fullName, {\r\n exponent: def.exponent,\r\n });\r\n });\r\n\r\n await Promise.all(children);\r\n }\r\n\r\n private isIdentity(unit: Unit | Constant) {\r\n return unit.definition === unit.name;\r\n }\r\n\r\n /**\r\n * Reduce the tree to produce a single map\r\n * @param unit Unit to be processed\r\n * @param stopNodes The tree exploration should stop here\r\n */\r\n public reduce(unit: Unit | Constant, baseUnitsMap: Map<string, number>): Map<string, UnitConversion> {\r\n const unitFullName = unit.key.fullName;\r\n const innerMapStore = new Map<string, UnitConversion>();\r\n const outerMapStore = GraphUtils.dfsReduce(this._graph, unitFullName, (p, c) => this.reducingFunction(p, c), innerMapStore, baseUnitsMap, 1);\r\n return outerMapStore;\r\n }\r\n\r\n private reducingFunction(innermapStore: Map<string, UnitConversion>, unitFullName: string) {\r\n const outEdges = this._graph.outEdges(unitFullName);\r\n if (outEdges) {\r\n const cmap = outEdges.reduce<UnitConversion | undefined>((pm, e) => {\r\n const { exponent } = this._graph.edge(e.v, e.w);\r\n const stored = innermapStore.get(e.w);\r\n const map = stored ? stored : UnitConversion.identity;\r\n const emap = map.raise(exponent);\r\n return pm ? pm.multiply(emap) : emap;\r\n }, undefined);\r\n const thisMap = this._graph.node(unitFullName) ? UnitConversion.from(this._graph.node(unitFullName)) : UnitConversion.identity;\r\n const other = cmap || UnitConversion.identity;\r\n const result = other.compose(thisMap);\r\n innermapStore.set(unitFullName, result);\r\n } else {\r\n innermapStore.set(unitFullName, UnitConversion.identity);\r\n }\r\n return innermapStore;\r\n }\r\n}\r\n"]}
@@ -10,7 +10,7 @@ import { AbstractParserConstructor, CAProviderTuple } from "./AbstractParser";
10
10
  type AnyCAContainer = Schema | ECClass | Property | RelationshipConstraint;
11
11
  /**
12
12
  * Specifies the version specification for the schema
13
- * @internal
13
+ * @beta
14
14
  */
15
15
  export interface ECSpecVersion {
16
16
  readVersion: number;
@@ -1 +1 @@
1
- {"version":3,"file":"Helper.d.ts","sourceRoot":"","sources":["../../../src/Deserialization/Helper.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG3C,OAAO,EAAY,UAAU,EAAiB,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,OAAO,EAA6B,MAAM,mBAAmB,CAAC;AAQvE,OAAO,EAAmB,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAoD,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACzH,OAAO,EAAiB,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGpD,OAAO,EAAE,kBAAkB,EAA6B,MAAM,8BAA8B,CAAC;AAE7F,OAAO,EAAkB,yBAAyB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAI9F,KAAK,cAAc,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,sBAAsB,CAAC;AAG3E;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;GAIG;AACH,qBAAa,gBAAgB,CAAC,CAAC,GAAG,OAAO;IACvC,OAAO,CAAC,QAAQ,CAAgB;IAChC,OAAO,CAAC,cAAc,CAAC,CAA4B;IACnD,OAAO,CAAC,WAAW,CAAwC;IAC3D,OAAO,CAAC,OAAO,CAA2B;IAI1C,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,WAAW,CAAC,CAAa;gBAErB,UAAU,EAAE,yBAAyB,CAAC,CAAC,CAAC,EAAE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AAO,CAAC,yBAAyB;IAWjC;;;;OAIG;YACW,0BAA0B;IAYxC;;;;OAIG;IACH,OAAO,CAAC,8BAA8B;IAatC;;;;;;OAMG;YACW,iBAAiB;IAmD/B;;;;;;OAMG;IACH,OAAO,CAAC,qBAAqB;IAkD7B;;;;;OAKG;YACW,YAAY;IAa1B;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAaxB;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;WAYlB,oBAAoB,CAAC,aAAa,CAAC,EAAE,aAAa,GAAG,OAAO;CAM3E"}
@@ -77,14 +77,17 @@ export class SchemaReadHelper {
77
77
  if (!this._schemaInfo) {
78
78
  await this.readSchemaInfo(schema, rawSchema, addSchemaToCache);
79
79
  }
80
+ const schemaInfo = this._schemaInfo;
81
+ if (!schemaInfo)
82
+ throw new ECSchemaError(ECSchemaStatus.UnableToLoadSchema, `Schema info not loaded for ${schema.schemaKey.toString()}`);
80
83
  // If not adding schema to cache (occurs in readSchemaInfo), we must load the schema here
81
84
  if (!addSchemaToCache) {
82
- const loadedSchema = await this.loadSchema(this._schemaInfo, schema);
85
+ const loadedSchema = await this.loadSchema(schemaInfo, schema);
83
86
  if (undefined === loadedSchema)
84
87
  throw new ECSchemaError(ECSchemaStatus.UnableToLoadSchema, `Could not load schema ${schema.schemaKey.toString()}`);
85
88
  return loadedSchema;
86
89
  }
87
- const cachedSchema = await this._context.getCachedSchema(this._schemaInfo.schemaKey, SchemaMatchType.Latest);
90
+ const cachedSchema = await this._context.getCachedSchema(schemaInfo.schemaKey, SchemaMatchType.Latest);
88
91
  if (undefined === cachedSchema)
89
92
  throw new ECSchemaError(ECSchemaStatus.UnableToLoadSchema, `Could not load schema ${schema.schemaKey.toString()}`);
90
93
  return cachedSchema;
@@ -116,7 +119,7 @@ export class SchemaReadHelper {
116
119
  if (this.isSchemaItemLoaded(schemaItem))
117
120
  continue;
118
121
  const loadedItem = await this.loadSchemaItem(schema, itemName, itemType, rawItem);
119
- if (this.isSchemaItemLoaded(loadedItem) && this._visitorHelper) {
122
+ if (loadedItem && this.isSchemaItemLoaded(loadedItem) && this._visitorHelper) {
120
123
  await this._visitorHelper.visitSchemaPart(loadedItem);
121
124
  }
122
125
  }
@@ -148,7 +151,7 @@ export class SchemaReadHelper {
148
151
  // Load all schema items
149
152
  for (const [itemName, itemType, rawItem] of this._parser.getItems()) {
150
153
  const loadedItem = this.loadSchemaItemSync(schema, itemName, itemType, rawItem);
151
- if (this.isSchemaItemLoaded(loadedItem) && this._visitorHelper) {
154
+ if (loadedItem && this.isSchemaItemLoaded(loadedItem) && this._visitorHelper) {
152
155
  this._visitorHelper.visitSchemaPartSync(loadedItem);
153
156
  }
154
157
  }
@@ -183,13 +186,16 @@ export class SchemaReadHelper {
183
186
  * @param ref The object to read the SchemaReference's props from.
184
187
  */
185
188
  loadSchemaReferenceSync(ref) {
189
+ const schema = this._schema;
190
+ if (!schema)
191
+ throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Schema not set when loading reference ${ref.name}`);
186
192
  const schemaKey = new SchemaKey(ref.name, ECVersion.fromString(ref.version));
187
193
  const refSchema = this._context.getSchemaSync(schemaKey, SchemaMatchType.LatestWriteCompatible);
188
194
  if (!refSchema)
189
- throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema, `Could not locate the referenced schema, ${ref.name}.${ref.version}, of ${this._schema.schemaKey.name}`);
190
- this._schema.addReferenceSync(refSchema);
191
- SchemaGraph.generateGraphSync(this._schema).throwIfCycles();
192
- const results = this.validateSchemaReferences(this._schema);
195
+ throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema, `Could not locate the referenced schema, ${ref.name}.${ref.version}, of ${schema.schemaKey.name}`);
196
+ schema.addReferenceSync(refSchema);
197
+ SchemaGraph.generateGraphSync(schema).throwIfCycles();
198
+ const results = this.validateSchemaReferences(schema);
193
199
  let errorMessage = "";
194
200
  for (const result of results) {
195
201
  errorMessage += `${result}\r\n`;
@@ -429,13 +435,16 @@ export class SchemaReadHelper {
429
435
  if (undefined === schemaName || 0 === schemaName.length)
430
436
  throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The SchemaItem ${name} is invalid without a schema name`);
431
437
  if (isInThisSchema) {
432
- schemaItem = await this._schema.getItem(itemName);
438
+ if (!this._schema)
439
+ throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Schema not set when resolving SchemaItem ${name}`);
440
+ const schema = this._schema;
441
+ schemaItem = await schema.getItem(itemName);
433
442
  if (schemaItem)
434
443
  return schemaItem;
435
444
  const foundItem = this._parser.findItem(itemName);
436
445
  if (foundItem) {
437
- schemaItem = await this.loadSchemaItem(this._schema, ...foundItem);
438
- if (!skipVisitor && this.isSchemaItemLoaded(schemaItem) && this._visitorHelper) {
446
+ schemaItem = await this.loadSchemaItem(schema, ...foundItem);
447
+ if (!skipVisitor && schemaItem && this.isSchemaItemLoaded(schemaItem) && this._visitorHelper) {
439
448
  await this._visitorHelper.visitSchemaPart(schemaItem);
440
449
  }
441
450
  if (loadCallBack && schemaItem)
@@ -464,18 +473,23 @@ export class SchemaReadHelper {
464
473
  const isInThisSchema = (this._schema && this._schema.name.toLowerCase() === schemaName.toLowerCase());
465
474
  if (undefined === schemaName || schemaName.length === 0)
466
475
  throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The SchemaItem ${name} is invalid without a schema name`);
467
- if (isInThisSchema && undefined === this._schema.getItemSync(itemName)) {
468
- const foundItem = this._parser.findItem(itemName);
469
- if (foundItem) {
470
- schemaItem = this.loadSchemaItemSync(this._schema, ...foundItem);
471
- if (!skipVisitor && this.isSchemaItemLoaded(schemaItem) && this._visitorHelper) {
472
- this._visitorHelper.visitSchemaPartSync(schemaItem);
476
+ if (isInThisSchema) {
477
+ if (!this._schema)
478
+ throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Schema not set when resolving SchemaItem ${name}`);
479
+ const schema = this._schema;
480
+ if (undefined === schema.getItemSync(itemName)) {
481
+ const foundItem = this._parser.findItem(itemName);
482
+ if (foundItem) {
483
+ schemaItem = this.loadSchemaItemSync(schema, ...foundItem);
484
+ if (!skipVisitor && schemaItem && this.isSchemaItemLoaded(schemaItem) && this._visitorHelper) {
485
+ this._visitorHelper.visitSchemaPartSync(schemaItem);
486
+ }
487
+ if (loadCallBack && schemaItem)
488
+ loadCallBack(schemaItem);
489
+ return schemaItem;
473
490
  }
474
- if (loadCallBack && schemaItem)
475
- loadCallBack(schemaItem);
476
- return schemaItem;
491
+ throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Unable to locate SchemaItem ${name}.`);
477
492
  }
478
- throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Unable to locate SchemaItem ${name}.`);
479
493
  }
480
494
  schemaItem = this._context.getSchemaItemSync(new SchemaItemKey(itemName, new SchemaKey(schemaName)));
481
495
  if (undefined === schemaItem)