@itwin/core-quantity 5.2.0-dev.8 → 5.3.0-dev.2

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.
@@ -4,6 +4,24 @@
4
4
  import { BeEvent } from "@itwin/core-bentley";
5
5
  import { UnitProps } from "../Interfaces";
6
6
  import { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision } from "./FormatEnums";
7
+ /** Defines the units that make up a composite format and their display properties.
8
+ * A composite format allows displaying a single quantity value across multiple units,
9
+ * such as displaying length as "5 feet 6 inches" or angle as "45° 30' 15"".
10
+ * @beta
11
+ */
12
+ export interface FormatCompositeProps {
13
+ /** separates values when formatting composite strings */
14
+ readonly spacer?: string;
15
+ readonly includeZero?: boolean;
16
+ /** Array of units this format is comprised of. Each unit specifies the unit name and
17
+ * an optional custom label that will override the unit's default label when displaying values. */
18
+ readonly units: Array<{
19
+ /** The name of the unit (e.g., "Units.FT", "Units.IN") */
20
+ readonly name: string;
21
+ /** Optional custom label that overrides the unit's default label (e.g., "ft" for feet, 'in' for inches) */
22
+ readonly label?: string;
23
+ }>;
24
+ }
7
25
  /** This interface defines the persistence format for describing the formatting of quantity values.
8
26
  * @beta
9
27
  */
@@ -35,15 +53,7 @@ export interface FormatProps {
35
53
  /** The name of the unit that represents a revolution/perigon. Required for bearing or azimuth types. */
36
54
  readonly revolutionUnit?: string;
37
55
  readonly allowMathematicOperations?: boolean;
38
- readonly composite?: {
39
- /** separates values when formatting composite strings */
40
- readonly spacer?: string;
41
- readonly includeZero?: boolean;
42
- readonly units: Array<{
43
- readonly name: string;
44
- readonly label?: string;
45
- }>;
46
- };
56
+ readonly composite?: FormatCompositeProps;
47
57
  }
48
58
  /** This interface is used when supporting Custom Formatters that need more than the standard set of properties.
49
59
  * @beta
@@ -55,6 +65,24 @@ export interface CustomFormatProps extends FormatProps {
55
65
  * @beta
56
66
  */
57
67
  export declare const isCustomFormatProps: (item: FormatProps) => item is CustomFormatProps;
68
+ /** A [[FormatCompositeProps]] with unit names replaced with JSON representations of those units.
69
+ * @beta
70
+ */
71
+ export type ResolvedFormatCompositeProps = Omit<FormatCompositeProps, "units"> & {
72
+ readonly units: Array<{
73
+ readonly unit: UnitProps;
74
+ readonly label?: string;
75
+ }>;
76
+ };
77
+ /** A [[FormatProps]] with all the references to units replaced with JSON representations of those units.
78
+ * @beta
79
+ */
80
+ export type ResolvedFormatProps = Omit<FormatDefinition, "azimuthBaseUnit" | "revolutionUnit" | "composite"> & {
81
+ readonly azimuthBaseUnit?: UnitProps;
82
+ readonly revolutionUnit?: UnitProps;
83
+ readonly composite?: ResolvedFormatCompositeProps;
84
+ readonly custom?: any;
85
+ };
58
86
  /** CloneFormat defines unit and label specification if primary unit is to be set during clone.
59
87
  * @beta
60
88
  */
@@ -103,13 +131,24 @@ export interface FormatsProvider {
103
131
  * @param name The full name of the Format or KindOfQuantity.
104
132
  */
105
133
  getFormat(name: string): Promise<FormatDefinition | undefined>;
134
+ /**
135
+ * Fired when formats are added, removed, or changed.
136
+ * If all formats are changed, a single string "all" is emitted. Else, an array of changed format names is emitted.
137
+ */
106
138
  onFormatsChanged: BeEvent<(args: FormatsChangedArgs) => void>;
107
139
  }
108
140
  /** This interface is implemented by a class that would provide and allow creating formats for use in formatting quantities.
109
141
  * @beta
110
142
  */
111
143
  export interface MutableFormatsProvider extends FormatsProvider {
144
+ /**
145
+ * Adds a new format or updates an existing format associated with the specified name.
146
+ */
112
147
  addFormat(name: string, format: FormatDefinition): Promise<void>;
148
+ /**
149
+ * Removes the format associated with the specified name.
150
+ * @param name The name of the format to remove.
151
+ */
113
152
  removeFormat(name: string): Promise<void>;
114
153
  }
