UNPKG

igniteui-angular-core

Version:

Ignite UI Angular Core logic used in multiple UI components.

698 lines (697 loc) 24.2 kB
/* THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE AGREEMENT ("AGREEMENT") LOCATED HERE: https://www.infragistics.com/legal/license/igultimate-la https://www.infragistics.com/legal/license/igultimate-eula GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE: you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company. */ import { __extends } from "tslib"; import { Base, NotSupportedException, typeCast, Date_$type, Boolean_$type, markType } from "./type"; import { TypeDescriptionContext } from "./TypeDescriptionContext"; import { DescriptionTreeBuilderOptions } from "./DescriptionTreeBuilderOptions"; import { DescriptionTreeBuilder } from "./DescriptionTreeBuilder"; import { DescriptionTreeNode } from "./DescriptionTreeNode"; import { DescriptionSerializerBuilder } from "./DescriptionSerializerBuilder"; import { DescriptionResult } from "./DescriptionResult"; import { JsonDictionaryParser } from "./JsonDictionaryParser"; import { JsonDictionaryObject } from "./JsonDictionaryObject"; import { JsonDictionaryValue } from "./JsonDictionaryValue"; import { EmbeddedRefDescription } from "./EmbeddedRefDescription"; import { JsonDictionaryArray } from "./JsonDictionaryArray"; import { PointDescription } from "./PointDescription"; import { SizeDescription } from "./SizeDescription"; import { RectDescription } from "./RectDescription"; import { NotImplementedException } from "./NotImplementedException"; import { Convert } from "./Convert"; import { truncate, isNaN_, isPositiveInfinity, isNegativeInfinity } from "./number"; import { stringEndsWith, stringStartsWith, stringReplace } from "./string"; /** * @hidden */ var DescriptionSerializer = /** @class */ /*@__PURE__*/ (function (_super) { __extends(DescriptionSerializer, _super); function DescriptionSerializer() { var _this = _super.call(this) || this; _this.i = false; _this.g = false; _this.f = false; _this.k = null; _this.e = false; return _this; } DescriptionSerializer.prototype.h = function (a, b, c) { var d = ((function () { var $ret = new DescriptionTreeBuilderOptions(); $ret.a = true; $ret.b = c; return $ret; })()); DescriptionTreeBuilder.createTreeWithMoreOptions(a, b, d); return d.c; }; DescriptionSerializer.prototype.r = function (a, b) { var c = DescriptionTreeBuilder.createTree(a, b); var d = new DescriptionSerializerBuilder(); this.s(a, c, d); return d.toString(); }; DescriptionSerializer.prototype.y = function (a, b, c) { this.s(a, b, c); }; DescriptionSerializer.prototype.c = function (a, b) { var c = new JsonDictionaryParser(); var d = c.parse(b); return this.d(a, d, false, null, false); }; DescriptionSerializer.prototype.d = function (a, b, c, d, e) { if (typeCast(JsonDictionaryValue.$, b) !== null && (typeCast(JsonDictionaryValue.$, b)).e == 3) { return ((function () { var $ret = new DescriptionResult(); $ret.result = null; return $ret; })()); } if (!(typeCast(JsonDictionaryObject.$, b) !== null)) { throw new NotSupportedException(1, "expected an object at the root of the json"); } var f = b; if (c) { this.f = true; this.k = d; } if (e) { this.e = true; } var g = this.b(a, f); this.f = false; this.k = null; this.e = false; return g; }; DescriptionSerializer.prototype.aa = function (a, b, c, d, e) { if (this.g) { a.ah(b, c, d, e); } else { a.ag(b, c, d, e); } }; DescriptionSerializer.prototype.b = function (a, b, c) { if (c === void 0) { c = 8; } if (!b.g("type") || b.item("type").value == "EmbeddedRef") { if (b.g("refType")) { var d = new EmbeddedRefDescription(); d.refType = b.item("refType").value; if (b.g("id")) { d.value = b.item("id").value; } else { d.value = b.item("value").value; } var e = new DescriptionResult(); e.result = d; return e; } else { throw new NotSupportedException(1, "expected type to be defined for the json object"); } } var f = new DescriptionResult(); var g = b.item("type").value; var h = a.w(g); f.result = h; if (h == null) { if (this.i) { throw new NotSupportedException(1, "missing description for type: " + g); } f.d("couldn't find registered description for type: " + g); return f; } var i = b.e(); for (var j = 0; j < i.length; j++) { var k = i[j]; var l = a.getMetadata(g, TypeDescriptionContext.ac(k)); if (l == null) { if (TypeDescriptionContext.ac(k) == "Name") { var m = "string"; var n = b.item(k); var o = this.l(f, a, n, m); h.name = o; } continue; } var p = b.item(k); if (l.knownType == 14 || l.knownType == 11 || l.knownType == 12 || l.knownType == 26 || l.knownType == 27 || l.knownType == 25) { var q = p; switch (l.knownType) { case 26: case 14: q = DescriptionSerializer.n(a, p); break; case 27: case 12: q = DescriptionSerializer.o(a, p); break; case 25: case 11: q = DescriptionSerializer.m(a, p); break; } if (!this.e) { this.aa(a, h, k, l, q); } } else if (typeCast(JsonDictionaryObject.$, p) !== null) { var r = p; var s = this.b(a, r, l.knownType); f.e(s); this.aa(a, h, k, l, s.result); } else if (typeCast(JsonDictionaryArray.$, p) !== null) { var t = p; var u = "string"; var v = false; if (l.knownType == 10) { u = l.specificExternalType; } if (l.knownType == 9) { v = true; u = l.collectionElementType; } if (l.knownType == 23) { v = true; u = l.specificExternalType; } var w = this.a(f, a, t, u); if (this.f) { if (l.propertyName.toLowerCase() == "includedproperties" || l.propertyName.toLowerCase() == "excludedproperties" || l.propertyName.toLowerCase() == "includedcolumns" || l.propertyName.toLowerCase() == "excludedcolumns") { var x = w; var y = new Array(x.length); for (var z = 0; z < x.length; z++) { y[z] = this.p(x[z]); } w = y; } } if (!this.e || v) { this.aa(a, h, k, l, w); } } else { var aa = l.specificExternalType; if (aa == null && l.knownType == 3) { aa = "DateTime"; } if (aa == null && l.knownType == 21) { aa = "Timespan"; } if (aa == null) { aa = "String"; } var ab = p; var ac = this.l(f, a, ab, aa); if (this.f) { if (stringEndsWith(l.propertyName, "MemberPath") || stringEndsWith(l.propertyName.toLowerCase(), "field") || l.propertyName.toLowerCase() == "member" || l.propertyName.toLowerCase() == "membername" || (g != null && stringEndsWith(g, "Axis") && l.propertyName.toLowerCase() == "label")) { ac = this.p(ac); } } if (!this.e) { this.aa(a, h, k, l, ac); } } } return f; }; DescriptionSerializer.prototype.p = function (a) { if (a == null) { return null; } var b = a.toString(); if (this.k != null) { a = this.k(b); } else { if (stringStartsWith(b, "{")) { if (!stringStartsWith(b, "{[")) { b = b.substr(1, b.length - 2); b = "{[" + b + "]}"; a = b; } } else { if (!stringStartsWith(b, "[")) { b = "[" + b + "]"; a = b; } } } return a; }; DescriptionSerializer.j = function (a) { if (a == null) { return NaN; } if (typeof a === 'string') { var b = a; if (b == "@dbl:INFINITY") { return Number.POSITIVE_INFINITY; } if (b == "@dbl:-INFINITY") { return Number.NEGATIVE_INFINITY; } if (b == "Infinity") { return Number.POSITIVE_INFINITY; } if (b == "-Infinity") { return Number.NEGATIVE_INFINITY; } } return a; }; DescriptionSerializer.m = function (a, b) { if (b == null) { return null; } var c = NaN; var d = NaN; if (b.g("x")) { c = DescriptionSerializer.j(b.item("x").value); } if (b.g("y")) { d = DescriptionSerializer.j(b.item("y").value); } return ((function () { var $ret = new PointDescription(); $ret.x = c; $ret.y = d; return $ret; })()); }; DescriptionSerializer.o = function (a, b) { if (b == null) { return null; } var c = NaN; var d = NaN; if (b.g("width")) { c = DescriptionSerializer.j(b.item("width").value); } if (b.g("height")) { d = DescriptionSerializer.j(b.item("height").value); } return ((function () { var $ret = new SizeDescription(); $ret.width = c; $ret.height = d; return $ret; })()); }; DescriptionSerializer.n = function (a, b) { if (b == null) { return null; } var c = NaN; var d = NaN; var e = NaN; var f = NaN; if (b.g("left")) { c = DescriptionSerializer.j(b.item("left").value); } if (b.g("top")) { d = DescriptionSerializer.j(b.item("top").value); } if (b.g("width")) { e = DescriptionSerializer.j(b.item("width").value); } if (b.g("height")) { f = DescriptionSerializer.j(b.item("height").value); } return ((function () { var $ret = new RectDescription(); $ret.left = c; $ret.top = d; $ret.width = e; $ret.height = f; return $ret; })()); }; DescriptionSerializer.prototype.a = function (a, b, c, d) { var e = new Array(c.items.length); for (var f = 0; f < c.items.length; f++) { var g = c.items[f]; if (typeCast(JsonDictionaryObject.$, g) !== null) { var h = g; var i = this.b(b, h); a.e(i); e[f] = i.result; } else if (typeCast(JsonDictionaryArray.$, g) !== null) { var j = g; var k = this.a(a, b, j, d); e[f] = k; } else { var l = g; var m = this.l(a, b, l, d); e[f] = m; } } return e; }; DescriptionSerializer.prototype.l = function (a, b, c, d) { switch (c.e) { case 1: return c.value; case 3: switch (d.toLowerCase()) { case "float": return NaN; case "double": return NaN; } return c.value; case 0: switch (d.toLowerCase()) { case "int": return truncate(c.value); case "double": if (c.value == null) { return NaN; } else if (typeof c.value === 'string' && (c.value == "Infinity" || c.value == "INFINITY")) { return Number.POSITIVE_INFINITY; } else if (typeof c.value === 'string' && (c.value == "-Infinity" || c.value == "-INFINITY")) { return Number.NEGATIVE_INFINITY; } return c.value; case "timespan": return truncate(c.value); case "short": return truncate(c.value); case "long": return truncate(c.value); case "float": if (c.value == null) { return NaN; } return c.value; case "byte": return truncate(c.value); default: a.d("unexpected target type for number: " + d); return c.value; } case 2: if (d.toLowerCase() == "datetime") { var val_ = c.value; var e = (new Date(val_)); return e; } return c.value; default: a.d("unexpected value type"); return c.value; } }; DescriptionSerializer.prototype.s = function (a, b, c) { if (b == null) { c.e("null"); return; } var d = false; c.f("{"); c.i(); c.e("\"type\": \"" + b.i + "\""); var e = b.f(); for (var f = 0; f < e.count; f++) { var g = e._inner[f]; if (g.c.toLowerCase() == "type") { continue; } if (f >= 0) { c.f(","); } this.t(a, b, g, c); d = true; } if (d) { c.f(""); } c.h(); c.f("}"); }; DescriptionSerializer.prototype.q = function (a) { if (a == null) { return null; } return a.substr(0, 1).toLowerCase() + a.substr(1); }; DescriptionSerializer.prototype.t = function (a, b, c, d) { if (c.c.toLowerCase() == "type") { return; } d.e("\"" + this.q(c.c) + "\": "); this.z(a, b, c, c.b, d); }; DescriptionSerializer.prototype.w = function (a, b, c) { c.e("{"); c.e("\"width\":"); this.v(a, "Double", b.width, c); c.e(",\"height\":"); this.v(a, "Double", b.height, c); c.e(",\"left\":"); this.v(a, "Double", b.left, c); c.e(",\"top\":"); this.v(a, "Double", b.top, c); c.e("}"); }; DescriptionSerializer.prototype.u = function (a, b, c) { c.e("{"); c.e("\"x\":"); this.v(a, "Double", b.x, c); c.e(",\"y\":"); this.v(a, "Double", b.y, c); c.e("}"); }; DescriptionSerializer.prototype.x = function (a, b, c) { c.e("{"); c.e("\"width\":"); this.v(a, "Double", b.width, c); c.e(",\"height\":"); this.v(a, "Double", b.height, c); c.e("}"); }; DescriptionSerializer.prototype.z = function (a, b, c, d, e) { var f = 2; if (c.a != null) { f = c.a.knownType; } switch (f) { case 6: case 16: case 23: case 10: { e.e("["); var g = c.b; var h = c.a.specificType; if (c.a.knownType == 6 || c.a.knownType == 16) { h = "String"; } if (h == null) { h = c.a.specificExternalType; } for (var i = 0; i < g.length; i++) { if (i > 0) { e.e(", "); } var j = h; if (typeCast(DescriptionTreeNode.$, g[i]) !== null) { this.s(a, g[i], e); } else { this.v(a, h, g[i], e); } } e.e("]"); } break; case 7: this.v(a, "Boolean", d, e); break; case 9: { e.e("["); var k = c.b; var l = c.a.collectionElementType; for (var m = 0; m < k.length; m++) { if (m > 0) { e.e(", "); } var n = l; if (typeCast(DescriptionTreeNode.$, k[m]) !== null) { this.s(a, k[m], e); } else { this.v(a, l, k[m], e); } } e.e("]"); } break; case 4: case 18: case 19: case 20: case 22: case 5: case 2: this.v(a, "String", d, e); break; case 3: this.v(a, "DateTime", d, e); break; case 8: if (c.a.specificExternalType.toLowerCase() == "string") { this.v(a, "String", d, e); } else { this.s(a, d, e); } break; case 24: case 1: this.v(a, "Double", d, e); break; case 26: case 14: this.w(a, d, e); break; case 27: case 12: this.x(a, d, e); break; case 25: case 11: this.u(a, d, e); break; case 21: this.v(a, "TimeSpan", d, e); break; case 17: if (d == null) { this.v(a, "String", d, e); } else if (typeof d === 'string') { this.v(a, "String", d, e); } else if (typeof d === 'number' || typeof d === 'number' || typeof d === 'number') { this.v(a, "Number", d, e); } else if (typeCast(Date_$type, d) !== null) { this.v(a, "DateTime", d, e); } else if (typeCast(Boolean_$type, d) !== null) { this.v(a, "Boolean", d, e); } else if (typeCast(DescriptionTreeNode.$, d) !== null) { this.s(a, d, e); } else { throw new NotImplementedException(0); } break; case 0: case 15: case 13: throw new NotImplementedException(0); } }; DescriptionSerializer.prototype.v = function (a, b, c, d) { switch (b.toLowerCase()) { case "string": if (c == null) { d.e("null"); } else { d.e("\"" + stringReplace(c, "\"", "\\\"") + "\""); } break; case "number": case "double": if (c == null) { d.e("null"); } else { if (!(typeof c === 'number')) { c = Convert.toDouble3(c); } if (isNaN_(c)) { d.e("null"); } else if (isPositiveInfinity(c)) { d.e("\"Infinity\""); } else if (isNegativeInfinity(c)) { d.e("\"-Infinity\""); } else { d.e(c.toString()); } } break; case "int": if (c == null) { d.e("null"); } else { d.e(c.toString()); } break; case "float": if (c == null) { d.e("null"); } else { if (typeof c === 'number' && isNaN_(c)) { d.e("null"); } else { d.e(c.toString()); } } break; case "long": if (c == null) { d.e("null"); } else { d.e(c.toString()); } break; case "decimal": if (c == null) { d.e("null"); } else { d.e(c.toString()); } break; case "timespan": if (c == null) { d.e("null"); } else { d.e(c.toString()); } break; case "boolean": d.e(c == null ? "false" : c.toString().toLowerCase()); break; case "datetime": if (c == null) { d.e("null"); } else { var v_ = c; d.e("\"" + (v_.toJSON()) + "\""); } break; } }; DescriptionSerializer.$t = markType(DescriptionSerializer, 'DescriptionSerializer'); return DescriptionSerializer; }(Base)); export { DescriptionSerializer };