@itwin/core-quantity 5.14.0-dev.21 → 5.14.0-dev.22

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 (45) hide show
  1. package/lib/cjs/BasicUnitsProvider.d.ts +10 -7
  2. package/lib/cjs/BasicUnitsProvider.d.ts.map +1 -1
  3. package/lib/cjs/BasicUnitsProvider.js +22 -33
  4. package/lib/cjs/BasicUnitsProvider.js.map +1 -1
  5. package/lib/cjs/Formatter/Format.d.ts +3 -1
  6. package/lib/cjs/Formatter/Format.d.ts.map +1 -1
  7. package/lib/cjs/Formatter/Format.js +72 -34
  8. package/lib/cjs/Formatter/Format.js.map +1 -1
  9. package/lib/cjs/Formatter/FormatterSpec.d.ts +6 -2
  10. package/lib/cjs/Formatter/FormatterSpec.d.ts.map +1 -1
  11. package/lib/cjs/Formatter/FormatterSpec.js +42 -20
  12. package/lib/cjs/Formatter/FormatterSpec.js.map +1 -1
  13. package/lib/cjs/Formatter/Interfaces.d.ts +23 -1
  14. package/lib/cjs/Formatter/Interfaces.d.ts.map +1 -1
  15. package/lib/cjs/Formatter/Interfaces.js.map +1 -1
  16. package/lib/cjs/Interfaces.d.ts +14 -0
  17. package/lib/cjs/Interfaces.d.ts.map +1 -1
  18. package/lib/cjs/Interfaces.js.map +1 -1
  19. package/lib/cjs/internal/BasicUnitsResolvedStateCache.d.ts +4 -0
  20. package/lib/cjs/internal/BasicUnitsResolvedStateCache.d.ts.map +1 -1
  21. package/lib/cjs/internal/BasicUnitsResolvedStateCache.js +7 -0
  22. package/lib/cjs/internal/BasicUnitsResolvedStateCache.js.map +1 -1
  23. package/lib/esm/BasicUnitsProvider.d.ts +10 -7
  24. package/lib/esm/BasicUnitsProvider.d.ts.map +1 -1
  25. package/lib/esm/BasicUnitsProvider.js +21 -12
  26. package/lib/esm/BasicUnitsProvider.js.map +1 -1
  27. package/lib/esm/Formatter/Format.d.ts +3 -1
  28. package/lib/esm/Formatter/Format.d.ts.map +1 -1
  29. package/lib/esm/Formatter/Format.js +72 -34
  30. package/lib/esm/Formatter/Format.js.map +1 -1
  31. package/lib/esm/Formatter/FormatterSpec.d.ts +6 -2
  32. package/lib/esm/Formatter/FormatterSpec.d.ts.map +1 -1
  33. package/lib/esm/Formatter/FormatterSpec.js +42 -20
  34. package/lib/esm/Formatter/FormatterSpec.js.map +1 -1
  35. package/lib/esm/Formatter/Interfaces.d.ts +23 -1
  36. package/lib/esm/Formatter/Interfaces.d.ts.map +1 -1
  37. package/lib/esm/Formatter/Interfaces.js.map +1 -1
  38. package/lib/esm/Interfaces.d.ts +14 -0
  39. package/lib/esm/Interfaces.d.ts.map +1 -1
  40. package/lib/esm/Interfaces.js.map +1 -1
  41. package/lib/esm/internal/BasicUnitsResolvedStateCache.d.ts +4 -0
  42. package/lib/esm/internal/BasicUnitsResolvedStateCache.d.ts.map +1 -1
  43. package/lib/esm/internal/BasicUnitsResolvedStateCache.js +6 -0
  44. package/lib/esm/internal/BasicUnitsResolvedStateCache.js.map +1 -1
  45. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAgIH;;GAEG;AACI,MAAM,mBAAmB,GAAG,CAAC,IAAiB,EAA6B,EAAE;IAClF,OAAQ,IAA0B,CAAC,MAAM,KAAK,SAAS,CAAC;AAC1D,CAAC,CAAC;AAFW,QAAA,mBAAmB,uBAE9B","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 Quantity\r\n */\r\n\r\nimport { BeEvent, BeUnorderedUiEvent } from \"@itwin/core-bentley\";\r\nimport { UnitProps, UnitSystemKey } from \"../Interfaces\";\r\nimport { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision } from \"./FormatEnums\";\r\nimport type { FormatterSpec } from \"./FormatterSpec\";\r\nimport type { ParserSpec } from \"../ParserSpec\";\r\n\r\n/** Defines a unit specification with a name and optional label override.\r\n * Used in composite formats and ratio unit specifications.\r\n * @beta\r\n */\r\nexport interface FormatUnitSpec {\r\n /** The name of the unit (e.g., \"Units.FT\", \"Units.IN\") */\r\n readonly name: string;\r\n /** Optional custom label that overrides the unit's default label (e.g., '\"' for inches, \"'\" for feet) */\r\n readonly label?: string;\r\n}\r\n\r\n/** A resolved [[FormatUnitSpec]] with the unit name replaced with the resolved UnitProps.\r\n * @beta\r\n */\r\nexport interface ResolvedFormatUnitSpec {\r\n /** The resolved unit */\r\n readonly unit: UnitProps;\r\n /** Optional custom label that overrides the unit's default label */\r\n readonly label?: string;\r\n}\r\n\r\n/** Defines the units that make up a composite format and their display properties.\r\n * A composite format allows displaying a single quantity value across multiple units,\r\n * such as displaying length as \"5 feet 6 inches\" or angle as \"45° 30' 15\"\".\r\n * @beta\r\n */\r\nexport interface FormatCompositeProps {\r\n /** Separator character between unit values when formatting composite strings. Must be empty or a single character. */\r\n readonly spacer?: string;\r\n /** Whether to include unit segments with zero magnitude in the formatted output. */\r\n readonly includeZero?: boolean;\r\n /** Array of units this format is comprised of. Each unit specifies the unit name and\r\n * an optional custom label that will override the unit's default label when displaying values. */\r\n readonly units: FormatUnitSpec[];\r\n}\r\n\r\n/** This interface defines the persistence format for describing the formatting of quantity values.\r\n * @beta\r\n */\r\nexport interface FormatProps {\r\n /** The format type. See [[FormatType]] */\r\n readonly type: string;\r\n\r\n /** The precision for the format. Must be an integer. See [[DecimalPrecision]] and [[FractionalPrecision]] */\r\n readonly precision?: number;\r\n\r\n /** Value is rounded to a multiple of this factor if nonzero and the `applyRounding` trait is set, defaults to 0 */\r\n readonly roundFactor?: number;\r\n\r\n /** Minimum width of the formatted output including digits and separators. Must be a positive integer (≥ 0). */\r\n readonly minWidth?: number;\r\n\r\n /** How and when positive and negative signs are displayed. See [[ShowSignOption]] */\r\n readonly showSignOption?: string;\r\n\r\n /** Array of format traits controlling display behavior. See [[FormatTraits]] */\r\n readonly formatTraits?: string | string[];\r\n\r\n /** Character separating integer from fractional part. Must be empty or a single character. */\r\n readonly decimalSeparator?: string;\r\n\r\n /** Character separating thousands in the integer part. Must be empty or a single character. */\r\n readonly thousandSeparator?: string;\r\n\r\n /** Character separating the magnitude from the unit label. Must be empty or a single character. */\r\n readonly uomSeparator?: string;\r\n\r\n /** Required when type is Scientific. See [[ScientificType]] */\r\n readonly scientificType?: string;\r\n\r\n /** Required when type is Ratio. See [[RatioType]]*/\r\n readonly ratioType?: string;\r\n /** The separator character for ratio formatting. Defaults to ':' if not specified. */\r\n readonly ratioSeparator?: string;\r\n /** The format type for the numbers within a ratio. Defaults to \"Decimal\". */\r\n readonly ratioFormatType?: string;\r\n\r\n /** Required when type is Station. Number of decimal places for calculating station offset magnitude. Must be a positive integer > 0. */\r\n readonly stationOffsetSize?: number;\r\n\r\n /** Character separating station and offset portions of a Station formatted value. Must be empty or a single character. */\r\n readonly stationSeparator?: string;\r\n\r\n /** Optional base factor for station formatting. A positive integer, defaults to 1. */\r\n readonly stationBaseFactor?: number;\r\n\r\n /** The base value for azimuth, specified from east counter-clockwise. */\r\n readonly azimuthBase?: number;\r\n\r\n /** The name of the unit for the azimuth base value. Required if azimuthBase is set.\r\n * @note Must share the same phenomenon as the persistence unit the Format/FormatterSpec/ParserSpec is used with (e.g. a `Units.HORIZONTAL_DIRECTION`\r\n * unit for a `Units.HORIZONTAL_DIRECTION` persistence unit, or a `Units.ANGLE` unit for a `Units.ANGLE` persistence unit) - the units provider\r\n * cannot convert between different phenomena, so a mismatch will fail to resolve.\r\n */\r\n readonly azimuthBaseUnit?: string;\r\n\r\n /** If set to true, azimuth values are returned counter-clockwise from the base. */\r\n readonly azimuthCounterClockwise?: boolean;\r\n\r\n /** The name of the unit that represents a revolution/perigon. Required for bearing or azimuth types.\r\n * @note Must share the same phenomenon as the persistence unit the Format/FormatterSpec/ParserSpec is used with (e.g. `Units.HORIZONTAL_DIR_REVOLUTION`\r\n * for a `Units.HORIZONTAL_DIRECTION` persistence unit, or `Units.REVOLUTION` for a `Units.ANGLE` persistence unit) - the units provider cannot\r\n * convert between different phenomena, so a mismatch will fail to resolve.\r\n */\r\n readonly revolutionUnit?: string;\r\n\r\n /** Enables calculating mathematic operations during parsing; only addition and subtraction are supported. */\r\n readonly allowMathematicOperations?: boolean;\r\n\r\n /** Composite format specification for multi-unit display. */\r\n readonly composite?: FormatCompositeProps;\r\n}\r\n\r\n/** This interface is used when supporting Custom Formatters that need more than the standard set of properties.\r\n * @beta\r\n */\r\nexport interface CustomFormatProps extends FormatProps {\r\n readonly custom: any;\r\n}\r\n\r\n/** CustomFormatProps type guard.\r\n * @beta\r\n */\r\nexport const isCustomFormatProps = (item: FormatProps): item is CustomFormatProps => {\r\n return (item as CustomFormatProps).custom !== undefined;\r\n};\r\n\r\n/** A [[FormatCompositeProps]] with unit names replaced with JSON representations of those units.\r\n * @beta\r\n */\r\nexport type ResolvedFormatCompositeProps = Omit<FormatCompositeProps, \"units\"> & {\r\n readonly units: ResolvedFormatUnitSpec[];\r\n};\r\n\r\n/** A [[FormatProps]] with all the references to units replaced with JSON representations of those units.\r\n * @beta\r\n */\r\nexport type ResolvedFormatProps = Omit<FormatDefinition, \"azimuthBaseUnit\" | \"revolutionUnit\" | \"composite\"> & {\r\n readonly azimuthBaseUnit?: UnitProps;\r\n readonly revolutionUnit?: UnitProps;\r\n readonly composite?: ResolvedFormatCompositeProps;\r\n readonly custom?: any;\r\n};\r\n\r\n/** CloneFormat defines unit and label specification if primary unit is to be set during clone.\r\n * @beta\r\n */\r\nexport interface CloneUnit {\r\n unit?: UnitProps;\r\n label?: string;\r\n}\r\n\r\n/** CloneOptions that define modifications that can be made during the cloning of a Format.\r\n * @beta\r\n */\r\nexport interface CloneOptions {\r\n /** allows composite formats to be converted to only show primary unit */\r\n showOnlyPrimaryUnit?: boolean;\r\n /** allow format traits to be set */\r\n traits?: FormatTraits;\r\n /** allows new FormatType to be specified */\r\n type?: FormatType;\r\n /** allows precision to be set, this will throw if value is not valid for FormatType */\r\n precision?: DecimalPrecision | FractionalPrecision;\r\n /** allows primary unit and label to be specified */\r\n primaryUnit?: CloneUnit;\r\n}\r\n\r\n/** An extension of FormatProps to help identify formats.\r\n * @beta\r\n */\r\nexport interface FormatDefinition extends FormatProps {\r\n readonly name?: string;\r\n readonly label?: string;\r\n readonly description?: string;\r\n}\r\n\r\n/** Argument for [[FormatsProvider.onFormatsChanged]]\r\n * @beta\r\n */\r\nexport interface FormatsChangedArgs {\r\n /**\r\n * If `all` - all formats within the `FormatsProvider` have changed.\r\n * If array, the array items list the names of formats that were changed or removed.\r\n */\r\n formatsChanged: \"all\" | string[];\r\n /** If set, indicates that the format set implies a particular unit system. The consumer\r\n * (e.g., QuantityFormatter) will synchronize the active unit system to match.\r\n * If `undefined`, the format change does not imply a unit system switch — the active\r\n * unit system remains unchanged.\r\n * @beta\r\n */\r\n impliedUnitSystem?: UnitSystemKey;\r\n}\r\n\r\n/** This interface is implemented by a class that would provide formats for use in formatting quantities.\r\n * @beta\r\n */\r\nexport interface FormatsProvider {\r\n /**\r\n * @param name The full name of the Format or KindOfQuantity.\r\n */\r\n getFormat(name: string, system?: UnitSystemKey): Promise<FormatDefinition | undefined>;\r\n\r\n /**\r\n * Fired when formats are added, removed, or changed.\r\n * If all formats are changed, a single string \"all\" is emitted. Else, an array of changed format names is emitted.\r\n */\r\n onFormatsChanged: BeEvent<(args: FormatsChangedArgs) => void>;\r\n}\r\n\r\n/** This interface is implemented by a class that would provide and allow creating formats for use in formatting quantities.\r\n * @beta\r\n */\r\nexport interface MutableFormatsProvider extends FormatsProvider {\r\n /**\r\n * Adds a new format or updates an existing format associated with the specified name.\r\n */\r\n addFormat(name: string, format: FormatDefinition): Promise<void>;\r\n /**\r\n * Removes the format associated with the specified name.\r\n * @param name The name of the format to remove.\r\n */\r\n removeFormat(name: string): Promise<void>;\r\n}\r\n\r\n/** Entries returned when looking up specs from the format registry.\r\n * @beta\r\n */\r\nexport interface FormattingSpecEntry {\r\n formatterSpec: FormatterSpec;\r\n parserSpec: ParserSpec;\r\n}\r\n\r\n/** Arguments for looking up a formatting spec entry.\r\n * @beta\r\n */\r\nexport interface FormattingSpecArgs {\r\n /** The KoQ name to look up. */\r\n name: string;\r\n /** The persistence unit name (e.g., `\"Units.M\"`). */\r\n persistenceUnitName: string;\r\n /** Optional unit system override. When omitted, the active system is used. */\r\n system?: UnitSystemKey;\r\n}\r\n\r\n/** Arguments for registering a formatting spec entry.\r\n * @beta\r\n */\r\nexport interface AddFormattingSpecArgs extends FormattingSpecArgs {\r\n /** Format properties to use. When omitted, the provider resolves them from the KoQ schema. */\r\n formatProps?: FormatProps;\r\n}\r\n\r\n/** Minimal contract required by [[FormatSpecHandle]] to look up current specs and expose formatting readiness.\r\n * Implemented by [[QuantityFormatter]] in `@itwin/core-frontend`.\r\n * @beta\r\n */\r\nexport interface FormattingSpecProvider {\r\n /** Look up a formatting spec entry by KoQ name and persistence unit. */\r\n getSpecsByNameAndUnit(args: FormattingSpecArgs): FormattingSpecEntry | undefined;\r\n /** Format a numeric value using the given formatter spec. */\r\n formatQuantity(magnitude: number, formatSpec: FormatterSpec): string;\r\n /** Event raised after the provider has finished reloading its caches.\r\n * Uses Set-backed event for safe concurrent add/remove during emit.\r\n */\r\n readonly onFormattingReady: BeUnorderedUiEvent<void>;\r\n}\r\n\r\n"]}
