@itwin/ecschema-metadata 3.1.0-dev.7 → 3.1.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 (39) hide show
  1. package/CHANGELOG.md +43 -3
  2. package/lib/cjs/Context.d.ts +5 -0
  3. package/lib/cjs/Context.d.ts.map +1 -1
  4. package/lib/cjs/Context.js +13 -0
  5. package/lib/cjs/Context.js.map +1 -1
  6. package/lib/cjs/Deserialization/Helper.js +3 -3
  7. package/lib/cjs/Deserialization/Helper.js.map +1 -1
  8. package/lib/cjs/Metadata/Format.d.ts +2 -15
  9. package/lib/cjs/Metadata/Format.d.ts.map +1 -1
  10. package/lib/cjs/Metadata/Format.js +42 -119
  11. package/lib/cjs/Metadata/Format.js.map +1 -1
  12. package/lib/cjs/Metadata/KindOfQuantity.js +2 -2
  13. package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
  14. package/lib/cjs/Metadata/OverrideFormat.d.ts +1 -1
  15. package/lib/cjs/Metadata/OverrideFormat.js.map +1 -1
  16. package/lib/cjs/Metadata/Unit.d.ts +4 -0
  17. package/lib/cjs/Metadata/Unit.d.ts.map +1 -1
  18. package/lib/cjs/Metadata/Unit.js +6 -0
  19. package/lib/cjs/Metadata/Unit.js.map +1 -1
  20. package/lib/cjs/UnitConversion/UnitConversion.d.ts +1 -2
  21. package/lib/cjs/UnitConversion/UnitConversion.d.ts.map +1 -1
  22. package/lib/cjs/UnitConversion/UnitConversion.js +1 -2
  23. package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
  24. package/lib/cjs/UnitConversion/UnitConverter.d.ts +1 -1
  25. package/lib/cjs/UnitConversion/UnitConverter.js +1 -1
  26. package/lib/cjs/UnitConversion/UnitConverter.js.map +1 -1
  27. package/lib/cjs/UnitProvider/SchemaUnitProvider.d.ts +78 -0
  28. package/lib/cjs/UnitProvider/SchemaUnitProvider.d.ts.map +1 -0
  29. package/lib/cjs/UnitProvider/SchemaUnitProvider.js +237 -0
  30. package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -0
  31. package/lib/cjs/ecschema-metadata.d.ts +3 -1
  32. package/lib/cjs/ecschema-metadata.d.ts.map +1 -1
  33. package/lib/cjs/ecschema-metadata.js +3 -1
  34. package/lib/cjs/ecschema-metadata.js.map +1 -1
  35. package/package.json +7 -5
  36. package/lib/cjs/utils/FormatEnums.d.ts +0 -106
  37. package/lib/cjs/utils/FormatEnums.d.ts.map +0 -1
  38. package/lib/cjs/utils/FormatEnums.js +0 -265
  39. package/lib/cjs/utils/FormatEnums.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaUnitProvider.js","sourceRoot":"","sources":["../../../src/UnitProvider/SchemaUnitProvider.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,sDAAkE;AAElE,wCAA2D;AAC3D,uDAAoD;AACpD,4CAAwD;AACxD,2CAAwC;AACxC,4CAA8C;AAC9C,mEAAgE;AAEhE;;;GAGG;AACH,MAAa,kBAAkB;IAI7B;;;;;;OAMG;IACH,YAAY,gBAAgC,EAAU,iBAAkC,EAAE;QAApC,mBAAc,GAAd,cAAc,CAAsB;QACxF,IAAI,gBAAgB,YAAY,uBAAa,EAAE;YAC7C,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC;SAClC;aAAM;YACL,IAAI,CAAC,QAAQ,GAAG,IAAI,uBAAa,EAAE,CAAC;YACpC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC;SAC5C;QACD,IAAI,CAAC,cAAc,GAAG,IAAI,6BAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzD,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,cAAc,CAAC,QAAgB;QAC1C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QACnD,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;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C,eAAuB,EAAE,UAAmB,EAAE,UAAmB,EAAE,UAAmB;QAC5H,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,cAAc,EAAE;YACvC,IAAI,KAAK,CAAC,gBAAgB,IAAI,KAAK,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE;gBAC/D,IAAI,KAAK,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,eAAe,CAAC,KAAK,CAAC,CAAC,EAAE;oBACnG,mDAAmD;oBACnD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;oBACrD,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC;oBAC9C,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC;oBAC9C,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,UAAU;wBAC9D,IAAI,CAAC,UAAU,IAAI,CAAC,eAAe,IAAI,eAAe,CAAC,GAAG,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;4BACrF,IAAI,CAAC,UAAU,IAAI,CAAC,eAAe,IAAI,eAAe,CAAC,GAAG,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;gCACrF,OAAO,IAAI,CAAC;iBACnB;aACF;SACF;QAED,MAAM,IAAI,2BAAY,CAAC,4BAAa,CAAC,KAAK,EAAE,+CAA+C,EAAE,GAAG,EAAE;YAChG,OAAO,EAAE,eAAe,EAAE,CAAC;QAC7B,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA5OD,gDA4OC","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 { UnitConversion, UnitExtraData, UnitProps, UnitsProvider } from \"@itwin/core-quantity\";\r\nimport { ISchemaLocater, SchemaContext } from \"../Context\";\r\nimport { SchemaItem } from \"../Metadata/SchemaItem\";\r\nimport { SchemaItemKey, SchemaKey } from \"../SchemaKey\";\r\nimport { Unit } from \"../Metadata/Unit\";\r\nimport { SchemaItemType } from \"../ECObjects\";\r\nimport { UnitConverter } from \"../UnitConversion/UnitConverter\";\r\n\r\n/**\r\n * Class used to find Units in SchemaContext by attributes such as Phenomenon and DisplayLabel.\r\n * @alpha\r\n */\r\nexport class SchemaUnitProvider implements UnitsProvider {\r\n private _unitConverter: UnitConverter;\r\n private _context: SchemaContext;\r\n\r\n /**\r\n *\r\n * @param contextOrLocater The SchemaContext or a different ISchemaLocater implementation used to retrieve the schema. The SchemaContext\r\n * class implements the ISchemaLocater interface. If the provided locater is not a SchemaContext instance a new SchemaContext will be\r\n * created and the locater will be added.\r\n * @param _unitExtraData Additional data like alternate display label not found in Units Schema to match with Units; Defaults to empty array.\r\n */\r\n constructor(contextOrLocater: ISchemaLocater, private _unitExtraData: UnitExtraData[] = []){\r\n if (contextOrLocater instanceof SchemaContext) {\r\n this._context = contextOrLocater;\r\n } else {\r\n this._context = new SchemaContext();\r\n this._context.addLocater(contextOrLocater);\r\n }\r\n this._unitConverter = new UnitConverter(this._context);\r\n }\r\n\r\n /**\r\n * Find unit in a schema that has unitName.\r\n * @param unitName Full name of unit.\r\n * @returns UnitProps interface from @itwin/core-quantity whose name matches unitName.\r\n */\r\n public async findUnitByName(unitName: string): Promise<UnitProps> {\r\n const unit = await this.findECUnitByName(unitName);\r\n return this.getUnitsProps(unit);\r\n }\r\n\r\n /**\r\n * Find all units in context that belongs to given phenomenon.\r\n * @param phenomenon Full name of phenomenon.\r\n * @returns Array of UnitProps (from @itwin/core-quantity) interface objects whose name matches phenomenon param.\r\n */\r\n public async getUnitsByFamily(phenomenon: string): Promise<Array<UnitProps>> {\r\n // Check if schema exists and phenomenon exists in schema\r\n const [schemaName, schemaItemName] = SchemaItem.parseFullName(phenomenon);\r\n const schemaKey = new SchemaKey(schemaName);\r\n const schema = await this._context.getSchema(schemaKey);\r\n\r\n if (!schema) {\r\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find schema for phenomenon\", () => {\r\n return { phenomenon, schema: schemaName };\r\n });\r\n }\r\n\r\n const itemKey = new SchemaItemKey(schemaItemName, schema.schemaKey);\r\n const phenom = await this._context.getSchemaItem(itemKey);\r\n if (!phenom)\r\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find schema item/phenomenon\", () => {\r\n return { item: schemaItemName, schema: schemaName };\r\n });\r\n\r\n if (phenom.schemaItemType !== SchemaItemType.Phenomenon)\r\n throw new BentleyError(BentleyStatus.ERROR, \"Item is not a phenomenon\", () => {\r\n return { itemType: phenom.key.fullName };\r\n });\r\n\r\n // Find units' full name that match given phenomenon param.\r\n const filteredUnits: Array<UnitProps> = [];\r\n const schemaItems = this._context.getSchemaItems();\r\n let { value, done } = schemaItems.next();\r\n while (!done) {\r\n if (Unit.isUnit(value)) {\r\n const foundPhenomenon = await value.phenomenon;\r\n if (foundPhenomenon && foundPhenomenon.key.matchesFullName(phenomenon)) {\r\n const unitProps = this.getUnitsProps(value);\r\n filteredUnits.push(unitProps);\r\n }\r\n }\r\n ({ value, done } = schemaItems.next());\r\n }\r\n\r\n return filteredUnits;\r\n }\r\n\r\n /**\r\n * Find alternate display labels associated with unitName, if any.\r\n * @param unitName Full name of Unit.\r\n */\r\n public getAlternateDisplayLabels(unitName: string): Array<string> {\r\n let alternateLabels: Array<string> = [];\r\n for (const entry of this._unitExtraData) {\r\n if (entry.name.toLowerCase() === unitName.toLowerCase()) {\r\n alternateLabels = entry.altDisplayLabels;\r\n }\r\n }\r\n\r\n return alternateLabels;\r\n }\r\n\r\n /**\r\n * Finds Unit by unitLabel, which could be a display label in the schema or alternate an display label defined in\r\n * this._unitExtraData. If there are duplicates of the same display label in the context or teh same alternate display\r\n * labels, specify schemaName, phenomenon, or unitSystem to get a specific unit.\r\n *\r\n * @param unitLabel Display label or alternate display label to query unit by.\r\n * @param schemaName Ensure Unit with unitLabel belongs to Schema with schemaName.\r\n * @param phenomenon Full name of phenomenon that Unit belongs to.\r\n * @param unitSystem Full name of unitSystem that Unit belongs to.\r\n * @returns The UnitProps interface from the @itwin/core-quantity package.\r\n */\r\n public async findUnit(unitLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps> {\r\n const findLabel = unitLabel.toLowerCase();\r\n const findSchema = schemaName ? schemaName.toLowerCase() : undefined;\r\n const findPhenomenon = phenomenon ? phenomenon.toLowerCase() : undefined;\r\n const findUnitSystem = unitSystem ? unitSystem.toLowerCase() : undefined;\r\n let foundUnit: Unit | undefined;\r\n\r\n try {\r\n try {\r\n foundUnit = await this.findUnitByDisplayLabel(findLabel, findSchema, findPhenomenon, findUnitSystem);\r\n } catch (err) {\r\n // If there is no Unit with display label that matches label, then check for alternate display labels that may match\r\n foundUnit = await this.findUnitByAltDisplayLabel(findLabel, findSchema, findPhenomenon, findUnitSystem);\r\n }\r\n } catch (err) {\r\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find unit with label\", () => {\r\n return { unitLabel };\r\n });\r\n }\r\n\r\n return this.getUnitsProps(foundUnit);\r\n }\r\n\r\n /**\r\n * Gets the @itwin/core-quantity UnitConversion for the given fromUnit and toUnit.\r\n * @param fromUnit The UnitProps of the 'from' unit.\r\n * @param toUnit The UnitProps of the 'to' unit.\r\n * @returns The UnitConversion interface from the @itwin/core-quantity package.\r\n */\r\n public async getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversion> {\r\n const conversion = await this._unitConverter.calculateConversion(fromUnit.name, toUnit.name);\r\n return {\r\n factor: conversion.factor,\r\n offset: conversion.offset,\r\n };\r\n }\r\n\r\n /**\r\n * Find unit in a schema that has unitName.\r\n * @param unitName Full name of unit.\r\n * @returns Unit whose full name matches unitName.\r\n */\r\n private async findECUnitByName(unitName: string): Promise<Unit> {\r\n // Check if schema exists and unit exists in schema\r\n const [schemaName, schemaItemName] = SchemaItem.parseFullName(unitName);\r\n const schemaKey = new SchemaKey(schemaName);\r\n const schema = await this._context.getSchema(schemaKey);\r\n\r\n if (!schema) {\r\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find schema for unit\", () => {\r\n return { schema: schemaName, unit: unitName };\r\n });\r\n }\r\n\r\n const itemKey = new SchemaItemKey(schemaItemName, schema.schemaKey);\r\n const item = await this._context.getSchemaItem<Unit>(itemKey);\r\n if (!item)\r\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find schema item/unit\", () => {\r\n return { item: schemaItemName, schema: schemaName };\r\n });\r\n\r\n if (item.schemaItemType === SchemaItemType.Unit)\r\n return item;\r\n\r\n throw new BentleyError(BentleyStatus.ERROR, \"Item is not a unit\", () => {\r\n return { itemType: item.key.fullName };\r\n });\r\n }\r\n\r\n /**\r\n * Gets the @itwin/core UnitProps for the given Unit.\r\n * @param unit The Unit to convert.\r\n * @returns UnitProps interface from @itwin/core.\r\n */\r\n private getUnitsProps(unit: Unit): UnitProps {\r\n return {\r\n name: unit.fullName,\r\n label: unit.label ?? \"\",\r\n phenomenon: unit.phenomenon ? unit.phenomenon.fullName : \"\",\r\n isValid: true,\r\n system: unit.unitSystem === undefined ? \"\" : unit.unitSystem.fullName,\r\n };\r\n }\r\n\r\n /**\r\n * Finds Unit by displayLabel and that it belongs to schemaName, phenomenon, and unitSystem if defined.\r\n * @internal\r\n */\r\n private async findUnitByDisplayLabel(displayLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<Unit> {\r\n const schemaItems = this._context.getSchemaItems();\r\n let { value, done } = schemaItems.next();\r\n while (!done) {\r\n if (Unit.isUnit(value) && value.label?.toLowerCase() === displayLabel) {\r\n const currPhenomenon = await value.phenomenon;\r\n const currUnitSystem = await value.unitSystem;\r\n if (!schemaName || value.schema.name.toLowerCase() === schemaName)\r\n if (!phenomenon || (currPhenomenon && currPhenomenon.key.matchesFullName(phenomenon)))\r\n if (!unitSystem || (currUnitSystem && currUnitSystem.key.matchesFullName(unitSystem)))\r\n return value;\r\n }\r\n ({ value, done } = schemaItems.next());\r\n }\r\n\r\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find unit with display label\", () => {\r\n return { displayLabel };\r\n });\r\n }\r\n\r\n /**\r\n * Finds Unit by altDisplayLabel and that it belongs to schemaName, phenomenon, and unitSystem if defined.\r\n * @internal\r\n */\r\n private async findUnitByAltDisplayLabel(altDisplayLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<Unit> {\r\n for (const entry of this._unitExtraData) {\r\n if (entry.altDisplayLabels && entry.altDisplayLabels.length > 0) {\r\n if (entry.altDisplayLabels.findIndex((ref: string) => ref.toLowerCase() === altDisplayLabel) !== -1) {\r\n // Found altDisplayLabel that matches label to find\r\n const unit = await this.findECUnitByName(entry.name);\r\n const foundPhenomenon = await unit.phenomenon;\r\n const foundUnitSystem = await unit.unitSystem;\r\n if (!schemaName || unit.schema.name.toLowerCase() === schemaName)\r\n if (!phenomenon || (foundPhenomenon && foundPhenomenon.key.matchesFullName(phenomenon)))\r\n if (!unitSystem || (foundUnitSystem && foundUnitSystem.key.matchesFullName(unitSystem)))\r\n return unit;\r\n }\r\n }\r\n }\r\n\r\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find unit with alternate display label\", () => {\r\n return { altDisplayLabel };\r\n });\r\n }\r\n}\r\n"]}