115
154
  //# sourceMappingURL=Interfaces.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Interfaces.d.ts","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC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,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,cAAc,EAAE,KAAK,GAAG,MAAM,EAAE,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAAC;IAE/D;;;OAGG;IACH,gBAAgB,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,kBAAkB,KAAK,IAAI,CAAC,CAAC;CAC/D;AAED;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,eAAe;IAC7D;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjE;;;OAGG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C"}
@@ -1 +1 @@
1
- {"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAgEH;;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":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Quantity\n */\n\nimport { BeEvent } from \"@itwin/core-bentley\";\nimport { UnitProps } from \"../Interfaces\";\nimport { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision } from \"./FormatEnums\";\n\n/** This interface defines the persistence format for describing the formatting of quantity values.\n * @beta\n */\nexport interface FormatProps {\n readonly type: string;\n readonly precision?: number;\n readonly roundFactor?: number;\n readonly minWidth?: number;\n readonly showSignOption?: string;\n readonly formatTraits?: string | string[];\n readonly decimalSeparator?: string;\n readonly thousandSeparator?: string;\n readonly uomSeparator?: string;\n\n /** conditionally required. */\n readonly scientificType?: string;\n\n /** conditionally required. */\n readonly ratioType?: string;\n\n /** conditionally required. */\n readonly stationOffsetSize?: number;\n readonly stationSeparator?: string;\n\n /** Optional base factor for station formatting. A positive integer, defaults to 1. */\n readonly stationBaseFactor?: number;\n\n /** The base value for azimuth, specified from east counter-clockwise. */\n readonly azimuthBase?: number;\n\n /** The name of the unit for the azimuth base value. */\n readonly azimuthBaseUnit?: string;\n\n /** If set to true, azimuth values are returned counter-clockwise from the base. */\n readonly azimuthCounterClockwise?: boolean;\n\n /** The name of the unit that represents a revolution/perigon. Required for bearing or azimuth types. */\n readonly revolutionUnit?: string;\n\n readonly allowMathematicOperations?: boolean;\n readonly composite?: {\n /** separates values when formatting composite strings */\n readonly spacer?: string;\n readonly includeZero?: boolean;\n readonly units: Array<{\n readonly name: string;\n readonly label?: string;\n }>;\n };\n}\n\n/** This interface is used when supporting Custom Formatters that need more than the standard set of properties.\n * @beta\n */\nexport interface CustomFormatProps extends FormatProps {\n readonly custom: any;\n}\n\n/** CustomFormatProps type guard.\n * @beta\n */\nexport const isCustomFormatProps = (item: FormatProps): item is CustomFormatProps => {\n return (item as CustomFormatProps).custom !== undefined;\n};\n\n/** CloneFormat defines unit and label specification if primary unit is to be set during clone.\n * @beta\n */\nexport interface CloneUnit {\n unit?: UnitProps;\n label?: string;\n}\n\n/** CloneOptions that define modifications that can be made during the cloning of a Format.\n * @beta\n */\nexport interface CloneOptions {\n /** allows composite formats to be converted to only show primary unit */\n showOnlyPrimaryUnit?: boolean;\n /** allow format traits to be set */\n traits?: FormatTraits;\n /** allows new FormatType to be specified */\n type?: FormatType;\n /** allows precision to be set, this will throw if value is not valid for FormatType */\n precision?: DecimalPrecision | FractionalPrecision;\n /** allows primary unit and label to be specified */\n primaryUnit?: CloneUnit;\n}\n\n/** An extension of FormatProps to help identify formats.\n * @beta\n */\nexport interface FormatDefinition extends FormatProps {\n readonly name?: string;\n readonly label?: string;\n readonly description?: string;\n}\n\n/** Argument for [[FormatsProvider.onFormatsChanged]]\n * @beta\n */\nexport interface FormatsChangedArgs {\n /**\n * If `all` - all formats within the `FormatsProvider` have changed.\n * If array, the array items list the names of formats that were changed or removed.\n */\n formatsChanged: \"all\" | string[];\n}\n\n/** This interface is implemented by a class that would provide formats for use in formatting quantities.\n * @beta\n */\nexport interface FormatsProvider {\n /**\n * @param name The full name of the Format or KindOfQuantity.\n */\n getFormat(name: string): Promise<FormatDefinition | undefined>;\n\n onFormatsChanged: BeEvent<(args: FormatsChangedArgs) => void>;\n}\n\n/** This interface is implemented by a class that would provide and allow creating formats for use in formatting quantities.\n * @beta\n */\nexport interface MutableFormatsProvider extends FormatsProvider {\n addFormat(name: string, format: FormatDefinition): Promise<void>;\n removeFormat(name: string): Promise<void>;\n}\n"]}
1
+ {"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AA2EH;;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":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Quantity\n */\n\nimport { BeEvent } from \"@itwin/core-bentley\";\nimport { UnitProps } from \"../Interfaces\";\nimport { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision } from \"./FormatEnums\";\n\n/** Defines the units that make up a composite format and their display properties.\n * A composite format allows displaying a single quantity value across multiple units,\n * such as displaying length as \"5 feet 6 inches\" or angle as \"45° 30' 15\"\".\n * @beta\n */\nexport interface FormatCompositeProps {\n /** separates values when formatting composite strings */\n readonly spacer?: string;\n readonly includeZero?: boolean;\n /** Array of units this format is comprised of. Each unit specifies the unit name and\n * an optional custom label that will override the unit's default label when displaying values. */\n readonly units: Array<{\n /** The name of the unit (e.g., \"Units.FT\", \"Units.IN\") */\n readonly name: string;\n /** Optional custom label that overrides the unit's default label (e.g., \"ft\" for feet, 'in' for inches) */\n readonly label?: string;\n }>;\n}\n\n/** This interface defines the persistence format for describing the formatting of quantity values.\n * @beta\n */\nexport interface FormatProps {\n readonly type: string;\n readonly precision?: number;\n readonly roundFactor?: number;\n readonly minWidth?: number;\n readonly showSignOption?: string;\n readonly formatTraits?: string | string[];\n readonly decimalSeparator?: string;\n readonly thousandSeparator?: string;\n readonly uomSeparator?: string;\n\n /** conditionally required. */\n readonly scientificType?: string;\n\n /** conditionally required. */\n readonly ratioType?: string;\n\n /** conditionally required. */\n readonly stationOffsetSize?: number;\n readonly stationSeparator?: string;\n\n /** Optional base factor for station formatting. A positive integer, defaults to 1. */\n readonly stationBaseFactor?: number;\n\n /** The base value for azimuth, specified from east counter-clockwise. */\n readonly azimuthBase?: number;\n\n /** The name of the unit for the azimuth base value. */\n readonly azimuthBaseUnit?: string;\n\n /** If set to true, azimuth values are returned counter-clockwise from the base. */\n readonly azimuthCounterClockwise?: boolean;\n\n /** The name of the unit that represents a revolution/perigon. Required for bearing or azimuth types. */\n readonly revolutionUnit?: string;\n\n readonly allowMathematicOperations?: boolean;\n readonly composite?: FormatCompositeProps;\n}\n\n/** This interface is used when supporting Custom Formatters that need more than the standard set of properties.\n * @beta\n */\nexport interface CustomFormatProps extends FormatProps {\n readonly custom: any;\n}\n\n/** CustomFormatProps type guard.\n * @beta\n */\nexport const isCustomFormatProps = (item: FormatProps): item is CustomFormatProps => {\n return (item as CustomFormatProps).custom !== undefined;\n};\n\n/** A [[FormatCompositeProps]] with unit names replaced with JSON representations of those units.\n * @beta\n */\nexport type ResolvedFormatCompositeProps = Omit<FormatCompositeProps, \"units\"> & {\n readonly units: Array<{\n readonly unit: UnitProps;\n readonly label?: string;\n }>;\n};\n\n/** A [[FormatProps]] with all the references to units replaced with JSON representations of those units.\n * @beta\n */\nexport type ResolvedFormatProps = Omit<FormatDefinition, \"azimuthBaseUnit\" | \"revolutionUnit\" | \"composite\"> & {\n readonly azimuthBaseUnit?: UnitProps;\n readonly revolutionUnit?: UnitProps;\n readonly composite?: ResolvedFormatCompositeProps;\n readonly custom?: any;\n};\n\n/** CloneFormat defines unit and label specification if primary unit is to be set during clone.\n * @beta\n */\nexport interface CloneUnit {\n unit?: UnitProps;\n label?: string;\n}\n\n/** CloneOptions that define modifications that can be made during the cloning of a Format.\n * @beta\n */\nexport interface CloneOptions {\n /** allows composite formats to be converted to only show primary unit */\n showOnlyPrimaryUnit?: boolean;\n /** allow format traits to be set */\n traits?: FormatTraits;\n /** allows new FormatType to be specified */\n type?: FormatType;\n /** allows precision to be set, this will throw if value is not valid for FormatType */\n precision?: DecimalPrecision | FractionalPrecision;\n /** allows primary unit and label to be specified */\n primaryUnit?: CloneUnit;\n}\n\n/** An extension of FormatProps to help identify formats.\n * @beta\n */\nexport interface FormatDefinition extends FormatProps {\n readonly name?: string;\n readonly label?: string;\n readonly description?: string;\n}\n\n/** Argument for [[FormatsProvider.onFormatsChanged]]\n * @beta\n */\nexport interface FormatsChangedArgs {\n /**\n * If `all` - all formats within the `FormatsProvider` have changed.\n * If array, the array items list the names of formats that were changed or removed.\n */\n formatsChanged: \"all\" | string[];\n}\n\n/** This interface is implemented by a class that would provide formats for use in formatting quantities.\n * @beta\n */\nexport interface FormatsProvider {\n /**\n * @param name The full name of the Format or KindOfQuantity.\n */\n getFormat(name: string): Promise<FormatDefinition | undefined>;\n\n /**\n * Fired when formats are added, removed, or changed.\n * If all formats are changed, a single string \"all\" is emitted. Else, an array of changed format names is emitted.\n */\n onFormatsChanged: BeEvent<(args: FormatsChangedArgs) => void>;\n}\n\n/** This interface is implemented by a class that would provide and allow creating formats for use in formatting quantities.\n * @beta\n */\nexport interface MutableFormatsProvider extends FormatsProvider {\n /**\n * Adds a new format or updates an existing format associated with the specified name.\n */\n addFormat(name: string, format: FormatDefinition): Promise<void>;\n /**\n * Removes the format associated with the specified name.\n * @param name The name of the format to remove.\n */\n removeFormat(name: string): Promise<void>;\n}\n"]}
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import { UnitProps, UnitsProvider } from "../Interfaces";
5
5
  import { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision, RatioType, ScientificType, ShowSignOption } from "./FormatEnums";