1
+ {"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAgIH;;GAEG;AACI,MAAM,mBAAmB,GAAG,CAAC,IAAiB,EAA6B,EAAE;IAClF,OAAQ,IAA0B,CAAC,MAAM,KAAK,SAAS,CAAC;AAC1D,CAAC,CAAC;AAFW,QAAA,mBAAmB,uBAE9B","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 Quantity\r\n */\r\n\r\nimport { BeEvent, BeUnorderedUiEvent } from \"@itwin/core-bentley\";\r\nimport { UnitProps, UnitSystemKey } from \"../Interfaces\";\r\nimport { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision } from \"./FormatEnums\";\r\nimport type { FormatterSpec } from \"./FormatterSpec\";\r\nimport type { ParserSpec } from \"../ParserSpec\";\r\n\r\n/** Defines a unit specification with a name and optional label override.\r\n * Used in composite formats and ratio unit specifications.\r\n * @beta\r\n */\r\nexport interface FormatUnitSpec {\r\n /** The name of the unit (e.g., \"Units.FT\", \"Units.IN\") */\r\n readonly name: string;\r\n /** Optional custom label that overrides the unit's default label (e.g., '\"' for inches, \"'\" for feet) */\r\n readonly label?: string;\r\n}\r\n\r\n/** A resolved [[FormatUnitSpec]] with the unit name replaced with the resolved UnitProps.\r\n * @beta\r\n */\r\nexport interface ResolvedFormatUnitSpec {\r\n /** The resolved unit */\r\n readonly unit: UnitProps;\r\n /** Optional custom label that overrides the unit's default label */\r\n readonly label?: string;\r\n}\r\n\r\n/** Defines the units that make up a composite format and their display properties.\r\n * A composite format allows displaying a single quantity value across multiple units,\r\n * such as displaying length as \"5 feet 6 inches\" or angle as \"45° 30' 15\"\".\r\n * @beta\r\n */\r\nexport interface FormatCompositeProps {\r\n /** Separator character between unit values when formatting composite strings. Must be empty or a single character. */\r\n readonly spacer?: string;\r\n /** Whether to include unit segments with zero magnitude in the formatted output. */\r\n readonly includeZero?: boolean;\r\n /** Array of units this format is comprised of. Each unit specifies the unit name and\r\n * an optional custom label that will override the unit's default label when displaying values. */\r\n readonly units: FormatUnitSpec[];\r\n}\r\n\r\n/** This interface defines the persistence format for describing the formatting of quantity values.\r\n * @beta\r\n */\r\nexport interface FormatProps {\r\n /** The format type. See [[FormatType]] */\r\n readonly type: string;\r\n\r\n /** The precision for the format. Must be an integer. See [[DecimalPrecision]] and [[FractionalPrecision]] */\r\n readonly precision?: number;\r\n\r\n /** Value is rounded to a multiple of this factor if nonzero and the `applyRounding` trait is set, defaults to 0 */\r\n readonly roundFactor?: number;\r\n\r\n /** Minimum width of the formatted output including digits and separators. Must be a positive integer (≥ 0). */\r\n readonly minWidth?: number;\r\n\r\n /** How and when positive and negative signs are displayed. See [[ShowSignOption]] */\r\n readonly showSignOption?: string;\r\n\r\n /** Array of format traits controlling display behavior. See [[FormatTraits]] */\r\n readonly formatTraits?: string | string[];\r\n\r\n /** Character separating integer from fractional part. Must be empty or a single character. */\r\n readonly decimalSeparator?: string;\r\n\r\n /** Character separating thousands in the integer part. Must be empty or a single character. */\r\n readonly thousandSeparator?: string;\r\n\r\n /** Character separating the magnitude from the unit label. Must be empty or a single character. */\r\n readonly uomSeparator?: string;\r\n\r\n /** Required when type is Scientific. See [[ScientificType]] */\r\n readonly scientificType?: string;\r\n\r\n /** Required when type is Ratio. See [[RatioType]]*/\r\n readonly ratioType?: string;\r\n /** The separator character for ratio formatting. Defaults to ':' if not specified. */\r\n readonly ratioSeparator?: string;\r\n /** The format type for the numbers within a ratio. Defaults to \"Decimal\". */\r\n readonly ratioFormatType?: string;\r\n\r\n /** Required when type is Station. Number of decimal places for calculating station offset magnitude. Must be a positive integer > 0. */\r\n readonly stationOffsetSize?: number;\r\n\r\n /** Character separating station and offset portions of a Station formatted value. Must be empty or a single character. */\r\n readonly stationSeparator?: string;\r\n\r\n /** Optional base factor for station formatting. A positive integer, defaults to 1. */\r\n readonly stationBaseFactor?: number;\r\n\r\n /** The base value for azimuth, specified from east counter-clockwise. */\r\n readonly azimuthBase?: number;\r\n\r\n /** The name of the unit for the azimuth base value. Required if azimuthBase is set.\r\n * @note Must share the same phenomenon as the persistence unit the Format/FormatterSpec/ParserSpec is used with (e.g. a `Units.HORIZONTAL_DIRECTION`\r\n * unit for a `Units.HORIZONTAL_DIRECTION` persistence unit, or a `Units.ANGLE` unit for a `Units.ANGLE` persistence unit) - the units provider\r\n * cannot convert between different phenomena, so a mismatch will fail to resolve.\r\n */\r\n readonly azimuthBaseUnit?: string;\r\n\r\n /** If set to true, azimuth values are returned counter-clockwise from the base. */\r\n readonly azimuthCounterClockwise?: boolean;\r\n\r\n /** The name of the unit that represents a revolution/perigon. Required for bearing or azimuth types.\r\n * @note Must share the same phenomenon as the persistence unit the Format/FormatterSpec/ParserSpec is used with (e.g. `Units.HORIZONTAL_DIR_REVOLUTION`\r\n * for a `Units.HORIZONTAL_DIRECTION` persistence unit, or `Units.REVOLUTION` for a `Units.ANGLE` persistence unit) - the units provider cannot\r\n * convert between different phenomena, so a mismatch will fail to resolve.\r\n */\r\n readonly revolutionUnit?: string;\r\n\r\n /** Enables calculating mathematic operations during parsing; only addition and subtraction are supported. */\r\n readonly allowMathematicOperations?: boolean;\r\n\r\n /** Composite format specification for multi-unit display. */\r\n readonly composite?: FormatCompositeProps;\r\n}\r\n\r\n/** This interface is used when supporting Custom Formatters that need more than the standard set of properties.\r\n * @beta\r\n */\r\nexport interface CustomFormatProps extends FormatProps {\r\n readonly custom: any;\r\n}\r\n\r\n/** CustomFormatProps type guard.\r\n * @beta\r\n */\r\nexport const isCustomFormatProps = (item: FormatProps): item is CustomFormatProps => {\r\n return (item as CustomFormatProps).custom !== undefined;\r\n};\r\n\r\n/** A [[FormatCompositeProps]] with unit names replaced with JSON representations of those units.\r\n * @beta\r\n */\r\nexport type ResolvedFormatCompositeProps = Omit<FormatCompositeProps, \"units\"> & {\r\n readonly units: ResolvedFormatUnitSpec[];\r\n};\r\n\r\n/** A [[FormatProps]] with all the references to units replaced with JSON representations of those units.\r\n * @beta\r\n */\r\nexport type ResolvedFormatProps = Omit<FormatDefinition, \"azimuthBaseUnit\" | \"revolutionUnit\" | \"composite\"> & {\r\n readonly azimuthBaseUnit?: UnitProps;\r\n readonly revolutionUnit?: UnitProps;\r\n readonly composite?: ResolvedFormatCompositeProps;\r\n readonly custom?: any;\r\n};\r\n\r\n/** CloneFormat defines unit and label specification if primary unit is to be set during clone.\r\n * @beta\r\n */\r\nexport interface CloneUnit {\r\n unit?: UnitProps;\r\n label?: string;\r\n}\r\n\r\n/** CloneOptions that define modifications that can be made during the cloning of a Format.\r\n * @beta\r\n */\r\nexport interface CloneOptions {\r\n /** allows composite formats to be converted to only show primary unit */\r\n showOnlyPrimaryUnit?: boolean;\r\n /** allow format traits to be set */\r\n traits?: FormatTraits;\r\n /** allows new FormatType to be specified */\r\n type?: FormatType;\r\n /** allows precision to be set, this will throw if value is not valid for FormatType */\r\n precision?: DecimalPrecision | FractionalPrecision;\r\n /** allows primary unit and label to be specified */\r\n primaryUnit?: CloneUnit;\r\n}\r\n\r\n/** An extension of FormatProps to help identify formats.\r\n * @beta\r\n */\r\nexport interface FormatDefinition extends FormatProps {\r\n readonly name?: string;\r\n readonly label?: string;\r\n readonly description?: string;\r\n}\r\n\r\n/** Argument for [[FormatsProvider.onFormatsChanged]]\r\n * @beta\r\n */\r\nexport interface FormatsChangedArgs {\r\n /**\r\n * If `all` - all formats within the `FormatsProvider` have changed.\r\n * If array, the array items list the names of formats that were changed or removed.\r\n */\r\n formatsChanged: \"all\" | string[];\r\n /** If set, indicates that the format set implies a particular unit system. The consumer\r\n * (e.g., QuantityFormatter) will synchronize the active unit system to match.\r\n * If `undefined`, the format change does not imply a unit system switch — the active\r\n * unit system remains unchanged.\r\n * @beta\r\n */\r\n impliedUnitSystem?: UnitSystemKey;\r\n}\r\n\r\n/**\r\n * Context passed through a chain of providers while resolving one format request.\r\n * A provider that delegates the current request must forward this context unchanged; omit it only when starting an independent request.\r\n * @beta\r\n */\r\nexport interface FormatsProviderContext {\r\n /** Providers already visited while resolving the current format request. */\r\n readonly providerChain: ReadonlySet<FormatsProvider>;\r\n}\r\n\r\n/** This interface is implemented by a class that would provide formats for use in formatting quantities.\r\n * @beta\r\n */\r\nexport interface FormatsProvider {\r\n /**\r\n * @param name The full name of the Format or KindOfQuantity.\r\n * @param context Optional context to forward when delegating the current lookup through another provider.\r\n */\r\n getFormat(name: string, system?: UnitSystemKey, context?: FormatsProviderContext): Promise<FormatDefinition | undefined>;\r\n\r\n /**\r\n * Fired when formats are added, removed, or changed.\r\n * If all formats are changed, a single string \"all\" is emitted. Else, an array of changed format names is emitted.\r\n */\r\n onFormatsChanged: BeEvent<(args: FormatsChangedArgs) => void>;\r\n}\r\n\r\n/**\r\n * Optional capability for providers that can resolve format definitions from local data without awaiting.\r\n * @note Implementations should use already-loaded local data and avoid schema loading or asynchronous I/O from this method.\r\n * @beta\r\n */\r\nexport interface SyncFormatsProvider {\r\n /**\r\n * Return a locally available format definition, or `undefined` when unavailable.\r\n * @param context Optional context to forward when delegating the current lookup through another provider.\r\n */\r\n getFormatSync(name: string, system?: UnitSystemKey, context?: FormatsProviderContext): FormatDefinition | undefined;\r\n}\r\n\r\n/** This interface is implemented by a class that would provide and allow creating formats for use in formatting quantities.\r\n * @beta\r\n */\r\nexport interface MutableFormatsProvider extends FormatsProvider {\r\n /**\r\n * Adds a new format or updates an existing format associated with the specified name.\r\n */\r\n addFormat(name: string, format: FormatDefinition): Promise<void>;\r\n /**\r\n * Removes the format associated with the specified name.\r\n * @param name The name of the format to remove.\r\n */\r\n removeFormat(name: string): Promise<void>;\r\n}\r\n\r\n/** Entries returned when looking up specs from the format registry.\r\n * @beta\r\n */\r\nexport interface FormattingSpecEntry {\r\n formatterSpec: FormatterSpec;\r\n parserSpec: ParserSpec;\r\n}\r\n\r\n/** Arguments for looking up a formatting spec entry.\r\n * @beta\r\n */\r\nexport interface FormattingSpecArgs {\r\n /** The KoQ name to look up. */\r\n name: string;\r\n /** The persistence unit name (e.g., `\"Units.M\"`). */\r\n persistenceUnitName: string;\r\n /** Optional unit system override. When omitted, the active system is used. */\r\n system?: UnitSystemKey;\r\n}\r\n\r\n/** Arguments for registering a formatting spec entry.\r\n * @beta\r\n */\r\nexport interface AddFormattingSpecArgs extends FormattingSpecArgs {\r\n /** Format properties to use. When omitted, the provider resolves them from the KoQ schema. */\r\n formatProps?: FormatProps;\r\n}\r\n\r\n/** Minimal contract required by [[FormatSpecHandle]] to look up current specs and expose formatting readiness.\r\n * Implemented by [[QuantityFormatter]] in `@itwin/core-frontend`.\r\n * @beta\r\n */\r\nexport interface FormattingSpecProvider {\r\n /** Look up a formatting spec entry by KoQ name and persistence unit. */\r\n getSpecsByNameAndUnit(args: FormattingSpecArgs): FormattingSpecEntry | undefined;\r\n /** Format a numeric value using the given formatter spec. */\r\n formatQuantity(magnitude: number, formatSpec: FormatterSpec): string;\r\n /** Event raised after the provider has finished reloading its caches.\r\n * Uses Set-backed event for safe concurrent add/remove during emit.\r\n */\r\n readonly onFormattingReady: BeUnorderedUiEvent<void>;\r\n}\r\n\r\n"]}
@@ -106,6 +106,20 @@ export interface UnitsProvider {
106
106
  */
107
107
  getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversionProps>;
108
108
  }
