azurite
Version:
An open source Azure Storage API compatible server
63 lines • 2.51 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.EdmDouble = void 0;
const constants_1 = require("../utils/constants");
const EntityProperty_1 = require("./EntityProperty");
class EdmDouble {
static validate(value) {
if (value === "NaN" || value === "Infinity" || value === "-Infinity") {
return value;
}
if (typeof value === "string") {
// TODO: Support convert from string. parseFloat doesn't strictly checks non number chars
const val = Number.parseFloat(value);
if (!Number.isNaN(val)) {
// Test on both Product server and Azurite, they are aligned: "1.797693134862315e308" will pass validation, "1.797693134862316e308" will fail validation.
if (val === Number.POSITIVE_INFINITY || val === Number.NEGATIVE_INFINITY) {
throw TypeError(`InvalidInput`);
}
return val;
}
}
if (typeof value !== "number") {
throw TypeError(`Not a valid EdmDouble string.`);
}
return value;
}
constructor(value) {
this.value = value;
this.typedValue = EdmDouble.validate(value);
}
toJsonPropertyValuePair(name) {
return [name, this.value];
}
toJsonPropertyValueString(name) {
if (typeof this.typedValue === "number") {
return `"${name}":${Number.isInteger(this.value) ? this.typedValue.toFixed(1) : this.value}`;
}
else {
return `"${name}":${JSON.stringify(this.typedValue)}`;
}
}
toJsonPropertyTypePair(name, annotationLevel, isSystemProperty, force = false) {
if (isSystemProperty) {
throw RangeError(`EdmDouble type shouldn't be a system property.`);
}
if (force ||
(typeof this.typedValue === "string" &&
(annotationLevel === EntityProperty_1.AnnotationLevel.MINIMAL ||
annotationLevel === EntityProperty_1.AnnotationLevel.FULL))) {
return [`${name}${constants_1.ODATA_TYPE}`, "Edm.Double"];
}
}
toJsonPropertyTypeString(name, annotationLevel, isSystemProperty) {
const res = this.toJsonPropertyTypePair(name, annotationLevel, isSystemProperty);
if (!res) {
return;
}
const [key, value] = res;
return `"${key}":"${value}"`;
}
}
exports.EdmDouble = EdmDouble;
//# sourceMappingURL=EdmDouble.js.map
;