6
- import { CloneOptions, FormatProps } from "./Interfaces";
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
8
8
  * @beta
9
9
  */
@@ -83,7 +83,7 @@ export declare class BaseFormat {
83
83
  parseFormatTraits(formatTraitsFromJson: string | string[]): void;
84
84
  /** This method returns true if the formatTrait is set in this Format object. */
85
85
  hasFormatTraitSet(formatTrait: FormatTraits): boolean;
86
- loadFormatProperties(formatProps: FormatProps): void;
86
+ loadFormatProperties(formatProps: FormatProps | ResolvedFormatProps): void;
87
87
  }
88
88
  /** A class used to define the specifications for formatting quantity values. This class is typically loaded by reading [[FormatProps]].
89
89
  * @beta
@@ -99,7 +99,6 @@ export declare class Format extends BaseFormat {
99
99
  get hasUnits(): boolean;
100
100
  get customProps(): any;
101
101
  static isFormatTraitSetInProps(formatProps: FormatProps, trait: FormatTraits): boolean;
102
- private createUnit;
103
102
  /**
104
103
  * Clone Format
105
104
  */
@@ -108,11 +107,14 @@ export declare class Format extends BaseFormat {
108
107
  * Populates this Format with the values from the provided.
109
108
  */
110
109
  fromJSON(unitsProvider: UnitsProvider, jsonObj: FormatProps): Promise<void>;
110
+ fromFullyResolvedJSON(jsonObj: ResolvedFormatProps): void;
111
111
  /** Create a Format from FormatProps */
112
112
  static createFromJSON(name: string, unitsProvider: UnitsProvider, formatProps: FormatProps): Promise<Format>;
113
+ static createFromFullyResolvedJSON(name: string, formatProps: ResolvedFormatProps): Format;
113
114
  /**
114
115
  * Returns a JSON object that contain the specification for this Format.
115
116
  */
116
117
  toJSON(): FormatProps;
118
+ toFullyResolvedJSON(): ResolvedFormatProps;
117
119
  }