109
+ /**
110
+ * Optional capability for providers that can resolve units and conversions from local data without awaiting.
111
+ * @note Implementations should use already-loaded local data and avoid schema loading or asynchronous I/O from these methods.
112
+ * @beta
113
+ */
114
+ export interface SyncUnitsProvider {
115
+ /** Find a unit by fully qualified name using local data. */
116
+ findUnitByNameSync(unitName: string): UnitProps;
117
+ /**
118
+ * Compute conversion factors using local data.
119
+ * @note On failure, implementations should return `{ factor: 1.0, offset: 0.0, error: true }`.
120
+ */
121
+ getConversionSync(fromUnit: UnitProps, toUnit: UnitProps): UnitConversionProps;
122
+ }
109
123
  /**
110
124
  * Identifies a user-facing unit system preference group.
111
125
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Interfaces.d.ts","sourceRoot":"","sources":["../../src/Interfaces.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,sBAAsB,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,MAAM,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EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAC/G,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;IAC3D,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACrD;;;;;;OAMG;IACH,aAAa,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACrF;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,4DAA4D;IAC5D,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAChD;;;OAGG;IACH,iBAAiB,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,GAAG,mBAAmB,CAAC;CAChF;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,UAAU,GAAG,aAAa,GAAG,UAAU,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../src/Interfaces.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAmDH;;GAEG;AACH,IAAY,oBAKX;AALD,WAAY,oBAAoB;IAC9B,mGAAmG;IACnG,mEAA2C,CAAA;IAC3C,gGAAgG;IAChG,qEAA6C,CAAA;AAC/C,CAAC,EALW,oBAAoB,oCAApB,oBAAoB,QAK/B","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 Quantity\r\n */\r\n\r\n/** This interface allows a provider to be specified that will define an array of alternate labels for a specific unit.\r\n * @beta\r\n */\r\nexport interface AlternateUnitLabelsProvider {\r\n getAlternateUnitLabels: (unit: UnitProps) => string[] | undefined;\r\n}\r\n\r\n/** This interface provides basic information about a Unit that is return from a UnitProvider. This info\r\n * uniquely identifies a unit by its name.\r\n * @beta\r\n */\r\nexport interface UnitProps {\r\n /** Unique name for unit. */\r\n readonly name: string;\r\n /** Default label for unit. */\r\n readonly label: string;\r\n /** Unique name of unit phenomenon. Example phenomenon names include 'Units.LENGTH', 'Units.AREA', and 'Units.VOLUME' */\r\n readonly phenomenon: string;\r\n /** This is set to true if the Unit is known by the UnitsProvider. */\r\n readonly isValid: boolean;\r\n /** Unique system name. Example \"Units.USCUSTOM\",\" Units.METRIC\", \"Units.USSURVEY\", \"Units.IMPERIAL\" */\r\n readonly system: string;\r\n}\r\n\r\n/** This interface defines the required properties of a Quantity.\r\n * @beta\r\n */\r\nexport interface QuantityProps {\r\n readonly magnitude: number;\r\n readonly unit: UnitProps;\r\n readonly isValid: boolean;\r\n}\r\n\r\n/** Interface that defines how to convert between a specific unit an another in synchronous formatting or parsing processing.\r\n * @beta\r\n */\r\nexport interface UnitConversionSpec {\r\n /** Unit name that was used to locate the unit by the Unit Provider */\r\n name: string;\r\n /** The default label that is used to display unit */\r\n label: string;\r\n /** Unit system name, used to when finding preferred parse unit */\r\n system: string;\r\n /** the information necessary to convert the unit to a specific display unit */\r\n conversion: UnitConversionProps;\r\n /** Labels that may be used to represent the unit in a string that is to be parsed. */\r\n parseLabels?: string[];\r\n}\r\n\r\n/** Indicates the way in which unit values are inverted during conversion\r\n * @beta\r\n */\r\nexport enum UnitConversionInvert {\r\n /** Invert value before applying the other conversion steps (the from-unit is the inverted unit) */\r\n InvertPreConversion = \"InvertPreConversion\",\r\n /** Invert value after applying the other conversion steps (the to-unit is the inverted unit) */\r\n InvertPostConversion = \"InvertPostConversion\"\r\n}\r\n\r\n/** This interface defines the properties required to convert a quantity value from one unit to another such as from meters to feet\r\n * or from Celsius to Fahrenheit.\r\n * @beta\r\n */\r\nexport interface UnitConversionProps {\r\n /** The factor to multiply the input value by to convert to the output value. */\r\n factor: number;\r\n /** The offset to add to the input value to convert to the output value. */\r\n offset: number;\r\n /** If set, inverts the unit value (1/x) before or after conversion. */\r\n inversion?: UnitConversionInvert;\r\n /**\r\n * If `true`, the conversion could not be resolved (e.g. unknown unit, incompatible phenomena).\r\n * When `error` is `true`, `factor` MUST be `1.0` and `offset` MUST be `0.0` (identity).\r\n * Callers must check this flag before applying the conversion — applying an identity conversion\r\n * silently produces wrong output.\r\n */\r\n error?: boolean;\r\n}\r\n\r\n/** Interface that defines potential parse units that may be found in user's string input of a quantity value.\r\n * @beta\r\n */\r\nexport interface PotentialParseUnit {\r\n unitName: string;\r\n altLabels?: string[];\r\n}\r\n\r\n/**\r\n * This interface defines extra properties to be associated with Units from Units Schema by name\r\n * @alpha\r\n */\r\nexport interface UnitExtraData {\r\n readonly name: string;\r\n readonly altDisplayLabels: string[];\r\n}\r\n\r\n/** This interface is implemented by the class that is responsible for locating units by name or label and providing conversion values between units.\r\n * The methods to be implemented are async allowing the UnitsProvider to query the backend when necessary to look up unit definition and conversion rules.\r\n * @beta\r\n */\r\nexport interface UnitsProvider {\r\n findUnit(unitLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps>;\r\n getUnitsByFamily(phenomenon: string): Promise<UnitProps[]>;\r\n findUnitByName(unitName: string): Promise<UnitProps>;\r\n /**\r\n * Compute the conversion factors from `fromUnit` to `toUnit`.\r\n * On failure (unknown unit, incompatible phenomena), implementations MUST return\r\n * `{ factor: 1.0, offset: 0.0, error: true }`. Throwing is also permitted;\r\n * composite providers treat a throw as equivalent to `error: true`.\r\n * Callers MUST check `result.error` before applying the conversion.\r\n */\r\n getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversionProps>;\r\n}\r\n\r\n/**\r\n * Identifies a user-facing unit system preference group.\r\n *\r\n * A `UnitSystemKey` does **not** map one-to-one to an EC `UnitSystem` element. Instead, each key\r\n * represents a *preference group* that matches against one or more EC `UnitSystem` names in\r\n * priority order when resolving formats from a `KindOfQuantity`:\r\n *\r\n * | Key | EC UnitSystems matched (highest priority first) |\r\n * | -------------- | ------------------------------------------------------- |\r\n * | `\"metric\"` | SI / METRIC, INTERNATIONAL, FINANCE |\r\n * | `\"imperial\"` | IMPERIAL, USCUSTOM, INTERNATIONAL, FINANCE |\r\n * | `\"usCustomary\"`| USCUSTOM, INTERNATIONAL, FINANCE |\r\n * | `\"usSurvey\"` | USSURVEY, USCUSTOM, INTERNATIONAL, FINANCE |\r\n *\r\n * EC `UnitSystem` elements not listed above (e.g. CGS, MARITIME, INDUSTRIAL) are not covered by\r\n * any preference group and will only appear if a `KindOfQuantity` explicitly references them.\r\n *\r\n * @see [SchemaFormatsProvider]($ecschema-metadata) for how preference groups resolve formats.\r\n * @beta\r\n */\r\nexport type UnitSystemKey = \"metric\" | \"imperial\" | \"usCustomary\" | \"usSurvey\";\r\n"]}
1
+ {"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../src/Interfaces.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAmDH;;GAEG;AACH,IAAY,oBAKX;AALD,WAAY,oBAAoB;IAC9B,mGAAmG;IACnG,mEAA2C,CAAA;IAC3C,gGAAgG;IAChG,qEAA6C,CAAA;AAC/C,CAAC,EALW,oBAAoB,oCAApB,oBAAoB,QAK/B","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 Quantity\r\n */\r\n\r\n/** This interface allows a provider to be specified that will define an array of alternate labels for a specific unit.\r\n * @beta\r\n */\r\nexport interface AlternateUnitLabelsProvider {\r\n getAlternateUnitLabels: (unit: UnitProps) => string[] | undefined;\r\n}\r\n\r\n/** This interface provides basic information about a Unit that is return from a UnitProvider. This info\r\n * uniquely identifies a unit by its name.\r\n * @beta\r\n */\r\nexport interface UnitProps {\r\n /** Unique name for unit. */\r\n readonly name: string;\r\n /** Default label for unit. */\r\n readonly label: string;\r\n /** Unique name of unit phenomenon. Example phenomenon names include 'Units.LENGTH', 'Units.AREA', and 'Units.VOLUME' */\r\n readonly phenomenon: string;\r\n /** This is set to true if the Unit is known by the UnitsProvider. */\r\n readonly isValid: boolean;\r\n /** Unique system name. Example \"Units.USCUSTOM\",\" Units.METRIC\", \"Units.USSURVEY\", \"Units.IMPERIAL\" */\r\n readonly system: string;\r\n}\r\n\r\n/** This interface defines the required properties of a Quantity.\r\n * @beta\r\n */\r\nexport interface QuantityProps {\r\n readonly magnitude: number;\r\n readonly unit: UnitProps;\r\n readonly isValid: boolean;\r\n}\r\n\r\n/** Interface that defines how to convert between a specific unit an another in synchronous formatting or parsing processing.\r\n * @beta\r\n */\r\nexport interface UnitConversionSpec {\r\n /** Unit name that was used to locate the unit by the Unit Provider */\r\n name: string;\r\n /** The default label that is used to display unit */\r\n label: string;\r\n /** Unit system name, used to when finding preferred parse unit */\r\n system: string;\r\n /** the information necessary to convert the unit to a specific display unit */\r\n conversion: UnitConversionProps;\r\n /** Labels that may be used to represent the unit in a string that is to be parsed. */\r\n parseLabels?: string[];\r\n}\r\n\r\n/** Indicates the way in which unit values are inverted during conversion\r\n * @beta\r\n */\r\nexport enum UnitConversionInvert {\r\n /** Invert value before applying the other conversion steps (the from-unit is the inverted unit) */\r\n InvertPreConversion = \"InvertPreConversion\",\r\n /** Invert value after applying the other conversion steps (the to-unit is the inverted unit) */\r\n InvertPostConversion = \"InvertPostConversion\"\r\n}\r\n\r\n/** This interface defines the properties required to convert a quantity value from one unit to another such as from meters to feet\r\n * or from Celsius to Fahrenheit.\r\n * @beta\r\n */\r\nexport interface UnitConversionProps {\r\n /** The factor to multiply the input value by to convert to the output value. */\r\n factor: number;\r\n /** The offset to add to the input value to convert to the output value. */\r\n offset: number;\r\n /** If set, inverts the unit value (1/x) before or after conversion. */\r\n inversion?: UnitConversionInvert;\r\n /**\r\n * If `true`, the conversion could not be resolved (e.g. unknown unit, incompatible phenomena).\r\n * When `error` is `true`, `factor` MUST be `1.0` and `offset` MUST be `0.0` (identity).\r\n * Callers must check this flag before applying the conversion — applying an identity conversion\r\n * silently produces wrong output.\r\n */\r\n error?: boolean;\r\n}\r\n\r\n/** Interface that defines potential parse units that may be found in user's string input of a quantity value.\r\n * @beta\r\n */\r\nexport interface PotentialParseUnit {\r\n unitName: string;\r\n altLabels?: string[];\r\n}\r\n\r\n/**\r\n * This interface defines extra properties to be associated with Units from Units Schema by name\r\n * @alpha\r\n */\r\nexport interface UnitExtraData {\r\n readonly name: string;\r\n readonly altDisplayLabels: string[];\r\n}\r\n\r\n/** This interface is implemented by the class that is responsible for locating units by name or label and providing conversion values between units.\r\n * The methods to be implemented are async allowing the UnitsProvider to query the backend when necessary to look up unit definition and conversion rules.\r\n * @beta\r\n */\r\nexport interface UnitsProvider {\r\n findUnit(unitLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps>;\r\n getUnitsByFamily(phenomenon: string): Promise<UnitProps[]>;\r\n findUnitByName(unitName: string): Promise<UnitProps>;\r\n /**\r\n * Compute the conversion factors from `fromUnit` to `toUnit`.\r\n * On failure (unknown unit, incompatible phenomena), implementations MUST return\r\n * `{ factor: 1.0, offset: 0.0, error: true }`. Throwing is also permitted;\r\n * composite providers treat a throw as equivalent to `error: true`.\r\n * Callers MUST check `result.error` before applying the conversion.\r\n */\r\n getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversionProps>;\r\n}\r\n\r\n/**\r\n * Optional capability for providers that can resolve units and conversions from local data without awaiting.\r\n * @note Implementations should use already-loaded local data and avoid schema loading or asynchronous I/O from these methods.\r\n * @beta\r\n */\r\nexport interface SyncUnitsProvider {\r\n /** Find a unit by fully qualified name using local data. */\r\n findUnitByNameSync(unitName: string): UnitProps;\r\n /**\r\n * Compute conversion factors using local data.\r\n * @note On failure, implementations should return `{ factor: 1.0, offset: 0.0, error: true }`.\r\n */\r\n getConversionSync(fromUnit: UnitProps, toUnit: UnitProps): UnitConversionProps;\r\n}\r\n\r\n/**\r\n * Identifies a user-facing unit system preference group.\r\n *\r\n * A `UnitSystemKey` does **not** map one-to-one to an EC `UnitSystem` element. Instead, each key\r\n * represents a *preference group* that matches against one or more EC `UnitSystem` names in\r\n * priority order when resolving formats from a `KindOfQuantity`:\r\n *\r\n * | Key | EC UnitSystems matched (highest priority first) |\r\n * | -------------- | ------------------------------------------------------- |\r\n * | `\"metric\"` | SI / METRIC, INTERNATIONAL, FINANCE |\r\n * | `\"imperial\"` | IMPERIAL, USCUSTOM, INTERNATIONAL, FINANCE |\r\n * | `\"usCustomary\"`| USCUSTOM, INTERNATIONAL, FINANCE |\r\n * | `\"usSurvey\"` | USSURVEY, USCUSTOM, INTERNATIONAL, FINANCE |\r\n *\r\n * EC `UnitSystem` elements not listed above (e.g. CGS, MARITIME, INDUSTRIAL) are not covered by\r\n * any preference group and will only appear if a `KindOfQuantity` explicitly references them.\r\n *\r\n * @see [SchemaFormatsProvider]($ecschema-metadata) for how preference groups resolve formats.\r\n * @beta\r\n */\r\nexport type UnitSystemKey = \"metric\" | \"imperial\" | \"usCustomary\" | \"usSurvey\";\r\n"]}
@@ -4,6 +4,10 @@ import { type ResolvedBasicUnitsData } from "./BasicUnitConversionData";
4
4
  * @internal
