diff --git a/js/typedjson.js b/js/typedjson.js index d8a4bc4..a576b7e 100644 --- a/js/typedjson.js +++ b/js/typedjson.js @@ -1,4 +1,4 @@ -// [typedjson] Version: 1.2.1 - 2018-12-09 +// [typedjson] Version: 1.2.3 - 2018-12-09 (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); diff --git a/js/typedjson.min.js b/js/typedjson.min.js index 3748500..7c1fc71 100644 --- a/js/typedjson.min.js +++ b/js/typedjson.min.js @@ -1,3 +1,3 @@ -// [typedjson] Version: 1.2.1 - 2018-12-09 +// [typedjson] Version: 1.2.3 - 2018-12-09 !function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define("typedjson",[],r):"object"==typeof exports?exports.typedjson=r():e.typedjson=r()}("undefined"!=typeof self?self:this,function(){return function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){"use strict";t.r(r);var n="__typedJsonJsonObjectMetadataInformation__";function o(e){return!!~[Date,Number,String,Boolean].indexOf(e)}function i(e){return!!~[Float32Array,Float64Array,Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array].indexOf(e)}function s(e,r){return"string"!=typeof e||function(e,r){var t=r===String||r===ArrayBuffer||r===DataView,n=e.length>=2&&'"'===e[0]&&'"'===e[e.length-1],o=/^\d+$/.test(e.trim());return t&&!n||!n&&!o&&r===Date}(e,r)?e:JSON.parse(e)}function a(e,r){return e===r||e.prototype instanceof r}function c(e){for(var r=[],t=1;t0)return new Date(e);this._throwTypeMismatchError("Date","an ISO-8601 string",o,t)}else if(n===Float32Array){if(e instanceof Array&&e.every(function(e){return!isNaN(e)}))return new Float32Array(e);this._throwTypeMismatchError("Float32Array","a numeric source array",o,t)}else if(n===Float64Array){if(e instanceof Array&&e.every(function(e){return!isNaN(e)}))return new Float64Array(e);this._throwTypeMismatchError("Float64Array","a numeric source array",o,t)}else if(n===Uint8Array){if(e instanceof Array&&e.every(function(e){return!isNaN(e)}))return new Uint8Array(e.map(function(e){return~~e}));this._throwTypeMismatchError("Uint8Array","a numeric source array",o,t)}else if(n===Uint8ClampedArray){if(e instanceof Array&&e.every(function(e){return!isNaN(e)}))return new Uint8ClampedArray(e.map(function(e){return~~e}));this._throwTypeMismatchError("Uint8ClampedArray","a numeric source array",o,t)}else if(n===Uint16Array){if(e instanceof Array&&e.every(function(e){return!isNaN(e)}))return new Uint16Array(e.map(function(e){return~~e}));this._throwTypeMismatchError("Uint16Array","a numeric source array",o,t)}else if(n===Uint32Array){if(e instanceof Array&&e.every(function(e){return!isNaN(e)}))return new Uint32Array(e.map(function(e){return~~e}));this._throwTypeMismatchError("Uint32Array","a numeric source array",o,t)}else if(n===ArrayBuffer){if("string"==typeof e)return this._stringToArrayBuffer(e);this._throwTypeMismatchError("ArrayBuffer","a string source",o,t)}else if(n===DataView){if("string"==typeof e)return this._stringToDataView(e);this._throwTypeMismatchError("DataView","a string source",o,t)}else{if(n===Array){if(e instanceof Array)return this.convertAsArray(e,r,t);throw new TypeError(this._makeTypeErrorMessage(Array,e.constructor,t))}if(n===Set){if(e instanceof Array)return this.convertAsSet(e,r,t);this._throwTypeMismatchError("Set","Array",o,t)}else if(n===Map){if(e instanceof Array)return this.convertAsMap(e,r,t);this._throwTypeMismatchError("Map","a source array of key-value-pair objects",o,t)}else if(e&&"object"==typeof e)return this.convertAsObject(e,r,t)}},e.prototype.convertAsArray=function(e,r,t){var n=this;if(void 0===t&&(t="object"),!(e instanceof Array))return this._errorHandler(new TypeError(this._makeTypeErrorMessage(Array,e.constructor,t))),[];if(!r.elementConstructor||!r.elementConstructor.length)return this._errorHandler(new TypeError("Could not deserialize "+t+" as Array: missing constructor reference of Array elements.")),[];var o={selfConstructor:r.elementConstructor[0],elementConstructor:r.elementConstructor.length>1?r.elementConstructor.slice(1):[],knownTypes:r.knownTypes};return e.map(function(e){try{return n.convertSingleValue(e,o)}catch(e){return void n._errorHandler(e)}})},e.prototype.convertAsSet=function(e,r,t){var n=this;if(void 0===t&&(t="object"),!(e instanceof Array))return this._errorHandler(new TypeError(this._makeTypeErrorMessage(Array,e.constructor,t))),new Set;if(!r.elementConstructor||!r.elementConstructor.length)return this._errorHandler(new TypeError("Could not deserialize "+t+" as Set: missing constructor reference of Set elements.")),new Set;var o={selfConstructor:r.elementConstructor[0],elementConstructor:r.elementConstructor.length>1?r.elementConstructor.slice(1):[],knownTypes:r.knownTypes},i=new Set;return e.forEach(function(e,r){try{i.add(n.convertSingleValue(e,o,t+"["+r+"]"))}catch(e){n._errorHandler(e)}}),i},e.prototype.convertAsMap=function(e,r,t){var n=this;if(void 0===t&&(t="object"),e instanceof Array||this._errorHandler(new TypeError(this._makeTypeErrorMessage(Array,e.constructor,t))),!r.keyConstructor)return this._errorHandler(new TypeError("Could not deserialize "+t+" as Map: missing key constructor.")),new Map;if(!r.elementConstructor||!r.elementConstructor.length)return this._errorHandler(new TypeError("Could not deserialize "+t+" as Map: missing value constructor.")),new Map;var o={selfConstructor:r.keyConstructor,knownTypes:r.knownTypes},i={selfConstructor:r.elementConstructor[0],elementConstructor:r.elementConstructor.length>1?r.elementConstructor.slice(1):[],knownTypes:r.knownTypes},s=new Map;return e.forEach(function(e){try{var r=n.convertSingleValue(e.key,o);l(r)&&s.set(r,n.convertSingleValue(e.value,i,t+"["+r+"]"))}catch(e){n._errorHandler(e)}}),s},e.prototype._throwTypeMismatchError=function(e,r,t,n){throw void 0===n&&(n="object"),new TypeError("Could not deserialize "+n+" as "+e+": expected "+r+", got "+t+".")},e.prototype._makeTypeErrorMessage=function(e,r,t){return void 0===t&&(t="object"),"Could not deserialize "+t+": expected '"+("function"==typeof e?p(e):e)+"', got '"+("function"==typeof r?p(r):r)+"'."},e.prototype._instantiateType=function(e){return new e},e.prototype._mergeKnownTypes=function(){for(var e=this,r=[],t=0;t1?r.slice(1):[]};return t&&(t+="[]"),e.map(function(e){return n.convertSingleValue(e,o,t)})},e.prototype.convertAsSet=function(e,r,t){var n=this;if(void 0===t&&(t="object"),!r)throw new TypeError("Could not serialize "+t+" as Set: missing element type definition.");var o={selfType:r};t&&(t+="[]");var i=[];return e.forEach(function(e){var r=n.convertSingleValue(e,o,t);l(e)&&!l(r)||i.push(r)}),i},e.prototype.convertAsMap=function(e,r,t,n){var o=this;if(void 0===n&&(n="object"),!t)throw new TypeError("Could not serialize "+n+" as Map: missing value type definition.");if(!r)throw new TypeError("Could not serialize "+n+" as Map: missing key type definition.");var i={selfType:t,elementTypes:[t]},s={selfType:r};n&&(n+="[]");var a=[];return e.forEach(function(e,r){var t={key:o.convertSingleValue(r,s,n),value:o.convertSingleValue(e,i,n)};l(t.key)&&l(t.value)&&a.push(t)}),a},e.prototype.convertAsTypedArray=function(e){return Array.from(e)},e.prototype.convertAsArrayBuffer=function(e){return Array.from(new Uint16Array(e)).map(function(e){return String.fromCharCode(e)}).join("")},e.prototype.convertAsDataView=function(e){return this.convertAsArrayBuffer(e.buffer)},e}();function g(e){var r;function t(e){var t;if(e.prototype.hasOwnProperty(n))(t=e.prototype[n]).classType=e;else{t=new d(e);var o=e.prototype[n];o&&(o.dataMembers.forEach(function(e,r){return t.dataMembers.set(r,e)}),o.knownTypes.forEach(function(e){return t.knownTypes.add(e)})),Object.defineProperty(e.prototype,n,{enumerable:!1,configurable:!1,writable:!1,value:t})}t.isExplicitlyMarked=!0,t.onDeserializedMethodName=r.onDeserialized,t.initializerCallback=r.initializer,r.name&&(t.name=r.name),"string"==typeof r.knownTypes?t.knownTypeMethodName=r.knownTypes:r.knownTypes instanceof Array&&r.knownTypes.filter(function(e){return!!e}).forEach(function(e){return t.knownTypes.add(e)})}if(r="function"==typeof e?{}:e||{},"function"!=typeof e)return t;t(e)}function T(e,r){if(!(e instanceof Object)||"string"!=typeof r&&"symbol"!=typeof r)return function(r,t){var n,o=e||{},i="@jsonMember on "+p(r.constructor)+"."+String(t);if(o.hasOwnProperty("constructor")){if(!l(o.constructor))return void c(i+": cannot resolve specified property constructor at runtime.");f&&!a(o.constructor,Reflect.getMetadata("design:type",r,t))&&u(i+": detected property type does not match 'constructor' option."),n=o.constructor}else if(f){if(!(n=Reflect.getMetadata("design:type",r,t)))return void c(i+": cannot resolve detected property constructor at runtime.")}else if(!o.deserializer)return void c(i+": ReflectDecorators is required if no 'constructor' option is specified.");A(i,n)||h(r,t,{ctor:n,emitDefaultValue:o.emitDefaultValue||!1,isRequired:o.isRequired||!1,key:t.toString(),name:o.name||t.toString(),deserializer:o.deserializer,serializer:o.serializer})};var t=e,n="@jsonMember on "+p(t.constructor)+"."+String(r);if(f){var o=Reflect.getMetadata("design:type",t,r);o?A(n,o)||h(t,r,{ctor:o,key:r.toString(),name:r.toString()}):c(n+": could not resolve detected property constructor at runtime.")}else c(n+": ReflectDecorators is required if no 'constructor' option is specified.")}function A(e,r){return r===Array?(c(e+": property is an Array. Use the jsonArrayMember decorator to serialize this property."),!0):r===Set?(c(e+": property is a Set. Use the jsonSetMember decorator to serialize this property."),!0):r===Map&&(c(e+": property is a Map. Use the jsonMapMember decorator to serialize this property."),!0)}function b(e,r){return void 0===r&&(r={}),function(t,n){var o="@jsonArrayMember on "+p(t.constructor)+"."+String(n);if("function"==typeof e){var i=void 0===r.dimensions?1:r.dimensions;!isNaN(i)&&i<1?c(o+": 'dimensions' option must be at least 1."):f&&Reflect.getMetadata("design:type",t,n)!==Array?c(o+": property is not an Array."):h(t,n,{ctor:Array,elementType:function(e,r){var t=new Array(r).fill(Array,0,-1);return t[r-1]=e,t}(e,i),emitDefaultValue:r.emitDefaultValue||!1,isRequired:r.isRequired||!1,key:n.toString(),name:r.name||n.toString(),deserializer:r.deserializer,serializer:r.serializer})}else c(o+": could not resolve constructor of array elements at runtime.")}}function M(e,r){return void 0===r&&(r={}),function(t,n){var o="@jsonSetMember on "+p(t.constructor)+"."+String(n);"function"==typeof e?f&&Reflect.getMetadata("design:type",t,n)!==Set?c(o+": property is not a Set."):h(t,n,{ctor:Set,elementType:[e],emitDefaultValue:r.emitDefaultValue||!1,isRequired:r.isRequired||!1,key:n.toString(),name:r.name||n.toString(),deserializer:r.deserializer,serializer:r.serializer}):c(o+": could not resolve constructor of set elements at runtime.")}}function C(e,r,t){return void 0===t&&(t={}),function(n,o){var i="@jsonMapMember on "+p(n.constructor)+"."+String(o);"function"==typeof e?"function"==typeof r?f&&Reflect.getMetadata("design:type",n,o)!==Map?c(i+": property is not a Map."):h(n,o,{ctor:Map,elementType:[r],keyType:e,emitDefaultValue:t.emitDefaultValue||!1,isRequired:t.isRequired||!1,key:o.toString(),name:t.name||o.toString(),deserializer:t.deserializer,serializer:t.serializer}):c(i+": could not resolve constructor of map values at runtime."):c(i+": could not resolve constructor of map keys at runtime.")}}t.d(r,"TypedJSON",function(){return E}),t.d(r,"jsonObject",function(){return g}),t.d(r,"jsonMember",function(){return T}),t.d(r,"jsonArrayMember",function(){return b}),t.d(r,"jsonSetMember",function(){return M}),t.d(r,"jsonMapMember",function(){return C});var k=Object.assign||function(e){for(var r,t=1,n=arguments.length;t