118
120
  //# sourceMappingURL=Format.d.ts.map
@@ -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,SAAS,EAAE,cAAc,EACzB,cAAc,EACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAqB,WAAW,EAAuB,MAAM,cAAc,CAAC;AAKjG;;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,YAAY,EAAE,OAAO,CAAQ;IACvC,SAAS,CAAC,SAA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OAEG;IACI,MAAM,IAAI,WAAW;IAerB,mBAAmB,IAAI,mBAAmB;CA6ClD"}
@@ -8,7 +8,6 @@
8
8
  import { QuantityConstants } from "../Constants";
9
9
  import { QuantityError, QuantityStatus } from "../Exception";
10
10
  import { DecimalPrecision, FormatTraits, formatTraitsToArray, FormatType, getTraitString, parseFormatTrait, parseFormatType, parsePrecision, parseRatioType, parseScientificType, parseShowSignOption, ShowSignOption, } from "./FormatEnums";
11
- import { isCustomFormatProps } from "./Interfaces";
12
11
  // cSpell:ignore ZERONORMALIZED, nosign, onlynegative, signalways, negativeparentheses
13
12
  // cSpell:ignore trailzeroes, keepsinglezero, zeroempty, keepdecimalpoint, applyrounding, fractiondash, showunitlabel, prependunitlabel, exponentonlynegative