5
5
  */
6
6
  export declare function resolveBasicUnitsData(loadSchema: () => Promise<SerializedUnitSchema>): Promise<ResolvedBasicUnitsData>;
7
+ /** Return shared resolved data for built-in units, building it synchronously on first use.
8
+ * @internal
9
+ */
10
+ export declare function resolveBasicUnitsDataSync(schema: SerializedUnitSchema): ResolvedBasicUnitsData;
7
11
  /** @internal — test use only. Resets the shared module-level lazy cache.
8
12
  * This stays in source rather than under a test folder because the public test seam
9
13
  * `BasicUnitsProvider._testResetUnitsCache()` lives in source and delegates here.
@@ -1 +1 @@
1
- {"version":3,"file":"BasicUnitsResolvedStateCache.d.ts","sourceRoot":"","sources":["../../../src/internal/BasicUnitsResolvedStateCache.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAA+B,KAAK,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAWrG;;GAEG;AACH,wBAAsB,qBAAqB,CAAC,UAAU,EAAE,MAAM,OAAO,CAAC,oBAAoB,CAAC,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAc5H;AAED;;;GAGG;AACH,wBAAgB,qCAAqC,IAAI,IAAI,CAG5D"}
1
+ {"version":3,"file":"BasicUnitsResolvedStateCache.d.ts","sourceRoot":"","sources":["../../../src/internal/BasicUnitsResolvedStateCache.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAA+B,KAAK,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAWrG;;GAEG;AACH,wBAAsB,qBAAqB,CAAC,UAAU,EAAE,MAAM,OAAO,CAAC,oBAAoB,CAAC,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAc5H;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,oBAAoB,GAAG,sBAAsB,CAE9F;AAED;;;GAGG;AACH,wBAAgB,qCAAqC,IAAI,IAAI,CAG5D"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveBasicUnitsData = resolveBasicUnitsData;
4
+ exports.resolveBasicUnitsDataSync = resolveBasicUnitsDataSync;
4
5
  exports._testResetResolvedBasicUnitsDataCache = _testResetResolvedBasicUnitsDataCache;
5
6
  const BasicUnitConversionData_1 = require("./BasicUnitConversionData");
6
7
  // Shared module-level cache for the built-in basic-units indexes used by BasicUnitsProvider.
@@ -26,6 +27,12 @@ async function resolveBasicUnitsData(loadSchema) {
26
27
  }
27
28
  return _resolvePromise;
28
29
  }
30
+ /** Return shared resolved data for built-in units, building it synchronously on first use.
31
+ * @internal
32
+ */
33
+ function resolveBasicUnitsDataSync(schema) {
34
+ return _resolvedData ??= (0, BasicUnitConversionData_1.buildResolvedBasicUnitsData)(schema);
35
+ }
29
36
  /** @internal — test use only. Resets the shared module-level lazy cache.
30
37
  * This stays in source rather than under a test folder because the public test seam
31
38
  * `BasicUnitsProvider._testResetUnitsCache()` lives in source and delegates here.
@@ -1 +1 @@
1
- {"version":3,"file":"BasicUnitsResolvedStateCache.js","sourceRoot":"","sources":["../../../src/internal/BasicUnitsResolvedStateCache.ts"],"names":[],"mappings":";;AAmBA,sDAcC;AAMD,sFAGC;AArCD,uEAAqG;AAErG,6FAA6F;AAC7F,IAAI,aAAiD,CAAC;AACtD,IAAI,eAA4D,CAAC;AAEjE,SAAS,kBAAkB,CAAC,GAAY;IACtC,eAAe,GAAG,SAAS,CAAC;IAC5B,MAAM,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,qBAAqB,CAAC,UAA+C;IACzF,IAAI,aAAa,KAAK,SAAS;QAC7B,OAAO,aAAa,CAAC;IAEvB,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;QAClC,eAAe,GAAG,UAAU,EAAE;aAC3B,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YACf,aAAa,KAAK,IAAA,qDAA2B,EAAC,MAAM,CAAC,CAAC;YACtD,OAAO,aAAa,CAAC;QACvB,CAAC,CAAC;aACD,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC;AAED;;;GAGG;AACH,SAAgB,qCAAqC;IACnD,aAAa,GAAG,SAAS,CAAC;IAC1B,eAAe,GAAG,SAAS,CAAC;AAC9B,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\nimport type { SerializedUnitSchema } from \"../SerializedUnitSchema\";\r\nimport { buildResolvedBasicUnitsData, type ResolvedBasicUnitsData } from \"./BasicUnitConversionData\";\r\n\r\n// Shared module-level cache for the built-in basic-units indexes used by BasicUnitsProvider.\r\nlet _resolvedData: ResolvedBasicUnitsData | undefined;\r\nlet _resolvePromise: Promise<ResolvedBasicUnitsData> | undefined;\r\n\r\nfunction clearFailedAttempt(err: unknown): never {\r\n _resolvePromise = undefined;\r\n throw err instanceof Error ? err : new Error(String(err));\r\n}\r\n\r\n/** Returns the shared resolved data for the built-in basic units, loading/building it asynchronously if needed.\r\n * @internal\r\n */\r\nexport async function resolveBasicUnitsData(loadSchema: () => Promise<SerializedUnitSchema>): Promise<ResolvedBasicUnitsData> {\r\n if (_resolvedData !== undefined)\r\n return _resolvedData;\r\n\r\n if (_resolvePromise === undefined) {\r\n _resolvePromise = loadSchema()\r\n .then((schema) => {\r\n _resolvedData ??= buildResolvedBasicUnitsData(schema);\r\n return _resolvedData;\r\n })\r\n .catch(clearFailedAttempt);\r\n }\r\n\r\n return _resolvePromise;\r\n}\r\n\r\n/** @internal — test use only. Resets the shared module-level lazy cache.\r\n * This stays in source rather than under a test folder because the public test seam\r\n * `BasicUnitsProvider._testResetUnitsCache()` lives in source and delegates here.\r\n */\r\nexport function _testResetResolvedBasicUnitsDataCache(): void {\r\n _resolvedData = undefined;\r\n _resolvePromise = undefined;\r\n}\r\n"]}
1
+ {"version":3,"file":"BasicUnitsResolvedStateCache.js","sourceRoot":"","sources":["../../../src/internal/BasicUnitsResolvedStateCache.ts"],"names":[],"mappings":";;AAmBA,sDAcC;AAKD,8DAEC;AAMD,sFAGC;AA5CD,uEAAqG;AAErG,6FAA6F;AAC7F,IAAI,aAAiD,CAAC;AACtD,IAAI,eAA4D,CAAC;AAEjE,SAAS,kBAAkB,CAAC,GAAY;IACtC,eAAe,GAAG,SAAS,CAAC;IAC5B,MAAM,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,qBAAqB,CAAC,UAA+C;IACzF,IAAI,aAAa,KAAK,SAAS;QAC7B,OAAO,aAAa,CAAC;IAEvB,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;QAClC,eAAe,GAAG,UAAU,EAAE;aAC3B,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YACf,aAAa,KAAK,IAAA,qDAA2B,EAAC,MAAM,CAAC,CAAC;YACtD,OAAO,aAAa,CAAC;QACvB,CAAC,CAAC;aACD,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC;AAED;;GAEG;AACH,SAAgB,yBAAyB,CAAC,MAA4B;IACpE,OAAO,aAAa,KAAK,IAAA,qDAA2B,EAAC,MAAM,CAAC,CAAC;AAC/D,CAAC;AAED;;;GAGG;AACH,SAAgB,qCAAqC;IACnD,aAAa,GAAG,SAAS,CAAC;IAC1B,eAAe,GAAG,SAAS,CAAC;AAC9B,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\nimport type { SerializedUnitSchema } from \"../SerializedUnitSchema\";\r\nimport { buildResolvedBasicUnitsData, type ResolvedBasicUnitsData } from \"./BasicUnitConversionData\";\r\n\r\n// Shared module-level cache for the built-in basic-units indexes used by BasicUnitsProvider.\r\nlet _resolvedData: ResolvedBasicUnitsData | undefined;\r\nlet _resolvePromise: Promise<ResolvedBasicUnitsData> | undefined;\r\n\r\nfunction clearFailedAttempt(err: unknown): never {\r\n _resolvePromise = undefined;\r\n throw err instanceof Error ? err : new Error(String(err));\r\n}\r\n\r\n/** Returns the shared resolved data for the built-in basic units, loading/building it asynchronously if needed.\r\n * @internal\r\n */\r\nexport async function resolveBasicUnitsData(loadSchema: () => Promise<SerializedUnitSchema>): Promise<ResolvedBasicUnitsData> {\r\n if (_resolvedData !== undefined)\r\n return _resolvedData;\r\n\r\n if (_resolvePromise === undefined) {\r\n _resolvePromise = loadSchema()\r\n .then((schema) => {\r\n _resolvedData ??= buildResolvedBasicUnitsData(schema);\r\n return _resolvedData;\r\n })\r\n .catch(clearFailedAttempt);\r\n }\r\n\r\n return _resolvePromise;\r\n}\r\n\r\n/** Return shared resolved data for built-in units, building it synchronously on first use.\r\n * @internal\r\n */\r\nexport function resolveBasicUnitsDataSync(schema: SerializedUnitSchema): ResolvedBasicUnitsData {\r\n return _resolvedData ??= buildResolvedBasicUnitsData(schema);\r\n}\r\n\r\n/** @internal — test use only. Resets the shared module-level lazy cache.\r\n * This stays in source rather than under a test folder because the public test seam\r\n * `BasicUnitsProvider._testResetUnitsCache()` lives in source and delegates here.\r\n */\r\nexport function _testResetResolvedBasicUnitsDataCache(): void {\r\n _resolvedData = undefined;\r\n _resolvePromise = undefined;\r\n}\r\n"]}
@@ -1,15 +1,14 @@
1
- import type { UnitProps, UnitsProvider } from "./Interfaces";
1
+ import type { SyncUnitsProvider, UnitProps, UnitsProvider } from "./Interfaces";
2
2
  /** @internal — test use only. Resets the shared module-level lazy cache. */