@@ -29,7 +29,9 @@ export { Unit } from "./Metadata/Unit";
29
29
  export { UnitSystem } from "./Metadata/UnitSystem";
30
30
  export * from "./PropertyTypes";
31
31
  export * from "./SchemaKey";
32
- export * from "./utils/FormatEnums";
32
+ export * from "./UnitConversion/UnitConversion";
33
+ export * from "./UnitConversion/UnitConverter";
34
+ export * from "./UnitProvider/SchemaUnitProvider";
33
35
  export * from "./Validation/SchemaWalker";
34
36
  export * from "./SchemaPartVisitorDelegate";
35
37
  export { CustomAttribute, CustomAttributeContainerProps } from "./Metadata/CustomAttribute";
@@ -1 +1 @@
1
- {"version":3,"file":"ecschema-metadata.d.ts","sourceRoot":"","sources":["../../src/ecschema-metadata.ts"],"names":[],"mappings":"AAKA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mCAAmC,CAAC;AAClD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EACL,QAAQ,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,cAAc,EACxF,mBAAmB,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,sBAAsB,EAC3G,oBAAoB,EAAE,WAAW,EAAE,iBAAiB,EAAE,aAAa,EAAE,2B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G;AACH;;;GAGG;AACH;;;GAGG"}
@@ -74,7 +74,9 @@ var UnitSystem_1 = require("./Metadata/UnitSystem");
74
74
  Object.defineProperty(exports, "UnitSystem", { enumerable: true, get: function () { return UnitSystem_1.UnitSystem; } });