14
13
  /** A base Format class with shared properties and functionality between quantity and ecschema-metadata Format classes
@@ -221,19 +220,6 @@ export class Format extends BaseFormat {
221
220
  const traitStr = getTraitString(trait);
222
221
  return formatTraits.find((traitEntry) => traitStr === traitEntry) ? true : false;
223
222
  }
224
- async createUnit(unitsProvider, name, label) {
225
- if (name === undefined || typeof (name) !== "string" || (label !== undefined && typeof (label) !== "string")) // throws if name is undefined or name isn't a string or if label is defined and isn't a string
226
- throw new QuantityError(QuantityStatus.InvalidJson, `This Composite has a unit with an invalid 'name' or 'label' attribute.`);
227
- for (const unit of this.units) {
228
- const unitObj = unit[0].name;
229
- if (unitObj.toLowerCase() === name.toLowerCase()) // duplicate names are not allowed
230
- throw new QuantityError(QuantityStatus.InvalidJson, `The unit ${unitObj} has a duplicate name.`);
231
- }
232
- const newUnit = await unitsProvider.findUnitByName(name);
233
- if (!newUnit || !newUnit.isValid)
234
- throw new QuantityError(QuantityStatus.InvalidJson, `Invalid unit name '${name}'.`);
235
- this.units.push([newUnit, label]);
236
- }
237
223
  /**
238
224
  * Clone Format
239
225
  */