3
3
  export declare function _testResetUnitsCache(): void;
4
4
  /**
5
5
  * A `UnitsProvider` backed by the full BIS `Units.ecschema.json` bundled as a JSON asset.
6
6
  *
7
- * The bundled JSON is loaded lazily via dynamic `import()` on the first provider call and cached
8
- * at module scope — construction is essentially free, and multiple instances
9
- * share the same immutable lookup indexes.
7
+ * The bundled data is available locally. The provider builds its immutable lookup indexes on the
8
+ * first call and caches them at module scope, so multiple instances share the same indexes.
10
9
  *
11
- * If an initial schema load fails, later provider calls will retry the load instead of pinning the
12
- * provider into a permanently failed module-level state.
10
+ * If resolving the bundled data fails, the next provider call retries instead of retaining a failed
11
+ * module-level state.
13
12
  *
14
13
  * This is the zero-dependency default for backends, tools, and any frontend that doesn't need
15
14
  * iModel overrides. Equivalent to calling `createUnitsProvider()` with no arguments.
@@ -17,7 +16,11 @@ export declare function _testResetUnitsCache(): void;
17
16
  * @see createUnitsProvider for layering schema-defined units on top of basic BIS units.
18
17
  * @beta
19
18
  */
20
- export declare class BasicUnitsProvider implements UnitsProvider {
19
+ export declare class BasicUnitsProvider implements UnitsProvider, SyncUnitsProvider {
20
+ /** Find a built-in unit by fully qualified name using local data. */
21
+ findUnitByNameSync(unitName: string): UnitProps;
22
+ /** Compute a conversion between built-in units using the same bundled data as [[getConversion]]. */
23
+ getConversionSync(fromUnit: UnitProps, toUnit: UnitProps): import("./Interfaces").UnitConversionProps;
21
24
  /** Find a unit by its display label, optionally filtering by schema name, phenomenon, and unit system.
22
25
  * @param unitLabel - The display label to search for (case-insensitive).
23
26
  * @param schemaName - Optional schema name filter. Returns `BadUnit` if provided and not `"Units"`.
@@ -1 +1 @@
1
- {"version":3,"file":"BasicUnitsProvider.d.ts","sourceRoot":"","sources":["../../src/BasicUnitsProvider.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAe7D,4EAA4E;AAC5E,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,kBAAmB,YAAW,aAAa;IAItD;;;;;;OAMG;IACU,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAuB3H;;;OAGG;IACU,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAMvE;;;OAGG;IACU,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAMjE;;;;;OAKG;IACU,aAAa,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS;CAIlE"}
1
+ {"version":3,"file":"BasicUnitsProvider.d.ts","sourceRoot":"","sources":["../../src/BasicUnitsProvider.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAiBhF,4EAA4E;AAC5E,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,kBAAmB,YAAW,aAAa,EAAE,iBAAiB;IAEzE,qEAAqE;IAC9D,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS;IAMtD,oGAAoG;IAC7F,iBAAiB,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS;IAM/D;;;;;;OAMG;IACU,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAuB3H;;;OAGG;IACU,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAMvE;;;OAGG;IACU,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAMjE;;;;;OAKG;IACU,aAAa,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS;CAIlE"}
@@ -1,13 +1,13 @@
1
1
  import { BadUnit } from "./Unit";
2
2
  import { getBasicUnitConversion } from "./internal/BasicUnitConversionData";
3
- import { _testResetResolvedBasicUnitsDataCache, resolveBasicUnitsData } from "./internal/BasicUnitsResolvedStateCache";
3
+ import { _testResetResolvedBasicUnitsDataCache, resolveBasicUnitsData, resolveBasicUnitsDataSync } from "./internal/BasicUnitsResolvedStateCache";
4
+ import bundledUnitsSchema from "./assets/Units.json";
5
+ const bundledSchema = bundledUnitsSchema;
4
6
  async function resolveState() {
5
- return resolveBasicUnitsData(async () => {
6
- // First caller pays the dynamic-import + schema-index build cost.
7
- // Concurrent callers await the same promise, and later callers reuse the resolved state.
8
- const { default: schema } = await import("./assets/Units.json");
9
- return schema;
10
- });
7
+ return resolveBasicUnitsData(async () => bundledSchema);
8
+ }
9
+ function resolveStateSync() {
10
+ return resolveBasicUnitsDataSync(bundledSchema);
11
11
  }
12
12
  /** @internal — test use only. Resets the shared module-level lazy cache. */
13
13
  export function _testResetUnitsCache() {
@@ -16,12 +16,11 @@ export function _testResetUnitsCache() {
16
16
  /**
17
17
  * A `UnitsProvider` backed by the full BIS `Units.ecschema.json` bundled as a JSON asset.
18
18
  *
19
- * The bundled JSON is loaded lazily via dynamic `import()` on the first provider call and cached
20
- * at module scope — construction is essentially free, and multiple instances
21
- * share the same immutable lookup indexes.
19
+ * The bundled data is available locally. The provider builds its immutable lookup indexes on the
20
+ * first call and caches them at module scope, so multiple instances share the same indexes.
22
21
  *
23
- * If an initial schema load fails, later provider calls will retry the load instead of pinning the
24
- * provider into a permanently failed module-level state.
22
+ * If resolving the bundled data fails, the next provider call retries instead of retaining a failed
23
+ * module-level state.
25
24
  *
26
25
  * This is the zero-dependency default for backends, tools, and any frontend that doesn't need
27
26
  * iModel overrides. Equivalent to calling `createUnitsProvider()` with no arguments.
@@ -30,6 +29,16 @@ export function _testResetUnitsCache() {
30
29
  * @beta
31
30
  */
32
31
  export class BasicUnitsProvider {
32
+ /** Find a built-in unit by fully qualified name using local data. */
33
+ findUnitByNameSync(unitName) {
34
+ const state = resolveStateSync();
35
+ const entry = state.nameMap.get(unitName);
36
+ return entry ? entry.props : new BadUnit();
37
+ }
38
+ /** Compute a conversion between built-in units using the same bundled data as [[getConversion]]. */
39
+ getConversionSync(fromUnit, toUnit) {
40
+ return getBasicUnitConversion(resolveStateSync(), fromUnit, toUnit);
41
+ }
33
42
  // ── UnitsProvider implementation ─────────────────────────────────────
34
43
  /** Find a unit by its display label, optionally filtering by schema name, phenomenon, and unit system.
35
44
  * @param unitLabel - The display label to search for (case-insensitive).
@@ -1 +1 @@
1
- {"version":3,"file":"BasicUnitsProvider.js","sourceRoot":"","sources":["../../src/BasicUnitsProvider.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAC5E,OAAO,EAAE,qCAAqC,EAAE,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;AAEvH,KAAK,UAAU,YAAY;IACzB,OAAO,qBAAqB,CAAC,KAAK,IAAI,EAAE;QACtC,kEAAkE;QAClE,yFAAyF;QACzF,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAC;QAChE,OAAO,MAA8B,CAAC;IACxC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,oBAAoB;IAClC,qCAAqC,EAAE,CAAC;AAC1C,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,kBAAkB;IAE7B,wEAAwE;IAExE;;;;;;OAMG;IACI,KAAK,CAAC,QAAQ,CAAC,SAAiB,EAAE,UAAmB,EAAE,UAAmB,EAAE,UAAmB;QACpG,MAAM,KAAK,GAAG,MAAM,YAAY,EAAE,CAAC;QACnC,IAAI,UAAU,IAAI,UAAU,KAAK,KAAK,CAAC,UAAU,EAAE,CAAC;YAClD,OAAO,IAAI,OAAO,EAAE,CAAC;QACvB,CAAC;QACD,MAAM,UAAU,GAAG,KAAK,CA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AM,KAAK,GAAG,MAAM,YAAY,EAAE,CAAC;QACnC,OAAO,sBAAsB,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC;CACF","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 type { UnitProps, UnitsProvider } from \"./Interfaces\";\r\nimport type { SerializedUnitSchema } from \"./SerializedUnitSchema\";\r\nimport { BadUnit } from \"./Unit\";\r\nimport { getBasicUnitConversion } from \"./internal/BasicUnitConversionData\";\r\nimport { _testResetResolvedBasicUnitsDataCache, resolveBasicUnitsData } from \"./internal/BasicUnitsResolvedStateCache\";\r\n\r\nasync function resolveState() {\r\n return resolveBasicUnitsData(async () => {\r\n // First caller pays the dynamic-import + schema-index build cost.\r\n // Concurrent callers await the same promise, and later callers reuse the resolved state.\r\n const { default: schema } = await import(\"./assets/Units.json\");\r\n return schema as SerializedUnitSchema;\r\n });\r\n}\r\n\r\n/** @internal — test use only. Resets the shared module-level lazy cache. */\r\nexport function _testResetUnitsCache(): void {\r\n _testResetResolvedBasicUnitsDataCache();\r\n}\r\n\r\n/**\r\n * A `UnitsProvider` backed by the full BIS `Units.ecschema.json` bundled as a JSON asset.\r\n *\r\n * The bundled JSON is loaded lazily via dynamic `import()` on the first provider call and cached\r\n * at module scope — construction is essentially free, and multiple instances\r\n * share the same immutable lookup indexes.\r\n *\r\n * If an initial schema load fails, later provider calls will retry the load instead of pinning the\r\n * provider into a permanently failed module-level state.\r\n *\r\n * This is the zero-dependency default for backends, tools, and any frontend that doesn't need\r\n * iModel overrides. Equivalent to calling `createUnitsProvider()` with no arguments.\r\n *\r\n * @see createUnitsProvider for layering schema-defined units on top of basic BIS units.\r\n * @beta\r\n */\r\nexport class BasicUnitsProvider implements UnitsProvider {\r\n\r\n // ── UnitsProvider implementation ─────────────────────────────────────\r\n\r\n /** Find a unit by its display label, optionally filtering by schema name, phenomenon, and unit system.\r\n * @param unitLabel - The display label to search for (case-insensitive).\r\n * @param schemaName - Optional schema name filter. Returns `BadUnit` if provided and not `\"Units\"`.\r\n * @param phenomenon - Optional phenomenon filter (e.g. `\"Units.LENGTH\"`).\r\n * @param unitSystem - Optional unit system filter (e.g. `\"Units.METRIC\"`).\r\n * @returns The matching `UnitProps`, or a `BadUnit` if no match is found.\r\n */\r\n public async findUnit(unitLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps> {\r\n const state = await resolveState();\r\n if (schemaName && schemaName !== state.schemaName) {\r\n return new BadUnit();\r\n }\r\n const candidates = state.labelMap.get(unitLabel.toLowerCase());\r\n if (!candidates || candidates.length === 0) {\r\n return new BadUnit();\r\n }\r\n\r\n for (const c of candidates) {\r\n if (phenomenon && c.props.phenomenon !== phenomenon) {\r\n continue;\r\n }\r\n if (unitSystem && c.props.system !== unitSystem) {\r\n continue;\r\n }\r\n return c.props;\r\n }\r\n\r\n return new BadUnit();\r\n }\r\n\r\n /** Return all units belonging to the given phenomenon (unit family).\r\n * @param phenomenon - The phenomenon full name (e.g. `\"Units.LENGTH\"`).\r\n * @returns An array of matching `UnitProps`, or an empty array if none.\r\n */\r\n public async getUnitsByFamily(phenomenon: string): Promise<UnitProps[]> {\r\n const state = await resolveState();\r\n const entries = state.phenomenonMap.get(phenomenon);\r\n return entries ? entries.map((e) => e.props) : [];\r\n }\r\n\r\n /** Find a unit by its fully-qualified name (e.g. `\"Units.M\"`).\r\n * @param unitName - The qualified unit name.\r\n * @returns The matching `UnitProps`, or a `BadUnit` if not found.\r\n */\r\n public async findUnitByName(unitName: string): Promise<UnitProps> {\r\n const state = await resolveState();\r\n const entry = state.nameMap.get(unitName);\r\n return entry ? entry.props : new BadUnit();\r\n }\r\n\r\n /** Compute the conversion factors from `fromUnit` to `toUnit`.\r\n * Handles normal units, inverted units, and mixed (inverted ↔ non-inverted) conversions.\r\n * @param fromUnit - The source unit.\r\n * @param toUnit - The target unit.\r\n * @returns A `UnitConversionProps` with `factor`, `offset`, and optionally `inversion` and `error`.\r\n */\r\n public async getConversion(fromUnit: UnitProps, toUnit: UnitProps) {\r\n const state = await resolveState();\r\n return getBasicUnitConversion(state, fromUnit, toUnit);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"BasicUnitsProvider.js","sourceRoot":"","sources":["../../src/BasicUnitsProvider.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAC5E,OAAO,EAAE,qCAAqC,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AAClJ,OAAO,kBAAkB,MAAM,qBAAqB,CAAC;AAErD,MAAM,aAAa,GAAG,kBAA0C,CAAC;AAEjE,KAAK,UAAU,YAAY;IACzB,OAAO,qBAAqB,CAAC,KAAK,IAAI,EAAE,CAAC,aAAa,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,gBAAgB;IACvB,OAAO,yBAAyB,CAAC,aAAa,CAAC,CAAC;AAClD,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,oBAAoB;IAClC,qCAAqC,EAAE,CAAC;AAC1C,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,kBAAkB;IAE7B,qEAAqE;IAC9D,kBAAkB,CAAC,QAAgB;QACxC,MAAM,KAAK,GAAG,gBAAgB,EAAE,CAAC;QACjC,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC1C,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,OAAO,EAAE,CAAC;IAC7C,CAAC;IAED,oGAAoG;IAC7F,iBAAiB,CAAC,QAAmB,EAAE,MAAiB;QAC7D,OAAO,sBAAsB,CAA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AAC;IAED;;;OAGG;IACI,KAAK,CAAC,cAAc,CAAC,QAAgB;QAC1C,MAAM,KAAK,GAAG,MAAM,YAAY,EAAE,CAAC;QACnC,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC1C,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,OAAO,EAAE,CAAC;IAC7C,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,aAAa,CAAC,QAAmB,EAAE,MAAiB;QAC/D,MAAM,KAAK,GAAG,MAAM,YAAY,EAAE,CAAC;QACnC,OAAO,sBAAsB,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC;CACF","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 type { SyncUnitsProvider, UnitProps, UnitsProvider } from \"./Interfaces\";\r\nimport type { SerializedUnitSchema } from \"./SerializedUnitSchema\";\r\nimport { BadUnit } from \"./Unit\";\r\nimport { getBasicUnitConversion } from \"./internal/BasicUnitConversionData\";\r\nimport { _testResetResolvedBasicUnitsDataCache, resolveBasicUnitsData, resolveBasicUnitsDataSync } from \"./internal/BasicUnitsResolvedStateCache\";\r\nimport bundledUnitsSchema from \"./assets/Units.json\";\r\n\r\nconst bundledSchema = bundledUnitsSchema as SerializedUnitSchema;\r\n\r\nasync function resolveState() {\r\n return resolveBasicUnitsData(async () => bundledSchema);\r\n}\r\n\r\nfunction resolveStateSync() {\r\n return resolveBasicUnitsDataSync(bundledSchema);\r\n}\r\n\r\n/** @internal — test use only. Resets the shared module-level lazy cache. */\r\nexport function _testResetUnitsCache(): void {\r\n _testResetResolvedBasicUnitsDataCache();\r\n}\r\n\r\n/**\r\n * A `UnitsProvider` backed by the full BIS `Units.ecschema.json` bundled as a JSON asset.\r\n *\r\n * The bundled data is available locally. The provider builds its immutable lookup indexes on the\r\n * first call and caches them at module scope, so multiple instances share the same indexes.\r\n *\r\n * If resolving the bundled data fails, the next provider call retries instead of retaining a failed\r\n * module-level state.\r\n *\r\n * This is the zero-dependency default for backends, tools, and any frontend that doesn't need\r\n * iModel overrides. Equivalent to calling `createUnitsProvider()` with no arguments.\r\n *\r\n * @see createUnitsProvider for layering schema-defined units on top of basic BIS units.\r\n * @beta\r\n */\r\nexport class BasicUnitsProvider implements UnitsProvider, SyncUnitsProvider {\r\n\r\n /** Find a built-in unit by fully qualified name using local data. */\r\n public findUnitByNameSync(unitName: string): UnitProps {\r\n const state = resolveStateSync();\r\n const entry = state.nameMap.get(unitName);\r\n return entry ? entry.props : new BadUnit();\r\n }\r\n\r\n /** Compute a conversion between built-in units using the same bundled data as [[getConversion]]. */\r\n public getConversionSync(fromUnit: UnitProps, toUnit: UnitProps) {\r\n return getBasicUnitConversion(resolveStateSync(), fromUnit, toUnit);\r\n }\r\n\r\n // ── UnitsProvider implementation ─────────────────────────────────────\r\n\r\n /** Find a unit by its display label, optionally filtering by schema name, phenomenon, and unit system.\r\n * @param unitLabel - The display label to search for (case-insensitive).\r\n * @param schemaName - Optional schema name filter. Returns `BadUnit` if provided and not `\"Units\"`.\r\n * @param phenomenon - Optional phenomenon filter (e.g. `\"Units.LENGTH\"`).\r\n * @param unitSystem - Optional unit system filter (e.g. `\"Units.METRIC\"`).\r\n * @returns The matching `UnitProps`, or a `BadUnit` if no match is found.\r\n */\r\n public async findUnit(unitLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps> {\r\n const state = await resolveState();\r\n if (schemaName && schemaName !== state.schemaName) {\r\n return new BadUnit();\r\n }\r\n const candidates = state.labelMap.get(unitLabel.toLowerCase());\r\n if (!candidates || candidates.length === 0) {\r\n return new BadUnit();\r\n }\r\n\r\n for (const c of candidates) {\r\n if (phenomenon && c.props.phenomenon !== phenomenon) {\r\n continue;\r\n }\r\n if (unitSystem && c.props.system !== unitSystem) {\r\n continue;\r\n }\r\n return c.props;\r\n }\r\n\r\n return new BadUnit();\r\n }\r\n\r\n /** Return all units belonging to the given phenomenon (unit family).\r\n * @param phenomenon - The phenomenon full name (e.g. `\"Units.LENGTH\"`).\r\n * @returns An array of matching `UnitProps`, or an empty array if none.\r\n */\r\n public async getUnitsByFamily(phenomenon: string): Promise<UnitProps[]> {\r\n const state = await resolveState();\r\n const entries = state.phenomenonMap.get(phenomenon);\r\n return entries ? entries.map((e) => e.props) : [];\r\n }\r\n\r\n /** Find a unit by its fully-qualified name (e.g. `\"Units.M\"`).\r\n * @param unitName - The qualified unit name.\r\n * @returns The matching `UnitProps`, or a `BadUnit` if not found.\r\n */\r\n public async findUnitByName(unitName: string): Promise<UnitProps> {\r\n const state = await resolveState();\r\n const entry = state.nameMap.get(unitName);\r\n return entry ? entry.props : new BadUnit();\r\n }\r\n\r\n /** Compute the conversion factors from `fromUnit` to `toUnit`.\r\n * Handles normal units, inverted units, and mixed (inverted ↔ non-inverted) conversions.\r\n * @param fromUnit - The source unit.\r\n * @param toUnit - The target unit.\r\n * @returns A `UnitConversionProps` with `factor`, `offset`, and optionally `inversion` and `error`.\r\n */\r\n public async getConversion(fromUnit: UnitProps, toUnit: UnitProps) {\r\n const state = await resolveState();\r\n return getBasicUnitConversion(state, fromUnit, toUnit);\r\n }\r\n}\r\n"]}
@@ -1,7 +1,7 @@
1
1
  /** @packageDocumentation
2
2
  * @module Quantity
3
3
  */
4
- import { UnitProps, UnitsProvider } from "../Interfaces";
4
+ import { SyncUnitsProvider, UnitProps, UnitsProvider } from "../Interfaces";
5
5
  import { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision, RatioFormatType, RatioType, ScientificType, ShowSignOption } from "./FormatEnums";
6
6
  import { CloneOptions, FormatProps, ResolvedFormatProps } from "./Interfaces";
7
7
  /** A base Format class with shared properties and functionality between quantity and ecschema-metadata Format classes
@@ -124,6 +124,8 @@ export declare class Format extends BaseFormat {
124
124
  fromFullyResolvedJSON(jsonObj: ResolvedFormatProps): void;
125
125
  /** Create a Format from FormatProps */
126
126
  static createFromJSON(name: string, unitsProvider: UnitsProvider, formatProps: FormatProps): Promise<Format>;
127
+ /** Create a `Format` from `FormatProps` using a synchronous unit provider. */
128
+ static createFromJSONSync(name: string, unitsProvider: SyncUnitsProvider, formatProps: FormatProps): Format;
127
129
  static createFromFullyResolvedJSON(name: string, formatProps: ResolvedFormatProps): Format;
128
130
  /**
129
131
  * Returns a JSON object that contain the specification for this Format.
@@ -1 +1 @@
1
- {"version":3,"file":"Format.d.ts","sourceRoot":"","sources":["../../../src/Formatter/Format.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EACL,gBAAgB,EAAE,YAAY,EAAuB,UAAU,EAAE,mBAAmB,EAEpF,eAAe,EAAE,SAAS,EAC1B,cAAc,EACd,cAAc,EACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAA0B,MAAM,cAAc,CAAC;AAKtG;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,KAAK,CAAM;IACnB,SAAS,CAAC,YAAY,EAAE,MAAM,CAAO;IACrC,SAAS,CAAC,KAAK,EAAE,UAAU,CAAsB;IACjD,SAAS,CAAC,UAAU,EAAE,MAAM,CAAwB;IACpD,SAAS,CAAC,eAAe,EAAE,cAAc,CAA+B;IACxE,SAAS,CAAC,iBAAiB,EAAE,MAAM,CAAoD;IACvF,SAAS,CAAC,kBAAkB,EAAE,MAAM,CAAqD;IACzF,SAAS,CAAC,aAAa,SAAO;IAC9B,SAAS,CAAC,iBAAiB,SAAO;IAClC,SAAS,CAAC,aAAa,EAAE,YAAY,CAA8B;IACnE,SAAS,CAAC,OAAO,EAAE,MAAM,CAAO;IAChC,SAAS,CAAC,Y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WAAW,EAAE,WAAW,GAAG,mBAAmB;CA4H3E;AAED;;GAEG;AACH,qBAAa,MAAO,SAAQ,UAAU;IACpC,SAAS,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IAC1D,SAAS,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC;IAE7B;;OAEG;gBACS,IAAI,EAAE,MAAM;IAIxB,IAAW,KAAK,IAAI,KAAK,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,GAAG,SAAS,CAAwB;IAC9F,IAAW,QAAQ,IAAI,OAAO,CAAgE;IAC9F,IAAW,WAAW,IAAI,GAAG,CAA8B;WAE7C,uBAAuB,CAAC,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY;IAQnF;;OAEG;IACI,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM;IA2D5C;;OAEG;IACU,QAAQ,CAAC,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAKjF,qBAAqB,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI;IA+DhE,uCAAuC;WACnB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW;IAMvG,8EAA8E;WAChE,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,iBAAiB,EAAE,WAAW,EAAE,WAAW,GAAG,MAAM;WAMpG,2BAA2B,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,mBAAmB;IAMxF;;OAEG;IACI,MAAM,IAAI,WAAW;IAerB,mBAAmB,IAAI,mBAAmB;CA+ClD"}
@@ -372,6 +372,12 @@ export class Format extends BaseFormat {
372
372
  await actualFormat.fromJSON(unitsProvider, formatProps);
373
373
  return actualFormat;
374
374
  }
375
+ /** Create a `Format` from `FormatProps` using a synchronous unit provider. */
376
+ static createFromJSONSync(name, unitsProvider, formatProps) {
377
+ const actualFormat = new Format(name);
378
+ actualFormat.fromFullyResolvedJSON(resolveFormatPropsSync(name, unitsProvider, formatProps));
379
+ return actualFormat;
380
+ }
375
381
  static createFromFullyResolvedJSON(name, formatProps) {
376
382
  const actualFormat = new Format(name);
377
383
  actualFormat.fromFullyResolvedJSON(formatProps);
@@ -438,52 +444,50 @@ export class Format extends BaseFormat {
438
444
  return baseFormatProps;
439
445
  }
440
446
  }
441
- async function resolveCompositeUnit(provider, name, label) {
447
+ function validateCompositeUnitInput(name, label) {
442
448
  if (typeof name !== "string" || (undefined !== label && typeof label !== "string")) {
443
449
  throw new QuantityError(QuantityStatus.InvalidJson, `This Composite has a unit with an invalid 'name' or 'label' attribute.`);
444
450
  }
445
- const unit = await provider.findUnitByName(name);
451
+ }
452
+ function validateResolvedUnit(unit, errorMessage) {
446
453
  if (!unit || !unit.isValid) {
447
- throw new QuantityError(QuantityStatus.InvalidJson, `Invalid unit name '${name}'.`);
454
+ throw new QuantityError(QuantityStatus.InvalidJson, errorMessage);
448
455
  }
449
456
  return unit;
450
457
  }
451
- async function resolveAzimuthBearingUnit(formatName, jsonObj, key, provider) {
458
+ function getAzimuthBearingUnitName(formatName, jsonObj, key) {
452
459
  const unitName = jsonObj[key];
453
- if (undefined !== unitName) {
454
- if (typeof unitName !== "string") {
455
- throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid '${key}' attribute. It should be of type 'string'.`);
456
- }
457
- const unit = await provider.findUnitByName(unitName);
458
- if (!unit || !unit.isValid) {
459
- throw new QuantityError(QuantityStatus.InvalidJson, `Invalid unit name '${unitName}' for ${key} in Format '${formatName}'.`);
460
- }
461
- return unit;
460
+ if (undefined !== unitName && typeof unitName !== "string") {
461
+ throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid '${key}' attribute. It should be of type 'string'.`);
462
462
  }
463
- return undefined;
463
+ return unitName;
464
464
  }
465
- async function resolveFormatProps(formatName, unitsProvider, jsonObj) {
466
- let units;
467
- if (undefined !== jsonObj.composite?.units) {
468
- units = await Promise.all(jsonObj.composite.units.map(async (entry) => {
469
- const unit = await resolveCompositeUnit(unitsProvider, entry.name);
470
- return { unit, label: entry.label };
471
- }));
472
- // For Ratio formats with 2 units: validate both units have the same phenomenon
473
- const formatType = parseFormatType(jsonObj.type, formatName);
474
- if (formatType === FormatType.Ratio && units.length === 2) {
475
- const phenomenon1 = units[0].unit.phenomenon;
476
- const phenomenon2 = units[1].unit.phenomenon;
477
- if (phenomenon1 !== phenomenon2) {
478
- throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has 2-unit composite with different phenomena. Both units must have the same phenomenon. Found '${phenomenon1}' and '${phenomenon2}'.`);
479
- }
465
+ async function resolveCompositeUnit(provider, name, label) {
466
+ validateCompositeUnitInput(name, label);
467
+ return validateResolvedUnit(await provider.findUnitByName(name), `Invalid unit name '${name}'.`);
468
+ }
469
+ function resolveCompositeUnitSync(provider, name, label) {
470
+ validateCompositeUnitInput(name, label);
471
+ return validateResolvedUnit(provider.findUnitByNameSync(name), `Invalid unit name '${name}'.`);
472
+ }
473
+ async function resolveAzimuthBearingUnit(formatName, jsonObj, key, provider) {
474
+ const unitName = getAzimuthBearingUnitName(formatName, jsonObj, key);
475
+ return undefined === unitName ? undefined : validateResolvedUnit(await provider.findUnitByName(unitName), `Invalid unit name '${unitName}' for ${key} in Format '${formatName}'.`);
476
+ }
477
+ function resolveAzimuthBearingUnitSync(formatName, jsonObj, key, provider) {
478
+ const unitName = getAzimuthBearingUnitName(formatName, jsonObj, key);
479
+ return undefined === unitName ? undefined : validateResolvedUnit(provider.findUnitByNameSync(unitName), `Invalid unit name '${unitName}' for ${key} in Format '${formatName}'.`);
480
+ }
481
+ function validateResolvedFormatProps(formatName, jsonObj, units, azimuthBaseUnit, revolutionUnit) {
482
+ const formatType = parseFormatType(jsonObj.type, formatName);
483
+ if (formatType === FormatType.Ratio && units?.length === 2) {
484
+ const phenomenon1 = units[0].unit.phenomenon;
485
+ const phenomenon2 = units[1].unit.phenomenon;
486
+ if (phenomenon1 !== phenomenon2) {
487
+ throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has 2-unit composite with different phenomena. Both units must have the same phenomenon. Found '${phenomenon1}' and '${phenomenon2}'.`);
480
488
  }
481
489
  }
482
- let azimuthBaseUnit, revolutionUnit;
483
- const type = parseFormatType(jsonObj.type, formatName);
484
- if (type === FormatType.Azimuth || type === FormatType.Bearing) {
485
- azimuthBaseUnit = await resolveAzimuthBearingUnit(formatName, jsonObj, "azimuthBaseUnit", unitsProvider);
486
- revolutionUnit = await resolveAzimuthBearingUnit(formatName, jsonObj, "revolutionUnit", unitsProvider);
490
+ if (formatType === FormatType.Azimuth || formatType === FormatType.Bearing) {
487
491
  if (!revolutionUnit) {
488
492
  throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} is 'Azimuth' or 'Bearing' type therefore the attribute 'revolutionUnit' is required.`);
489
493
  }
@@ -491,6 +495,8 @@ async function resolveFormatProps(formatName, unitsProvider, jsonObj) {
491
495
  throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an 'azimuthBase' attribute therefore the attribute 'azimuthBaseUnit' is required.`);
492
496
  }
493
497
  }
498
+ }
499
+ function createResolvedFormatProps(jsonObj, units, azimuthBaseUnit, revolutionUnit) {
494
500
  return {
495
501
  ...jsonObj,
496
502
  azimuthBaseUnit,
@@ -501,4 +507,36 @@ async function resolveFormatProps(formatName, unitsProvider, jsonObj) {
501
507
  } : undefined,
502
508
  };
503
509
  }
510
+ async function resolveFormatProps(formatName, unitsProvider, jsonObj) {
511
+ const units = undefined === jsonObj.composite?.units ? undefined : await Promise.all(jsonObj.composite.units.map(async (entry) => ({
512
+ // Label is intentionally not validated, matching master: existing JSON may carry a non-string label (e.g. null).
513
+ unit: await resolveCompositeUnit(unitsProvider, entry.name),
514
+ label: entry.label,
515
+ })));
516
+ let azimuthBaseUnit;
517
+ let revolutionUnit;
518
+ const formatType = parseFormatType(jsonObj.type, formatName);
519
+ if (formatType === FormatType.Azimuth || formatType === FormatType.Bearing) {
520
+ azimuthBaseUnit = await resolveAzimuthBearingUnit(formatName, jsonObj, "azimuthBaseUnit", unitsProvider);
521
+ revolutionUnit = await resolveAzimuthBearingUnit(formatName, jsonObj, "revolutionUnit", unitsProvider);
522
+ }
523
+ validateResolvedFormatProps(formatName, jsonObj, units, azimuthBaseUnit, revolutionUnit);
524
+ return createResolvedFormatProps(jsonObj, units, azimuthBaseUnit, revolutionUnit);
525
+ }
526
+ function resolveFormatPropsSync(formatName, unitsProvider, jsonObj) {
527
+ const units = undefined === jsonObj.composite?.units ? undefined : jsonObj.composite.units.map((entry) => ({
528
+ // Keep in sync with resolveFormatProps: label is intentionally not validated.
529
+ unit: resolveCompositeUnitSync(unitsProvider, entry.name),
530
+ label: entry.label,
531
+ }));
532
+ let azimuthBaseUnit;
533
+ let revolutionUnit;
534
+ const formatType = parseFormatType(jsonObj.type, formatName);
535
+ if (formatType === FormatType.Azimuth || formatType === FormatType.Bearing) {
536
+ azimuthBaseUnit = resolveAzimuthBearingUnitSync(formatName, jsonObj, "azimuthBaseUnit", unitsProvider);
537
+ revolutionUnit = resolveAzimuthBearingUnitSync(formatName, jsonObj, "revolutionUnit", unitsProvider);
538
+ }
539
+ validateResolvedFormatProps(formatName, jsonObj, units, azimuthBaseUnit, revolutionUnit);
540
+ return createResolvedFormatProps(jsonObj, units, azimuthBaseUnit, revolutionUnit);
541
+ }
504
542
  //# sourceMappingURL=Format.js.map