UNPKG

igniteui-angular-core

Version:

Ignite UI Angular Core logic used in multiple UI components.

636 lines (635 loc) 21.5 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 { DescriptionTreeNode } from "./DescriptionTreeNode"; import { DescriptionSerializerBuilder } from "./DescriptionSerializerBuilder"; import { DescriptionTreeBuilder } from "./DescriptionTreeBuilder"; 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_ } 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.h = false; _this.g = false; _this.f = false; _this.i = null; _this.e = false; return _this; } DescriptionSerializer.prototype.p = function (a, b) { var c = DescriptionTreeBuilder.createTree(a, b); var d = new DescriptionSerializerBuilder(); this.q(a, c, d); return d.toString(); }; DescriptionSerializer.prototype.w = function (a, b, c) { this.q(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.i = d; } if (e) { this.e = true; } var g = this.b(a, f); this.f = false; this.i = null; this.e = false; return g; }; DescriptionSerializer.prototype.y = function (a, b, c, d, e) { if (this.g) { a.ag(b, c, d, e); } else { a.af(b, c, d, e); } }; DescriptionSerializer.prototype.b = function (a, b, c) { if (c === void 0) { c = 8; } if (!b.g("type")) { if (b.g("refType")) { var d = new EmbeddedRefDescription(); d.refType = b.item("refType").value; d.value = b.item("id").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.h) { 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.ab(k)); if (l == null) { if (TypeDescriptionContext.ab(k) == "Name") { var m = "string"; var n = b.item(k); var o = this.j(f, a, n, m); h.name = o; } continue; } var p = b.item(k); if (l.knownType == 14 || l.knownType == 11 || l.knownType == 12) { var q = p; switch (l.knownType) { case 14: q = DescriptionSerializer.l(a, p); break; case 12: q = DescriptionSerializer.m(a, p); break; case 11: q = DescriptionSerializer.k(a, p); break; } if (!this.e) { this.y(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.y(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") { var x = w; var y = new Array(x.length); for (var z = 0; z < x.length; z++) { y[z] = this.n(x[z]); } w = y; } } if (!this.e || v) { this.y(a, h, k, l, w); } } else { var aa = l.specificExternalType; if (aa == null && l.knownType == 3) { aa = "DateTime"; } if (aa == null) { aa = "String"; } var ab = p; var ac = this.j(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.n(ac); } } if (!this.e) { this.y(a, h, k, l, ac); } } } return f; }; DescriptionSerializer.prototype.n = function (a) { if (a == null) { return null; } var b = a.toString(); if (this.i != null) { a = this.i(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.k = function (a, b) { if (b == null) { return null; } var c = NaN; var d = NaN; if (b.g("x")) { c = b.item("x").value; } if (b.g("y")) { d = b.item("y").value; } return ((function () { var $ret = new PointDescription(); $ret.x = c; $ret.y = d; return $ret; })()); }; DescriptionSerializer.m = function (a, b) { if (b == null) { return null; } var c = NaN; var d = NaN; if (b.g("width")) { c = b.item("width").value; } if (b.g("height")) { d = b.item("height").value; } return ((function () { var $ret = new SizeDescription(); $ret.width = c; $ret.height = d; return $ret; })()); }; DescriptionSerializer.l = 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 = b.item("left").value; } if (b.g("top")) { d = b.item("top").value; } if (b.g("width")) { e = b.item("width").value; } if (b.g("height")) { f = 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.j(a, b, l, d); e[f] = m; } } return e; }; DescriptionSerializer.prototype.j = 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; } return c.value; case "timespan": return 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.q = 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.r(a, b, g, c); d = true; } if (d) { c.f(""); } c.h(); c.f("}"); }; DescriptionSerializer.prototype.o = function (a) { if (a == null) { return null; } return a.substr(0, 1).toLowerCase() + a.substr(1); }; DescriptionSerializer.prototype.r = function (a, b, c, d) { if (c.c.toLowerCase() == "type") { return; } d.e("\"" + this.o(c.c) + "\": "); this.x(a, b, c, c.b, d); }; DescriptionSerializer.prototype.u = function (a, b, c) { c.e("{"); c.e("\"width\":"); this.t(a, "Double", b.width, c); c.e(",\"height\":"); this.t(a, "Double", b.height, c); c.e(",\"left\":"); this.t(a, "Double", b.left, c); c.e(",\"top\":"); this.t(a, "Double", b.top, c); c.e("}"); }; DescriptionSerializer.prototype.s = function (a, b, c) { c.e("{"); c.e("\"x\":"); this.t(a, "Double", b.x, c); c.e(",\"y\":"); this.t(a, "Double", b.y, c); c.e("}"); }; DescriptionSerializer.prototype.v = function (a, b, c) { c.e("{"); c.e("\"width\":"); this.t(a, "Double", b.width, c); c.e(",\"height\":"); this.t(a, "Double", b.height, c); c.e("}"); }; DescriptionSerializer.prototype.x = 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.q(a, g[i], e); } else { this.t(a, h, g[i], e); } } e.e("]"); } break; case 7: this.t(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.q(a, k[m], e); } else { this.t(a, l, k[m], e); } } e.e("]"); } break; case 4: case 18: case 19: case 20: case 22: case 5: case 2: this.t(a, "String", d, e); break; case 3: this.t(a, "DateTime", d, e); break; case 8: if (c.a.specificExternalType.toLowerCase() == "string") { this.t(a, "String", d, e); } else { this.q(a, d, e); } break; case 1: this.t(a, "Double", d, e); break; case 14: this.u(a, d, e); break; case 12: this.v(a, d, e); break; case 11: this.s(a, d, e); break; case 21: this.t(a, "TimeSpan", d, e); break; case 17: if (d == null) { this.t(a, "String", d, e); } else if (typeof d === 'string') { this.t(a, "String", d, e); } else if (typeof d === 'number' || typeof d === 'number' || typeof d === 'number') { this.t(a, "Number", d, e); } else if (typeCast(Date_$type, d) !== null) { this.t(a, "DateTime", d, e); } else if (typeCast(Boolean_$type, d) !== null) { this.t(a, "Boolean", d, e); } else { throw new NotImplementedException(0); } break; case 0: case 15: case 13: throw new NotImplementedException(0); } }; DescriptionSerializer.prototype.t = 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 { 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 };