@@ -293,9 +279,12 @@ export class Format extends BaseFormat {
293
279
  * Populates this Format with the values from the provided.
294
280
  */
295
281
  async fromJSON(unitsProvider, jsonObj) {
282
+ const json = await resolveFormatProps(this.name, unitsProvider, jsonObj);
283
+ return this.fromFullyResolvedJSON(json);
284
+ }
285
+ fromFullyResolvedJSON(jsonObj) {
296
286
  this.loadFormatProperties(jsonObj);
297
- if (isCustomFormatProps(jsonObj))
298
- this._customProps = jsonObj.custom;
287
+ this._customProps = jsonObj.custom;
299
288
  if (undefined !== jsonObj.composite) { // optional
300
289
  this._units = new Array();
301
290
  if (jsonObj.composite.includeZero !== undefined) {
@@ -315,15 +304,19 @@ export class Format extends BaseFormat {
315
304
  throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${this.name} has a Composite with an invalid 'units' attribute. It must be of type 'array'`);
316
305
  }
317
306
  if (jsonObj.composite.units.length > 0 && jsonObj.composite.units.length <= 4) { // Composite requires 1-4 units
318
- try {
319
- const createUnitPromises = [];
320
- for (const unit of jsonObj.composite.units) {
321
- createUnitPromises.push(this.createUnit(unitsProvider, unit.name, unit.label));
307
+ for (const nextUnit of jsonObj.composite.units) {
308
+ if (this._units) {
309
+ for (const existingUnit of this._units) {
310
+ const unitObj = existingUnit[0].name;
311
+ if (unitObj.toLowerCase() === nextUnit.unit.name.toLowerCase()) {
312
+ throw new QuantityError(QuantityStatus.InvalidJson, `The unit ${unitObj} has a duplicate name.`);
313
+ }
314
+ }
322
315
  }
323
- await Promise.all(createUnitPromises);
324
- }
325
- catch (e) {
326
- throw e;
316
+ if (undefined === this._units) {
317
+ this._units = [];
318
+ }
319
+ this._units.push([nextUnit.unit, nextUnit.label]);
327
320
  }
328
321
  }
329
322
  }
@@ -331,23 +324,8 @@ export class Format extends BaseFormat {
331
324
  throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${this.name} has a Composite with no valid 'units'`);
332
325
  }
333
326
  if (this.type === FormatType.Azimuth || this.type === FormatType.Bearing) {
334
- // these units cannot be loaded from loadFormatProperties() because they require an async call, and the method signature is already public
335
- if (undefined !== jsonObj.azimuthBaseUnit) {
336
- if (typeof (jsonObj.azimuthBaseUnit) !== "string")
337
- throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${this.name} has an invalid 'azimuthBaseUnit' attribute. It should be of type 'string'.`);
338
- const baseUnit = await unitsProvider.findUnitByName(jsonObj.azimuthBaseUnit);
339
- if (!baseUnit || !baseUnit.isValid)
340
- throw new QuantityError(QuantityStatus.InvalidJson, `Invalid unit name '${jsonObj.azimuthBaseUnit}' for azimuthBaseUnit in Format '${this.name}'.`);
341
- this._azimuthBaseUnit = baseUnit;
342
- }
343
- if (undefined !== jsonObj.revolutionUnit) {
344
- if (typeof (jsonObj.revolutionUnit) !== "string")
345
- throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${this.name} has an invalid 'revolutionUnit' attribute. It should be of type 'string'.`);
346
- const revolutionUnit = await unitsProvider.findUnitByName(jsonObj.revolutionUnit);
347
- if (!revolutionUnit || !revolutionUnit.isValid)
348
- throw new QuantityError(QuantityStatus.InvalidJson, `Invalid unit name '${jsonObj.revolutionUnit}' for revolutionUnit in Format '${this.name}'.`);
349
- this._revolutionUnit = revolutionUnit;
350
- }
327
+ this._azimuthBaseUnit = jsonObj.azimuthBaseUnit;
328
+ this._revolutionUnit = jsonObj.revolutionUnit;
351
329
  if (this._revolutionUnit === undefined)
352
330
  throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${this.name} is 'Azimuth' or 'Bearing' type therefore the attribute 'revolutionUnit' is required.`);
353
331
  if (this._azimuthBase !== undefined && this._azimuthBaseUnit === undefined)
@@ -360,17 +338,36 @@ export class Format extends BaseFormat {
360
338
  await actualFormat.fromJSON(unitsProvider, formatProps);
361
339
  return actualFormat;
362
340
  }
341
+ static createFromFullyResolvedJSON(name, formatProps) {
342
+ const actualFormat = new Format(name);
343
+ actualFormat.fromFullyResolvedJSON(formatProps);
344
+ return actualFormat;
345
+ }
363
346
  /**
364
347
  * Returns a JSON object that contain the specification for this Format.
365
348
  */
366
349
  toJSON() {
350
+ const json = this.toFullyResolvedJSON();
351
+ return {
352
+ ...json,
353
+ azimuthBaseUnit: json.azimuthBaseUnit?.name,
354
+ revolutionUnit: json.revolutionUnit?.name,
355
+ composite: json.composite ? {
356
+ ...json.composite,
357
+ units: json.composite.units.map((unit) => {
358
+ return undefined !== unit.label ? { name: unit.unit.name, label: unit.label } : { name: unit.unit.name };
359
+ }),
360
+ } : undefined,
361
+ };
362
+ }
363
+ toFullyResolvedJSON() {
367
364
  let composite;
368
365
  if (this.units) {
369
366
  const units = this.units.map((value) => {
370
367
  if (undefined !== value[1])
371
- return { name: value[0].name, label: value[1] };
368
+ return { unit: value[0], label: value[1] };
372
369
  else
373
- return { name: value[0].name };
370
+ return { unit: value[0] };
374
371
  });
375
372
  composite = {
376
373
  spacer: this.spacer,
@@ -378,8 +375,8 @@ export class Format extends BaseFormat {
378
375
  units,
379
376
  };
380
377
  }
381
- const azimuthBaseUnit = this.azimuthBaseUnit ? this.azimuthBaseUnit.name : undefined;
382
- const revolutionUnit = this.revolutionUnit ? this.revolutionUnit.name : undefined;
378
+ const azimuthBaseUnit = this.azimuthBaseUnit;
379
+ const revolutionUnit = this.revolutionUnit;
383
380
  const baseFormatProps = {
384
381
  type: this.type,
385
382
  precision: this.precision,
@@ -400,13 +397,63 @@ export class Format extends BaseFormat {
400
397
  azimuthCounterClockwise: this.azimuthCounterClockwise,
401
398
  revolutionUnit,
402
399
  composite,
400
+ custom: this.customProps,
403
401
  };
404
- if (this.customProps)
405
- return {
406
- ...baseFormatProps,
407
- custom: this.customProps,
408
- };
409
402
  return baseFormatProps;
410
403
  }
411
404
  }
405
+ async function resolveCompositeUnit(provider, name, label) {
406
+ if (typeof name !== "string" || (undefined !== label && typeof label !== "string")) {
407
+ throw new QuantityError(QuantityStatus.InvalidJson, `This Composite has a unit with an invalid 'name' or 'label' attribute.`);
408
+ }
409
+ const unit = await provider.findUnitByName(name);
410
+ if (!unit || !unit.isValid) {
411
+ throw new QuantityError(QuantityStatus.InvalidJson, `Invalid unit name '${name}'.`);
412
+ }
413
+ return unit;
414
+ }
415
+ async function resolveAzimuthBearingUnit(formatName, jsonObj, key, provider) {
416
+ const unitName = jsonObj[key];
417
+ if (undefined !== unitName) {
418
+ if (typeof unitName !== "string") {
419
+ throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid '${key}' attribute. It should be of type 'string'.`);
420
+ }
421
+ const unit = await provider.findUnitByName(unitName);
422
+ if (!unit || !unit.isValid) {
423
+ throw new QuantityError(QuantityStatus.InvalidJson, `Invalid unit name '${unitName}' for ${key} in Format '${formatName}'.`);
424
+ }
425
+ return unit;
426
+ }
427
+ return undefined;
428
+ }
429
+ async function resolveFormatProps(formatName, unitsProvider, jsonObj) {
430
+ let units;
431
+ if (undefined !== jsonObj.composite?.units) {
432
+ units = await Promise.all(jsonObj.composite.units.map(async (entry) => {
433
+ const unit = await resolveCompositeUnit(unitsProvider, entry.name);
434
+ return { unit, label: entry.label };
435
+ }));
436
+ }
437
+ let azimuthBaseUnit, revolutionUnit;
438
+ const type = parseFormatType(jsonObj.type, formatName);
439
+ if (type === FormatType.Azimuth || type === FormatType.Bearing) {
440
+ azimuthBaseUnit = await resolveAzimuthBearingUnit(formatName, jsonObj, "azimuthBaseUnit", unitsProvider);
441
+ revolutionUnit = await resolveAzimuthBearingUnit(formatName, jsonObj, "revolutionUnit", unitsProvider);
442
+ if (!revolutionUnit) {
443
+ throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} is 'Azimuth' or 'Bearing' type therefore the attribute 'revolutionUnit' is required.`);
444
+ }
445
+ if (jsonObj.azimuthBase !== undefined && !azimuthBaseUnit) {
446
+ throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an 'azimuthBase' attribute therefore the attribute 'azimuthBaseUnit' is required.`);
447
+ }
448
+ }
449
+ return {
450
+ ...jsonObj,
451
+ azimuthBaseUnit,
452
+ revolutionUnit,
453
+ composite: units ? {
454
+ ...jsonObj.composite,
455
+ units,
456
+ } : undefined,
457
+ };
458
+ }
412
459
  //# sourceMappingURL=Format.js.map