75
75
  __exportStar(require("./PropertyTypes"), exports);
76
76
  __exportStar(require("./SchemaKey"), exports);
77
- __exportStar(require("./utils/FormatEnums"), exports);
77
+ __exportStar(require("./UnitConversion/UnitConversion"), exports);
78
+ __exportStar(require("./UnitConversion/UnitConverter"), exports);
79
+ __exportStar(require("./UnitProvider/SchemaUnitProvider"), exports);
78
80
  __exportStar(require("./Validation/SchemaWalker"), exports);
79
81
  __exportStar(require("./SchemaPartVisitorDelegate"), exports);
80
82
  var SchemaGraph_1 = require("./utils/SchemaGraph");
@@ -1 +1 @@
1
- {"version":3,"file":"ecschema-metadata.js","sourceRoot":"","sources":["../../src/ecschema-metadata.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;AAE/F,8CAA4B;AAC5B,4CAA0B;AAC1B,mDAAiC;AACjC,oEAAkD;AAClD,8DAA4C;AAC5C,2DAAyC;AACzC,8DAA4C;AAC5C,2CAAyB;AACzB,8CAA4B;AAC5B,8CAA4B;AAC5B,+CAA6B;AAC7B,0CAAwD;AAA/C,gGAAA,OAAO,OAAA;AAAE,oGAAA,WAAW,OAAA;AAC7B,gDAA+C;AAAtC,oGAAA,QAAQ,OAAA;AACjB,wEAAuE;AAA9D,4HAAA,oBAAoB,OAAA;AAC7B,sDAAqD;AAA5C,0GAAA,WAAW,OAAA;AACpB,sDAAgF;AAAxD,0GAAA,WAAW,OAAA;AACnC,4CAA2C;AAAlC,gGAAA,MAAM,OAAA;AACf,wDAAuD;AAA9C,4GAAA,YAAY,OAAA;AACrB,4DAA2D;AAAlD,gHAAA,cAAc,OAAA;AACvB,0CAAyC;AAAhC,8FAAA,KAAK,OAAA;AACd,4DAA0C;AAC1C,oDAAmD;AAA1C,wGAAA,UAAU,OAAA;AACnB,gDAI6B;AAH3B,oGAAA,QAAQ,OAAA;AAAE,6GAAA,iBAAiB,OAAA;AAAE,kHAAA,sBAAsB,OAAA;AAAE,+GAAA,mBAAmB,OAAA;AAAE,0GAAA,cAAc,OAAA;AACxF,+GAAA,mBAAmB,OAAA;AAAE,oHAAA,wBAAwB,OAAA;AAAE,8GAAA,kBAAkB,OAAA;AACX,yGAAA,aAAa,OAAA;AAAE,uHAAA,2BAA2B,OAAA;AAElG,gEAA+D;AAAtD,oHAAA,gBAAgB,OAAA;AACzB,kEAAmH;AAA1G,sHAAA,iBAAiB,OAAA;AAAE,2HAAA,sBAAsB,OAAA;AAAE,6HAAA,wBAAwB,OAAA;AAC5E,4CAA2C;AAAlC,gGAAA,MAAM,OAAA;AACf,wDAAsC;AACtC,wCAAuC;AAA9B,4FAAA,IAAI,OAAA;AACb,oDAAmD;AAA1C,wGAAA,UAAU,OAAA;AACnB,kDAAgC;AAChC,8CAA4B;AAC5B,sDAAoC;AACpC,4DAA0C;AAC1C,8DAA4C;AAE5C,mDAAkD;AAAzC,0GAAA,WAAW,OAAA;AAEpB;;GAEG;AACH;;;GAGG;AACH;;;GAGG","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\nexport * from \"./Constants\";\r\nexport * from \"./Context\";\r\nexport * from \"./DelayedPromise\";\r\nexport * from \"./Deserialization/SchemaGraphUtil\";\r\nexport * from \"./Deserialization/JsonProps\";\r\nexport * from \"./Deserialization/Helper\";\r\nexport * from \"./Deserialization/XmlParser\";\r\nexport * from \"./ECName\";\r\nexport * from \"./ECObjects\";\r\nexport * from \"./Exception\";\r\nexport * from \"./Interfaces\";\r\nexport { ECClass, StructClass } from \"./Metadata/Class\";\r\nexport { Constant } from \"./Metadata/Constant\";\r\nexport { CustomAttributeClass } from \"./Metadata/CustomAttributeClass\";\r\nexport { EntityClass } from \"./Metadata/EntityClass\";\r\nexport { AnyEnumerator, Enumeration, Enumerator } from \"./Metadata/Enumeration\";\r\nexport { Format } from \"./Metadata/Format\";\r\nexport { InvertedUnit } from \"./Metadata/InvertedUnit\";\r\nexport { KindOfQuantity } from \"./Metadata/KindOfQuantity\";\r\nexport { Mixin } from \"./Metadata/Mixin\";\r\nexport * from \"./Metadata/OverrideFormat\";\r\nexport { Phenomenon } from \"./Metadata/Phenomenon\";\r\nexport {\r\n Property, PrimitiveProperty, PrimitiveArrayProperty, EnumerationProperty, StructProperty,\r\n StructArrayProperty, EnumerationArrayProperty, NavigationProperty, AnyArrayProperty, AnyEnumerationProperty,\r\n AnyPrimitiveProperty, AnyProperty, AnyStructProperty, ArrayProperty, PrimitiveOrEnumPropertyBase,\r\n} from \"./Metadata/Property\";\r\nexport { PropertyCategory } from \"./Metadata/PropertyCategory\";\r\nexport { RelationshipClass, RelationshipConstraint, RelationshipMultiplicity } from \"./Metadata/RelationshipClass\";\r\nexport { Schema } from \"./Metadata/Schema\";\r\nexport * from \"./Metadata/SchemaItem\";\r\nexport { Unit } from \"./Metadata/Unit\";\r\nexport { UnitSystem } from \"./Metadata/UnitSystem\";\r\nexport * from \"./PropertyTypes\";\r\nexport * from \"./SchemaKey\";\r\nexport * from \"./utils/FormatEnums\";\r\nexport * from \"./Validation/SchemaWalker\";\r\nexport * from \"./SchemaPartVisitorDelegate\";\r\nexport { CustomAttribute, CustomAttributeContainerProps} from \"./Metadata/CustomAttribute\";\r\nexport { SchemaGraph } from \"./utils/SchemaGraph\";\r\n\r\n/** @docs-package-description\r\n * The ecschema-metadata package contains classes for working with ECSchemas that can be used in both [frontend]($docs/learning/frontend/index.md) and [backend]($docs/learning/backend/index.md).\r\n */\r\n/**\r\n * @docs-group-description Metadata\r\n * Definitions of classes and interfaces that represent all [EC elements]($docs/bis/ec/index.md).\r\n */\r\n/**\r\n * @docs-group-description Utils\r\n * A set of utility classes used throughout the package.\r\n */\r\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uC;AAA9B,4FAAA,IAAI,OAAA;AACb,oDAAmD;AAA1C,wGAAA,UAAU,OAAA;AACnB,kDAAgC;AAChC,8CAA4B;AAC5B,kEAAgD;AAChD,iEAA+C;AAC/C,oEAAkD;AAClD,4DAA0C;AAC1C,8DAA4C;AAE5C,mDAAkD;AAAzC,0GAAA,WAAW,OAAA;AAEpB;;GAEG;AACH;;;GAGG;AACH;;;GAGG","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\nexport * from \"./Constants\";\r\nexport * from \"./Context\";\r\nexport * from \"./DelayedPromise\";\r\nexport * from \"./Deserialization/SchemaGraphUtil\";\r\nexport * from \"./Deserialization/JsonProps\";\r\nexport * from \"./Deserialization/Helper\";\r\nexport * from \"./Deserialization/XmlParser\";\r\nexport * from \"./ECName\";\r\nexport * from \"./ECObjects\";\r\nexport * from \"./Exception\";\r\nexport * from \"./Interfaces\";\r\nexport { ECClass, StructClass } from \"./Metadata/Class\";\r\nexport { Constant } from \"./Metadata/Constant\";\r\nexport { CustomAttributeClass } from \"./Metadata/CustomAttributeClass\";\r\nexport { EntityClass } from \"./Metadata/EntityClass\";\r\nexport { AnyEnumerator, Enumeration, Enumerator } from \"./Metadata/Enumeration\";\r\nexport { Format } from \"./Metadata/Format\";\r\nexport { InvertedUnit } from \"./Metadata/InvertedUnit\";\r\nexport { KindOfQuantity } from \"./Metadata/KindOfQuantity\";\r\nexport { Mixin } from \"./Metadata/Mixin\";\r\nexport * from \"./Metadata/OverrideFormat\";\r\nexport { Phenomenon } from \"./Metadata/Phenomenon\";\r\nexport {\r\n Property, PrimitiveProperty, PrimitiveArrayProperty, EnumerationProperty, StructProperty,\r\n StructArrayProperty, EnumerationArrayProperty, NavigationProperty, AnyArrayProperty, AnyEnumerationProperty,\r\n AnyPrimitiveProperty, AnyProperty, AnyStructProperty, ArrayProperty, PrimitiveOrEnumPropertyBase,\r\n} from \"./Metadata/Property\";\r\nexport { PropertyCategory } from \"./Metadata/PropertyCategory\";\r\nexport { RelationshipClass, RelationshipConstraint, RelationshipMultiplicity } from \"./Metadata/RelationshipClass\";\r\nexport { Schema } from \"./Metadata/Schema\";\r\nexport * from \"./Metadata/SchemaItem\";\r\nexport { Unit } from \"./Metadata/Unit\";\r\nexport { UnitSystem } from \"./Metadata/UnitSystem\";\r\nexport * from \"./PropertyTypes\";\r\nexport * from \"./SchemaKey\";\r\nexport * from \"./UnitConversion/UnitConversion\";\r\nexport * from \"./UnitConversion/UnitConverter\";\r\nexport * from \"./UnitProvider/SchemaUnitProvider\";\r\nexport * from \"./Validation/SchemaWalker\";\r\nexport * from \"./SchemaPartVisitorDelegate\";\r\nexport { CustomAttribute, CustomAttributeContainerProps} from \"./Metadata/CustomAttribute\";\r\nexport { SchemaGraph } from \"./utils/SchemaGraph\";\r\n\r\n/** @docs-package-description\r\n * The ecschema-metadata package contains classes for working with ECSchemas that can be used in both [frontend]($docs/learning/frontend/index.md) and [backend]($docs/learning/backend/index.md).\r\n */\r\n/**\r\n * @docs-group-description Metadata\r\n * Definitions of classes and interfaces that represent all [EC elements]($docs/bis/ec/index.md).\r\n */\r\n/**\r\n * @docs-group-description Utils\r\n * A set of utility classes used throughout the package.\r\n */\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/ecschema-metadata",
3
- "version": "3.1.0-dev.7",
3
+ "version": "3.1.1",
4
4
  "description": "ECObjects core concepts in typescript",
5
5
  "license": "MIT",
6
6
  "main": "lib/cjs/ecschema-metadata.js",
@@ -23,9 +23,10 @@
23
23
  },
24
24
  "devDependencies": {
25
25
  "@bentley/units-schema": "^1.0.5",
26
- "@itwin/build-tools": "3.1.0-dev.7",
27
- "@itwin/core-bentley": "3.1.0-dev.7",
28
- "@itwin/eslint-plugin": "3.1.0-dev.7",
26
+ "@itwin/build-tools": "3.1.1",
27
+ "@itwin/core-bentley": "3.1.1",
28
+ "@itwin/core-quantity": "3.1.1",
29
+ "@itwin/eslint-plugin": "3.1.1",
29
30
  "@types/almost-equal": "1.1.0",
30
31
  "@types/benchmark": "^2.1.0",
31
32
  "@types/chai": "^4.1.4",
@@ -46,7 +47,8 @@
46
47
  "typescript": "~4.4.0"
47
48
  },
48
49
  "peerDependencies": {
49
- "@itwin/core-bentley": "^3.1.0-dev.7"
50
+ "@itwin/core-bentley": "^3.1.1",
51
+ "@itwin/core-quantity": "^3.1.1"
50
52
  },
51
53
  "dependencies": {
52
54
  "almost-equal": "^1.1.0"
@@ -1,106 +0,0 @@
1
- /** @packageDocumentation
2
- * @module Metadata
3
- */
4
- /** The regular expression to parse [format strings]($docs/bis/ec/kindofquantity.md#format-string)
5
- * provided in serialized formats as well as the full name of an [[OverrideFormat]].
6
- *
7
- * `formatName(precision)[unitName|unitLabel][unitName|unitLabel][unitName|unitLabel][unitName|unitLabel]`
8
- *
9
- * Explanation of the regex:
10
- * - ([\w.:]+)
11
- * - Grabs the format full name
12
- * - (\(([^\)]+)\))?
13
- * - Grabs the precision part with and without the `()`.
14
- * - The parentheses are needed to validate the entire string. (TODO: Need to check if this is true)
15
- * - (\[([^\|\]]+)([\|])?([^\]]+)?\])?
16
- * - 4 of these make up the rest of the regex, none of them are required so each end in `?`
17
- * - Grabs the unit name and label including the `[]`
18
- * - Grabs the unit name, `|` and label separately
19
- * @internal
20
- */
21
- export declare const formatStringRgx: RegExp;
22
- /** @internal Needs to be moved to quantity */
23
- export declare function getItemNamesFromFormatString(formatString: string): Iterable<string>;
24
- /** @beta Needs to be moved to quantity */
25
- export declare enum FormatTraits {
26
- TrailZeroes = 1,
27
- KeepSingleZero = 2,
28
- ZeroEmpty = 4,
29
- KeepDecimalPoint = 8,
30
- ApplyRounding = 16,
31
- FractionDash = 32,
32
- ShowUnitLabel = 64,
33
- PrependUnitLabel = 128,
34
- Use1000Separator = 256,
35
- ExponentOnlyNegative = 512
36
- }
37
- /** @beta Needs to be moved to quantity */
38
- export declare enum FractionalPrecision {
39
- One = 1,
40
- Two = 2,
41
- Four = 4,
42
- Eight = 8,
43
- Sixteen = 16,
44
- ThirtyTwo = 32,
45
- SixtyFour = 64,
46
- OneHundredTwentyEight = 128,
47
- TwoHundredFiftySix = 256
48
- }
49
- /** @beta Needs to be moved to quantity */
50
- export declare enum DecimalPrecision {
51
- Zero = 0,
52
- One = 1,
53
- Two = 2,
54
- Three = 3,
55
- Four = 4,
56
- Five = 5,
57
- Six = 6,
58
- Seven = 7,
59
- Eight = 8,
60
- Nine = 9,
61
- Ten = 10,
62
- Eleven = 11,
63
- Twelve = 12
64
- }
65
- /** @beta Needs to be moved to quantity */
66
- export declare enum FormatType {
67
- Decimal = 0,
68
- Fractional = 1,
69
- Scientific = 2,
70
- Station = 3
71
- }
72
- /** @beta Needs to be moved to quantity */
73
- export declare enum ScientificType {
74
- Normalized = 0,
75
- ZeroNormalized = 1
76
- }
77
- /** @beta Needs to be moved to quantity */
78
- export declare enum ShowSignOption {
79
- NoSign = 0,
80
- OnlyNegative = 1,
81
- SignAlways = 2,
82
- NegativeParentheses = 3
83
- }
84
- /** @internal Needs to be moved to quantity */
85
- export declare function parseScientificType(scientificType: string): ScientificType | undefined;
86
- /** @internal Needs to be moved to quantity */
87
- export declare function scientificTypeToString(scientificType: ScientificType): string;
88
- /** @internal Needs to be moved to quantity */
89
- export declare function parseShowSignOption(showSignOption: string): ShowSignOption | undefined;
90
- /** @internal Needs to be moved to quantity */
91
- export declare function showSignOptionToString(showSign: ShowSignOption): string;
92
- /** @internal Needs to be moved to quantity */
93
- export declare function parseFormatTrait(formatTraitsString: string): FormatTraits | undefined;
94
- /** @internal Needs to be moved to quantity */
95
- export declare function formatTraitsToArray(currentFormatTrait: FormatTraits): string[];
96
- /** @internal Needs to be moved to quantity */
97
- export declare function parseFormatType(jsonObjType: string): FormatType | undefined;
98
- /** @internal Needs to be moved to quantity */
99
- export declare function formatTypeToString(type: FormatType): string;
100
- /** @internal Needs to be moved to quantity */
101
- export declare function parseDecimalPrecision(jsonObjPrecision: number): DecimalPrecision | undefined;
102
- /** @internal Needs to be moved to quantity */
103
- export declare function parseFractionalPrecision(jsonObjPrecision: number): FractionalPrecision | undefined;
104
- /** @internal Needs to be moved to quantity */
105
- export declare function parsePrecision(precision: number, type: FormatType): DecimalPrecision | FractionalPrecision | undefined;
106
- //# sourceMappingURL=FormatEnums.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FormatEnums.d.ts","sourceRoot":"","sources":["../../../src/utils/FormatEnums.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,eAAe,QAAiK,CAAC;AAE9L,8CAA8C;AAC9C,wBAAiB,4BAA4B,CAAC,YAAY,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAWpF;AAED,2CAA2C;AAC3C,oBAAY,YAAY;IAEtB,WAAW,IAAO;IAClB,cAAc,IAAM;IACpB,SAAS,IAAM;IACf,gBAAgB,IAAM;IACtB,aAAa,KAAO;IACpB,YAAY,KAAO;IACnB,aAAa,KAAO;IACpB,gBAAgB,MAAO;IACvB,gBAAgB,MAAQ;IACxB,oBAAoB,MAAQ;CAC7B;AAED,2CAA2C;AAC3C,oBAAY,mBAAmB;IAC7B,GAAG,IAAI;IACP,GAAG,IAAI;IACP,IAAI,IAAI;IACR,KAAK,IAAI;IACT,OAAO,KAAK;IACZ,SAAS,KAAK;IACd,SAAS,KAAK;IACd,qBAAqB,MAAM;IAC3B,kBAAkB,MAAM;CACzB;AAED,2CAA2C;AAC3C,oBAAY,gBAAgB;IAC1B,IAAI,IAAI;IACR,GAAG,IAAI;IACP,GAAG,IAAI;IACP,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,GAAG,IAAI;IACP,KAAK,IAAI;IACT,KAAK,IAAI;IACT,IAAI,IAAI;IACR,GAAG,KAAK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AED,+CAA+C;AAC/C,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,gBAAgB,GAAG,mBAAmB,GAAG,SAAS,CAWtH"}
@@ -1,265 +0,0 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- /** @packageDocumentation
7
- * @module Metadata
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.parsePrecision = exports.parseFractionalPrecision = exports.parseDecimalPrecision = exports.formatTypeToString = exports.parseFormatType = exports.formatTraitsToArray = exports.parseFormatTrait = exports.showSignOptionToString = exports.parseShowSignOption = exports.scientificTypeToString = exports.parseScientificType = exports.ShowSignOption = exports.ScientificType = exports.FormatType = exports.DecimalPrecision = exports.FractionalPrecision = exports.FormatTraits = exports.getItemNamesFromFormatString = exports.formatStringRgx = void 0;
11
- /** The regular expression to parse [format strings]($docs/bis/ec/kindofquantity.md#format-string)
12
- * provided in serialized formats as well as the full name of an [[OverrideFormat]].
13
- *
14
- * `formatName(precision)[unitName|unitLabel][unitName|unitLabel][unitName|unitLabel][unitName|unitLabel]`
15
- *
16
- * Explanation of the regex:
17
- * - ([\w.:]+)
18
- * - Grabs the format full name
19
- * - (\(([^\)]+)\))?
20
- * - Grabs the precision part with and without the `()`.
21
- * - The parentheses are needed to validate the entire string. (TODO: Need to check if this is true)
22
- * - (\[([^\|\]]+)([\|])?([^\]]+)?\])?
23
- * - 4 of these make up the rest of the regex, none of them are required so each end in `?`
24
- * - Grabs the unit name and label including the `[]`
25
- * - Grabs the unit name, `|` and label separately
26
- * @internal
27
- */
28
- exports.formatStringRgx = /([\w.:]+)(\(([^\)]+)\))?(\[([^\|\]]+)([\|])?([^\]]+)?\])?(\[([^\|\]]+)([\|])?([^\]]+)?\])?(\[([^\|\]]+)([\|])?([^\]]+)?\])?(\[([^\|\]]+)([\|])?([^\]]+)?\])?/;
29
- /** @internal Needs to be moved to quantity */
30
- function* getItemNamesFromFormatString(formatString) {
31
- const match = formatString.split(exports.formatStringRgx);
32
- yield match[1]; // the Format Name
33
- let index = 4;
34
- while (index < match.length - 1) { // index 0 and 21 are empty strings
35
- if (match[index] !== undefined)
36
- yield match[index + 1]; // Unit Name
37
- else
38
- break;
39
- index += 4;
40
- }
41
- }
42
- exports.getItemNamesFromFormatString = getItemNamesFromFormatString;
43
- /** @beta Needs to be moved to quantity */
44
- var FormatTraits;
45
- (function (FormatTraits) {
46
- // the leading + opts TypeScript out of inferring a union enum
47
- FormatTraits[FormatTraits["TrailZeroes"] = 1] = "TrailZeroes";
48
- FormatTraits[FormatTraits["KeepSingleZero"] = 2] = "KeepSingleZero";
49
- FormatTraits[FormatTraits["ZeroEmpty"] = 4] = "ZeroEmpty";
50
- FormatTraits[FormatTraits["KeepDecimalPoint"] = 8] = "KeepDecimalPoint";
51
- FormatTraits[FormatTraits["ApplyRounding"] = 16] = "ApplyRounding";
52
- FormatTraits[FormatTraits["FractionDash"] = 32] = "FractionDash";
53
- FormatTraits[FormatTraits["ShowUnitLabel"] = 64] = "ShowUnitLabel";
54
- FormatTraits[FormatTraits["PrependUnitLabel"] = 128] = "PrependUnitLabel";
55
- FormatTraits[FormatTraits["Use1000Separator"] = 256] = "Use1000Separator";
56
- FormatTraits[FormatTraits["ExponentOnlyNegative"] = 512] = "ExponentOnlyNegative";
57
- })(FormatTraits = exports.FormatTraits || (exports.FormatTraits = {}));
58
- /** @beta Needs to be moved to quantity */
59
- var FractionalPrecision;
60
- (function (FractionalPrecision) {
61
- FractionalPrecision[FractionalPrecision["One"] = 1] = "One";
62
- FractionalPrecision[FractionalPrecision["Two"] = 2] = "Two";
63
- FractionalPrecision[FractionalPrecision["Four"] = 4] = "Four";
64
- FractionalPrecision[FractionalPrecision["Eight"] = 8] = "Eight";
65
- FractionalPrecision[FractionalPrecision["Sixteen"] = 16] = "Sixteen";
66
- FractionalPrecision[FractionalPrecision["ThirtyTwo"] = 32] = "ThirtyTwo";
67
- FractionalPrecision[FractionalPrecision["SixtyFour"] = 64] = "SixtyFour";
68
- FractionalPrecision[FractionalPrecision["OneHundredTwentyEight"] = 128] = "OneHundredTwentyEight";
69
- FractionalPrecision[FractionalPrecision["TwoHundredFiftySix"] = 256] = "TwoHundredFiftySix";
70
- })(FractionalPrecision = exports.FractionalPrecision || (exports.FractionalPrecision = {}));
71
- /** @beta Needs to be moved to quantity */
72
- var DecimalPrecision;
73
- (function (DecimalPrecision) {
74
- DecimalPrecision[DecimalPrecision["Zero"] = 0] = "Zero";
75
- DecimalPrecision[DecimalPrecision["One"] = 1] = "One";
76
- DecimalPrecision[DecimalPrecision["Two"] = 2] = "Two";
77
- DecimalPrecision[DecimalPrecision["Three"] = 3] = "Three";
78
- DecimalPrecision[DecimalPrecision["Four"] = 4] = "Four";
79
- DecimalPrecision[DecimalPrecision["Five"] = 5] = "Five";
80
- DecimalPrecision[DecimalPrecision["Six"] = 6] = "Six";
81
- DecimalPrecision[DecimalPrecision["Seven"] = 7] = "Seven";
82
- DecimalPrecision[DecimalPrecision["Eight"] = 8] = "Eight";
83
- DecimalPrecision[DecimalPrecision["Nine"] = 9] = "Nine";
84
- DecimalPrecision[DecimalPrecision["Ten"] = 10] = "Ten";
85
- DecimalPrecision[DecimalPrecision["Eleven"] = 11] = "Eleven";
86
- DecimalPrecision[DecimalPrecision["Twelve"] = 12] = "Twelve";
87
- })(DecimalPrecision = exports.DecimalPrecision || (exports.DecimalPrecision = {}));
88
- /** @beta Needs to be moved to quantity */
89
- var FormatType;
90
- (function (FormatType) {
91
- FormatType[FormatType["Decimal"] = 0] = "Decimal";
92
- FormatType[FormatType["Fractional"] = 1] = "Fractional";
93
- FormatType[FormatType["Scientific"] = 2] = "Scientific";
94
- FormatType[FormatType["Station"] = 3] = "Station";
95
- })(FormatType = exports.FormatType || (exports.FormatType = {}));
96
- /** @beta Needs to be moved to quantity */
97
- var ScientificType;
98
- (function (ScientificType) {
99
- ScientificType[ScientificType["Normalized"] = 0] = "Normalized";
100
- ScientificType[ScientificType["ZeroNormalized"] = 1] = "ZeroNormalized";
101
- })(ScientificType = exports.ScientificType || (exports.ScientificType = {}));
102
- /** @beta Needs to be moved to quantity */
103
- var ShowSignOption;
104
- (function (ShowSignOption) {
105
- ShowSignOption[ShowSignOption["NoSign"] = 0] = "NoSign";
106
- ShowSignOption[ShowSignOption["OnlyNegative"] = 1] = "OnlyNegative";
107
- ShowSignOption[ShowSignOption["SignAlways"] = 2] = "SignAlways";
108
- ShowSignOption[ShowSignOption["NegativeParentheses"] = 3] = "NegativeParentheses";
109
- })(ShowSignOption = exports.ShowSignOption || (exports.ShowSignOption = {}));
110
- // parse and toString methods
111
- /** @internal Needs to be moved to quantity */
112
- function parseScientificType(scientificType) {
113
- switch (scientificType.toLowerCase()) {
114
- case "normalized": return ScientificType.Normalized;
115
- case "zeronormalized": return ScientificType.ZeroNormalized;
116
- default:
117
- return undefined;
118
- }
119
- }
120
- exports.parseScientificType = parseScientificType;
121
- /** @internal Needs to be moved to quantity */
122
- function scientificTypeToString(scientificType) {
123
- return (scientificType === ScientificType.Normalized) ? "Normalized" : "ZeroNormalized";
124
- }
125
- exports.scientificTypeToString = scientificTypeToString;
126
- /** @internal Needs to be moved to quantity */
127
- function parseShowSignOption(showSignOption) {
128
- switch (showSignOption.toLowerCase()) {
129
- case "nosign": return ShowSignOption.NoSign;
130
- case "onlynegative": return ShowSignOption.OnlyNegative;
131
- case "signalways": return ShowSignOption.SignAlways;
132
- case "negativeparentheses": return ShowSignOption.NegativeParentheses;
133
- default:
134
- return undefined;
135
- }
136
- }
137
- exports.parseShowSignOption = parseShowSignOption;
138
- /** @internal Needs to be moved to quantity */
139
- function showSignOptionToString(showSign) {
140
- switch (showSign) {
141
- case ShowSignOption.NegativeParentheses: return "NegativeParentheses";
142
- case ShowSignOption.NoSign: return "NoSign";
143
- case ShowSignOption.OnlyNegative: return "OnlyNegative";
144
- case ShowSignOption.SignAlways: return "SignAlways";
145
- }
146
- }
147
- exports.showSignOptionToString = showSignOptionToString;
148
- /** @internal Needs to be moved to quantity */
149
- function parseFormatTrait(formatTraitsString) {
150
- switch (formatTraitsString.toLowerCase()) {
151
- case "trailzeroes": return FormatTraits.TrailZeroes;
152
- case "keepsinglezero": return FormatTraits.KeepSingleZero;
153
- case "zeroempty": return FormatTraits.ZeroEmpty;
154
- case "keepdecimalpoint": return FormatTraits.KeepDecimalPoint;
155
- case "applyrounding": return FormatTraits.ApplyRounding;
156
- case "fractiondash": return FormatTraits.FractionDash;
157
- case "showunitlabel": return FormatTraits.ShowUnitLabel;
158
- case "prependunitlabel": return FormatTraits.PrependUnitLabel;
159
- case "use1000separator": return FormatTraits.Use1000Separator;
160
- case "exponentonlynegative": return FormatTraits.ExponentOnlyNegative;
161
- default: return undefined;
162
- }
163
- }
164
- exports.parseFormatTrait = parseFormatTrait;
165
- /** @internal Needs to be moved to quantity */
166
- function formatTraitsToArray(currentFormatTrait) {
167
- const formatTraitsArr = Array();
168
- if ((currentFormatTrait & FormatTraits.TrailZeroes) === FormatTraits.TrailZeroes)
169
- formatTraitsArr.push("TrailZeroes");
170
- if ((currentFormatTrait & FormatTraits.KeepSingleZero) === FormatTraits.KeepSingleZero)
171
- formatTraitsArr.push("KeepSingleZero");
172
- if ((currentFormatTrait & FormatTraits.ZeroEmpty) === FormatTraits.ZeroEmpty)
173
- formatTraitsArr.push("ZeroEmpty");
174
- if ((currentFormatTrait & FormatTraits.KeepDecimalPoint) === FormatTraits.KeepDecimalPoint)
175
- formatTraitsArr.push("KeepDecimalPoint");
176
- if ((currentFormatTrait & FormatTraits.ApplyRounding) === FormatTraits.ApplyRounding)
177
- formatTraitsArr.push("ApplyRounding");
178
- if ((currentFormatTrait & FormatTraits.FractionDash) === FormatTraits.FractionDash)
179
- formatTraitsArr.push("FractionDash");
180
- if ((currentFormatTrait & FormatTraits.ShowUnitLabel) === FormatTraits.ShowUnitLabel)
181
- formatTraitsArr.push("ShowUnitLabel");
182
- if ((currentFormatTrait & FormatTraits.PrependUnitLabel) === FormatTraits.PrependUnitLabel)
183
- formatTraitsArr.push("PrependUnitLabel");
184
- if ((currentFormatTrait & FormatTraits.Use1000Separator) === FormatTraits.Use1000Separator)
185
- formatTraitsArr.push("Use1000Separator");
186
- if ((currentFormatTrait & FormatTraits.ExponentOnlyNegative) === FormatTraits.ExponentOnlyNegative)
187
- formatTraitsArr.push("ExponentOnlyNegative");
188
- return formatTraitsArr;
189
- }
190
- exports.formatTraitsToArray = formatTraitsToArray;
191
- /** @internal Needs to be moved to quantity */
192
- function parseFormatType(jsonObjType) {
193
- switch (jsonObjType.toLowerCase()) {
194
- case "decimal": return FormatType.Decimal;
195
- case "scientific": return FormatType.Scientific;
196
- case "station": return FormatType.Station;
197
- case "fractional": return FormatType.Fractional;
198
- default:
199
- return undefined;
200
- }
201
- }
202
- exports.parseFormatType = parseFormatType;
203
- /** @internal Needs to be moved to quantity */
204
- function formatTypeToString(type) {
205
- switch (type) {
206
- case FormatType.Decimal: return "Decimal";
207
- case FormatType.Scientific: return "Scientific";
208
- case FormatType.Station: return "Station";
209
- case FormatType.Fractional: return "Fractional";
210
- }
211
- }
212
- exports.formatTypeToString = formatTypeToString;
213
- /** @internal Needs to be moved to quantity */
214
- function parseDecimalPrecision(jsonObjPrecision) {
215
- switch (jsonObjPrecision) {
216
- case 0: return DecimalPrecision.Zero;
217
- case 1: return DecimalPrecision.One;
218
- case 2: return DecimalPrecision.Two;
219
- case 3: return DecimalPrecision.Three;
220
- case 4: return DecimalPrecision.Four;
221
- case 5: return DecimalPrecision.Five;
222
- case 6: return DecimalPrecision.Six;
223
- case 7: return DecimalPrecision.Seven;
224
- case 8: return DecimalPrecision.Eight;
225
- case 9: return DecimalPrecision.Nine;
226
- case 10: return DecimalPrecision.Ten;
227
- case 11: return DecimalPrecision.Eleven;
228
- case 12: return DecimalPrecision.Twelve;
229
- default:
230
- return undefined;
231
- }
232
- }
233
- exports.parseDecimalPrecision = parseDecimalPrecision;
234
- /** @internal Needs to be moved to quantity */
235
- function parseFractionalPrecision(jsonObjPrecision) {
236
- switch (jsonObjPrecision) {
237
- case 1: return FractionalPrecision.One;
238
- case 2: return FractionalPrecision.Two;
239
- case 4: return FractionalPrecision.Four;
240
- case 8: return FractionalPrecision.Eight;
241
- case 16: return FractionalPrecision.Sixteen;
242
- case 32: return FractionalPrecision.ThirtyTwo;
243
- case 64: return FractionalPrecision.SixtyFour;
244
- case 128: return FractionalPrecision.OneHundredTwentyEight;
245
- case 256: return FractionalPrecision.TwoHundredFiftySix;
246
- default:
247
- return undefined;
248
- }
249
- }
250
- exports.parseFractionalPrecision = parseFractionalPrecision;
251
- /** @internal Needs to be moved to quantity */
252
- function parsePrecision(precision, type) {
253
- switch (type) { // type must be decimal, fractional, scientific, or station
254
- case FormatType.Decimal:
255
- case FormatType.Scientific:
256
- case FormatType.Station:
257
- return parseDecimalPrecision(precision);
258
- case FormatType.Fractional:
259
- return parseFractionalPrecision(precision);
260
- default:
261
- return undefined;
262
- }
263
- }
264
- exports.parsePrecision = parsePrecision;
265
- //# sourceMappingURL=FormatEnums.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FormatEnums.js","sourceRoot":"","sources":["../../../src/utils/FormatEnums.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH;;;;;;;;;;;;;;;;GAgBG;AACU,QAAA,eAAe,GAAG,8JAA8J,CAAC;AAE9L,8CAA8C;AAC9C,QAAe,CAAC,CAAC,4BAA4B,CAAC,YAAoB;IAChE,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,uBAAe,CAAC,CAAC;IAClD,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,kBAAkB;IAClC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,OAAO,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,EAAE,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C;QAC9C,KAAK,GAAG,CAAC,CAAC,OAAO,mBAAmB,CAAC,qBAAqB,CAAC;QAC3D,KAAK,GAAG,CAAC,CAAC,OAAO,mBAAmB,CAAC,kBAAkB,CAAC;QACxD;YACE,OAAO,SAAS,CAAC;KACpB;AACH,CAAC;AAdD,4DAcC;AAED,+CAA+C;AAC/C,SAAgB,cAAc,CAAC,SAAiB,EAAE,IAAgB;IAChE,QAAQ,IAAI,EAAE,EAAE,2DAA2D;QACzE,KAAK,UAAU,CAAC,OAAO,CAAC;QACxB,KAAK,UAAU,CAAC,UAAU,CAAC;QAC3B,KAAK,UAAU,CAAC,OAAO;YACrB,OAAO,qBAAqB,CAAC,SAAS,CAAC,CAAC;QAC1C,KAAK,UAAU,CAAC,UAAU;YACxB,OAAO,wBAAwB,CAAC,SAAS,CAAC,CAAC;QAC7C;YACE,OAAO,SAAS,CAAC;KACpB;AACH,CAAC;AAXD,wCAWC","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\n/** The regular expression to parse [format strings]($docs/bis/ec/kindofquantity.md#format-string)\r\n * provided in serialized formats as well as the full name of an [[OverrideFormat]].\r\n *\r\n * `formatName(precision)[unitName|unitLabel][unitName|unitLabel][unitName|unitLabel][unitName|unitLabel]`\r\n *\r\n * Explanation of the regex:\r\n * - ([\\w.:]+)\r\n * - Grabs the format full name\r\n * - (\\(([^\\)]+)\\))?\r\n * - Grabs the precision part with and without the `()`.\r\n * - The parentheses are needed to validate the entire string. (TODO: Need to check if this is true)\r\n * - (\\[([^\\|\\]]+)([\\|])?([^\\]]+)?\\])?\r\n * - 4 of these make up the rest of the regex, none of them are required so each end in `?`\r\n * - Grabs the unit name and label including the `[]`\r\n * - Grabs the unit name, `|` and label separately\r\n * @internal\r\n */\r\nexport const formatStringRgx = /([\\w.:]+)(\\(([^\\)]+)\\))?(\\[([^\\|\\]]+)([\\|])?([^\\]]+)?\\])?(\\[([^\\|\\]]+)([\\|])?([^\\]]+)?\\])?(\\[([^\\|\\]]+)([\\|])?([^\\]]+)?\\])?(\\[([^\\|\\]]+)([\\|])?([^\\]]+)?\\])?/;\r\n\r\n/** @internal Needs to be moved to quantity */\r\nexport function* getItemNamesFromFormatString(formatString: string): Iterable<string> {\r\n const match = formatString.split(formatStringRgx);\r\n yield match[1]; // the Format Name\r\n let index = 4;\r\n while (index < match.length - 1) { // index 0 and 21 are empty strings\r\n if (match[index] !== undefined)\r\n yield match[index + 1]; // Unit Name\r\n else\r\n break;\r\n index += 4;\r\n }\r\n}\r\n\r\n/** @beta Needs to be moved to quantity */\r\nexport enum FormatTraits {\r\n // the leading + opts TypeScript out of inferring a union enum\r\n TrailZeroes = +0x1,\r\n KeepSingleZero = 0x2,\r\n ZeroEmpty = 0x4,\r\n KeepDecimalPoint = 0x8,\r\n ApplyRounding = 0x10,\r\n FractionDash = 0x20,\r\n ShowUnitLabel = 0x40,\r\n PrependUnitLabel = 0x80,\r\n Use1000Separator = 0x100,\r\n ExponentOnlyNegative = 0x200,\r\n}\r\n\r\n/** @beta Needs to be moved to quantity */\r\nexport enum FractionalPrecision {\r\n One = 1,\r\n Two = 2,\r\n Four = 4,\r\n Eight = 8,\r\n Sixteen = 16,\r\n ThirtyTwo = 32,\r\n SixtyFour = 64,\r\n OneHundredTwentyEight = 128,\r\n TwoHundredFiftySix = 256,\r\n}\r\n\r\n/** @beta Needs to be moved to quantity */\r\nexport enum DecimalPrecision {\r\n Zero = 0,\r\n One = 1,\r\n Two = 2,\r\n Three = 3,\r\n Four = 4,\r\n Five = 5,\r\n Six = 6,\r\n Seven = 7,\r\n Eight = 8,\r\n Nine = 9,\r\n Ten = 10,\r\n Eleven = 11,\r\n Twelve = 12,\r\n}\r\n\r\n/** @beta Needs to be moved to quantity */\r\nexport enum FormatType {\r\n Decimal,\r\n Fractional,\r\n Scientific,\r\n Station,\r\n}\r\n\r\n/** @beta Needs to be moved to quantity */\r\nexport enum ScientificType { // required if type is scientific; options: normalized, zeroNormalized\r\n Normalized,\r\n ZeroNormalized,\r\n}\r\n\r\n/** @beta Needs to be moved to quantity */\r\nexport enum ShowSignOption { // default is no sign\r\n NoSign,\r\n OnlyNegative,\r\n SignAlways,\r\n NegativeParentheses,\r\n}\r\n\r\n// parse and toString methods\r\n\r\n/** @internal Needs to be moved to quantity */\r\nexport function parseScientificType(scientificType: string): ScientificType | undefined {\r\n switch (scientificType.toLowerCase()) {\r\n case \"normalized\": return ScientificType.Normalized;\r\n case \"zeronormalized\": return ScientificType.ZeroNormalized;\r\n default:\r\n return undefined;\r\n }\r\n}\r\n\r\n/** @internal Needs to be moved to quantity */\r\nexport function scientificTypeToString(scientificType: ScientificType): string {\r\n return (scientificType === ScientificType.Normalized) ? \"Normalized\" : \"ZeroNormalized\";\r\n}\r\n\r\n/** @internal Needs to be moved to quantity */\r\nexport function parseShowSignOption(showSignOption: string): ShowSignOption | undefined {\r\n switch (showSignOption.toLowerCase()) {\r\n case \"nosign\": return ShowSignOption.NoSign;\r\n case \"onlynegative\": return ShowSignOption.OnlyNegative;\r\n case \"signalways\": return ShowSignOption.SignAlways;\r\n case \"negativeparentheses\": return ShowSignOption.NegativeParentheses;\r\n default:\r\n return undefined;\r\n }\r\n}\r\n\r\n/** @internal Needs to be moved to quantity */\r\nexport function showSignOptionToString(showSign: ShowSignOption): string {\r\n switch (showSign) {\r\n case ShowSignOption.NegativeParentheses: return \"NegativeParentheses\";\r\n case ShowSignOption.NoSign: return \"NoSign\";\r\n case ShowSignOption.OnlyNegative: return \"OnlyNegative\";\r\n case ShowSignOption.SignAlways: return \"SignAlways\";\r\n }\r\n}\r\n\r\n/** @internal Needs to be moved to quantity */\r\nexport function parseFormatTrait(formatTraitsString: string): FormatTraits | undefined {\r\n switch (formatTraitsString.toLowerCase()) {\r\n case \"trailzeroes\": return FormatTraits.TrailZeroes;\r\n case \"keepsinglezero\": return FormatTraits.KeepSingleZero;\r\n case \"zeroempty\": return FormatTraits.ZeroEmpty;\r\n case \"keepdecimalpoint\": return FormatTraits.KeepDecimalPoint;\r\n case \"applyrounding\": return FormatTraits.ApplyRounding;\r\n case \"fractiondash\": return FormatTraits.FractionDash;\r\n case \"showunitlabel\": return FormatTraits.ShowUnitLabel;\r\n case \"prependunitlabel\": return FormatTraits.PrependUnitLabel;\r\n case \"use1000separator\": return FormatTraits.Use1000Separator;\r\n case \"exponentonlynegative\": return FormatTraits.ExponentOnlyNegative;\r\n default: return undefined;\r\n }\r\n}\r\n\r\n/** @internal Needs to be moved to quantity */\r\nexport function formatTraitsToArray(currentFormatTrait: FormatTraits): string[] {\r\n const formatTraitsArr = Array<string>();\r\n if ((currentFormatTrait & FormatTraits.TrailZeroes) === FormatTraits.TrailZeroes)\r\n formatTraitsArr.push(\"TrailZeroes\");\r\n if ((currentFormatTrait & FormatTraits.KeepSingleZero) === FormatTraits.KeepSingleZero)\r\n formatTraitsArr.push(\"KeepSingleZero\");\r\n if ((currentFormatTrait & FormatTraits.ZeroEmpty) === FormatTraits.ZeroEmpty)\r\n formatTraitsArr.push(\"ZeroEmpty\");\r\n if ((currentFormatTrait & FormatTraits.KeepDecimalPoint) === FormatTraits.KeepDecimalPoint)\r\n formatTraitsArr.push(\"KeepDecimalPoint\");\r\n if ((currentFormatTrait & FormatTraits.ApplyRounding) === FormatTraits.ApplyRounding)\r\n formatTraitsArr.push(\"ApplyRounding\");\r\n if ((currentFormatTrait & FormatTraits.FractionDash) === FormatTraits.FractionDash)\r\n formatTraitsArr.push(\"FractionDash\");\r\n if ((currentFormatTrait & FormatTraits.ShowUnitLabel) === FormatTraits.ShowUnitLabel)\r\n formatTraitsArr.push(\"ShowUnitLabel\");\r\n if ((currentFormatTrait & FormatTraits.PrependUnitLabel) === FormatTraits.PrependUnitLabel)\r\n formatTraitsArr.push(\"PrependUnitLabel\");\r\n if ((currentFormatTrait & FormatTraits.Use1000Separator) === FormatTraits.Use1000Separator)\r\n formatTraitsArr.push(\"Use1000Separator\");\r\n if ((currentFormatTrait & FormatTraits.ExponentOnlyNegative) === FormatTraits.ExponentOnlyNegative)\r\n formatTraitsArr.push(\"ExponentOnlyNegative\");\r\n return formatTraitsArr;\r\n}\r\n\r\n/** @internal Needs to be moved to quantity */\r\nexport function parseFormatType(jsonObjType: string): FormatType | undefined {\r\n switch (jsonObjType.toLowerCase()) {\r\n case \"decimal\": return FormatType.Decimal;\r\n case \"scientific\": return FormatType.Scientific;\r\n case \"station\": return FormatType.Station;\r\n case \"fractional\": return FormatType.Fractional;\r\n default:\r\n return undefined;\r\n }\r\n}\r\n\r\n/** @internal Needs to be moved to quantity */\r\nexport function formatTypeToString(type: FormatType): string {\r\n switch (type) {\r\n case FormatType.Decimal: return \"Decimal\";\r\n case FormatType.Scientific: return \"Scientific\";\r\n case FormatType.Station: return \"Station\";\r\n case FormatType.Fractional: return \"Fractional\";\r\n }\r\n}\r\n\r\n/** @internal Needs to be moved to quantity */\r\nexport function parseDecimalPrecision(jsonObjPrecision: number): DecimalPrecision | undefined {\r\n switch (jsonObjPrecision) {\r\n case 0: return DecimalPrecision.Zero;\r\n case 1: return DecimalPrecision.One;\r\n case 2: return DecimalPrecision.Two;\r\n case 3: return DecimalPrecision.Three;\r\n case 4: return DecimalPrecision.Four;\r\n case 5: return DecimalPrecision.Five;\r\n case 6: return DecimalPrecision.Six;\r\n case 7: return DecimalPrecision.Seven;\r\n case 8: return DecimalPrecision.Eight;\r\n case 9: return DecimalPrecision.Nine;\r\n case 10: return DecimalPrecision.Ten;\r\n case 11: return DecimalPrecision.Eleven;\r\n case 12: return DecimalPrecision.Twelve;\r\n default:\r\n return undefined;\r\n }\r\n}\r\n\r\n/** @internal Needs to be moved to quantity */\r\nexport function parseFractionalPrecision(jsonObjPrecision: number): FractionalPrecision | undefined {\r\n switch (jsonObjPrecision) {\r\n case 1: return FractionalPrecision.One;\r\n case 2: return FractionalPrecision.Two;\r\n case 4: return FractionalPrecision.Four;\r\n case 8: return FractionalPrecision.Eight;\r\n case 16: return FractionalPrecision.Sixteen;\r\n case 32: return FractionalPrecision.ThirtyTwo;\r\n case 64: return FractionalPrecision.SixtyFour;\r\n case 128: return FractionalPrecision.OneHundredTwentyEight;\r\n case 256: return FractionalPrecision.TwoHundredFiftySix;\r\n default:\r\n return undefined;\r\n }\r\n}\r\n\r\n/** @internal Needs to be moved to quantity */\r\nexport function parsePrecision(precision: number, type: FormatType): DecimalPrecision | FractionalPrecision | undefined {\r\n switch (type) { // type must be decimal, fractional, scientific, or station\r\n case FormatType.Decimal:\r\n case FormatType.Scientific:\r\n case FormatType.Station:\r\n return parseDecimalPrecision(precision);\r\n case FormatType.Fractional:\r\n return parseFractionalPrecision(precision);\r\n default:\r\n return undefined;\r\n }\r\n}\r\n"]}