@itwin/presentation-common
Version:
Common pieces for iModel.js presentation packages
55 lines • 2.21 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Core
*/
import { CompressedId64Set } from "@itwin/core-bentley";
/**
* Possible variable value types
* @public
*/
export var VariableValueTypes;
(function (VariableValueTypes) {
/** Integer value */
VariableValueTypes["Int"] = "int";
/** Array of integer values */
VariableValueTypes["IntArray"] = "int[]";
/** Boolean value */
VariableValueTypes["Bool"] = "bool";
/** String value */
VariableValueTypes["String"] = "string";
/** Id64String value */
VariableValueTypes["Id64"] = "id64";
/** Array of Id64String values */
VariableValueTypes["Id64Array"] = "id64[]";
})(VariableValueTypes || (VariableValueTypes = {}));
/** @public */
// eslint-disable-next-line @typescript-eslint/no-redeclare
export var RulesetVariable;
(function (RulesetVariable) {
/**
* Serialize given RulesetVariable to JSON.
* Note: In case of [[Id64sRulesetVariable]], this method expects IDs are sorted. See [[OrderedId64Iterable.sortArray]].
*/
function toJSON(variable) {
if (variable.type === VariableValueTypes.Id64Array) {
return { ...variable, value: CompressedId64Set.compressArray(variable.value) };
}
return variable;
}
RulesetVariable.toJSON = toJSON;
/** Deserialize [[RulesetVariable]] from JSON. */
function fromJSON(json) {
if (json.type === VariableValueTypes.Id64Array) {
if (typeof json.value === "string") {
return { ...json, value: CompressedId64Set.decompressArray(json.value) };
}
return json; // for some reason TS doesn't understand that `json.value` is always an array here
}
return json;
}
RulesetVariable.fromJSON = fromJSON;
})(RulesetVariable || (RulesetVariable = {}));
//# sourceMappingURL=RulesetVariables.js.map