Comparing version 1.5.1 to 1.5.2
@@ -0,1 +1,4 @@ | ||
# 1.5.2 | ||
* Fixed potential memory leak, fixes #95 through #100 by @svennergr | ||
# 1.5.1 | ||
@@ -2,0 +5,0 @@ * Fixed make beforeDeserialize, afterDeserialize optional, see #94 by zeevl |
@@ -489,3 +489,3 @@ /** | ||
var rootContextCache = new Map(); | ||
var rootContextCache = new WeakMap(); | ||
@@ -492,0 +492,0 @@ function Context(parentContext, modelSchema, json, onReadyCb, customArgs) { |
@@ -496,3 +496,3 @@ /** serializr - (c) Michel Weststrate 2016 - MIT Licensed */ | ||
var rootContextCache = new Map(); | ||
var rootContextCache = new WeakMap(); | ||
@@ -499,0 +499,0 @@ function Context(parentContext, modelSchema, json, onReadyCb, customArgs) { |
/** serializr - (c) Michel Weststrate 2016 - MIT Licensed */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define("serializr",["exports"],t):t((e=e||self).serializr={})}(this,function(e){"use strict";var t={j:function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}};function n(e,n){if(!e){var r=Array.prototype.slice.call(arguments,2),i=[],o=0,a=n.replace(/%([a-zA-Z%])/g,function(e,n){if("%%"===e)return e;var a=t[n];if("function"==typeof a){var s=r[o++];return i.push(s),a(s)}return e});throw console&&i.length>0&&console.log.apply(console,i),new Error("[serializr] "+(a||"Illegal State"))}}function r(e){if(e)throw new Error(e)}function i(e,t,n){if(0!==e.length){var r=e.filter(function(){return!0}).length,i=[],o=!1;e.forEach(function(e,a){t(e,function(e,t,a){t?o||(o=!0,n(t)):(i[e]=a,0==--r&&n(null,i))}.bind(null,a),a)})}else n(null,[])}function o(e){return null===e||"object"!=typeof e&&"function"!=typeof e}function a(e){return e&&e.factory&&e.props}function s(e){return e&&e.serializer&&e.deserializer}function f(e){return"object"==typeof e&&!!e.jsonname}function u(e){return"object"==typeof e&&!0===e.identifier}function c(e,t){for(;e;){if(e===t)return!0;e=e["extends"]}return!1}function l(e){return e&&"function"==typeof e.keys&&"function"==typeof e.clear}function p(e,t){if(t){n(s(e),"expected a propSchema");["beforeDeserialize","afterDeserialize"].forEach(function(n){"function"==typeof t[n]&&(e[n]=t[n])})}return e}function d(e){return e?a(e)?e:a(e.serializeInfo)?e.serializeInfo:e.constructor&&e.constructor.serializeInfo?e.constructor.serializeInfo:void 0:null}function h(e,t){return n(a(t)),e.serializeInfo=t}function y(e,t,r){n(e!==Object,"one cannot simply put define a model schema for Object"),n("function"==typeof e,"expected constructor function");var i={targetClass:e,factory:r||function(){return new e},props:t};if(e.prototype.constructor!==Object){var o=d(e.prototype.constructor);o&&o.targetClass!==e&&(i["extends"]=o)}return h(e,i),i}function m(e){var t={serializer:function(e){return n(o(e),"this value is not primitive: "+e),e},deserializer:function(e,t){o(e)?t(null,e):t("[serializr] this value is not primitive: "+e)}};return t=p(t,e)}var g="undefined"!=typeof Symbol?Symbol("SKIP"):{SKIP:!0},v=m(),b=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm,z=/([^\s,]+)/g;function j(e,t,r,i){var o,a,f;if(n(arguments.length>=2,"too few arguments. Please use @serializable as property decorator"),r===undefined&&"function"==typeof t&&t.prototype&&i!==undefined&&"number"==typeof i){n(s(e),"Constructor params must use alias(name)"),n(e.jsonname,"Constructor params must use alias(name)");var u=(a=t.toString().replace(b,""),null===(f=a.slice(a.indexOf("(")+1,a.indexOf(")")).match(z))&&(f=[]),f);u.length>=i&&(r=u[i],e.paramNumber=i,i=undefined,t=t.prototype,o=function(e){for(var n=[],r=0;r<t.constructor.length;r++)Object.keys(e.modelSchema.props).forEach(function(t){var i=e.modelSchema.props[t];i.paramNumber===r&&(n[r]=e.json[i.jsonname])});return new(Function.prototype.bind.apply(t.constructor,[null].concat(n)))})}n("string"==typeof r,"incorrect usage of @serializable decorator");var c=d(t);return c&&t.constructor.hasOwnProperty("serializeInfo")||(c=y(t.constructor,{},o)),c&&c.targetClass!==t.constructor&&(c=y(t.constructor,{},o)),c.props[r]=e,!i||i.get||i.set||(i.writable=!0),i}function x(e,t){n(1===arguments.length||2===arguments.length,"serialize expects one or 2 arguments");var r=1===arguments.length?e:t,i=1===arguments.length?null:e;if(Array.isArray(r)){if(0===r.length)return[];i||(i=d(r[0]))}else i||(i=d(r));return n(!!i,"Failed to find default schema for "+e),Array.isArray(r)?r.map(function(e){return R(i,e)}):R(i,r)}function R(e,t){var r;return n(e&&"object"==typeof e,"Expected schema"),n(t&&"object"==typeof t,"Expected object"),r=e["extends"]?R(e["extends"],t):{},Object.keys(e.props).forEach(function(i){var a=e.props[i];if("*"===i)return n(!0===a,"prop schema '*' can only be used with 'true'"),void function(e,t,n){for(var r in t)if(t.hasOwnProperty(r)&&!(r in e.props)){var i=t[r];o(i)&&(n[r]=i)}}(e,t,r);if(!0===a&&(a=v),!1!==a){var s=a.serializer(t[i],i,t);s!==g&&(r[a.jsonname||i]=s)}}),r}var C=new Map;function w(e,t,n,i,o){this.parentContext=e,this.isRoot=!e,this.pendingCallbacks=0,this.pendingRefsCount=0,this.onReadyCb=i||r,this.json=n,this.target=null,this.hasError=!1,this.modelSchema=t,this.isRoot?(this.rootContext=this,this.args=o,this.pendingRefs={},this.resolvedRefs={}):(this.rootContext=e.rootContext,this.args=e.args)}function S(e,t){for(var n in e.props)if("object"==typeof e.props[n]&&e.props[n].jsonname===t)return!0;return!1}function k(e,t,i,o,a){if(null!==i&&i!==undefined&&"object"==typeof i){var s=new w(e,t,i,o,a),f=t.factory(s);n(!!f,"No object returned from factory"),s.setTarget(f);var u=s.createCallback(r);return A(s,t,i,f),u(),f}o(null,null)}function A(e,t,r,i){t["extends"]&&A(e,t["extends"],r,i),Object.keys(t.props).forEach(function(a){var s=t.props[a];if("*"===a)return n(!0===s,"prop schema '*' can only be used with 'true'"),void function(e,t,r){for(var i in r)if(!(i in e.props||S(e,i))){var a=r[i];n(o(a),"encountered non primitive value while deserializing '*' properties in property '"+i+"': "+a),t[i]=a}}(t,i,r);if(!0===s&&(s=v),!1!==s){var f=s.jsonname||a;E(function(t,n){t||n===undefined||function(t,n,o){t.deserializer(n,function a(s){return function(f,u){D(function(n,r){n&&r!==undefined&&"function"==typeof t.afterDeserialize?t.deserializer(r,a(s),e,i[o]):s(n,r)},f,u,n,r,o,e,t)}}(e.rootContext.createCallback(function(e){e!==g&&(i[o]=e)})),e,i[o])}(s,n,a)},r[f],r,f,e,s)}})}function E(e,t,n,r,i,o){o&&"function"==typeof o.beforeDeserialize?o.beforeDeserialize(e,t,n,r,i,o):e(null,t)}function D(e,t,n,r,i,o,a,s){s&&"function"==typeof s.afterDeserialize?s.afterDeserialize(e,t,n,r,i,o,a,s):e(t,n)}function O(e,t){n("object"==typeof e||"function"==typeof e,"No modelschema provided. If you are importing it from another file be aware of circular dependencies.");var r={serializer:function(t){return n(a(e=d(e)),"expected modelSchema, got "+e),null===t||t===undefined?t:x(e,t)},deserializer:function(r,i,o){n(a(e=d(e)),"expected modelSchema, got "+e),null!==r&&r!==undefined?k(o,e,r,i,t):i(null,r)}};return r=p(r,t)}function I(e,t,r){n(!!e,"No modelschema provided. If you are importing it from another file be aware of circular dependencies.");var i,o=!1;function s(){if(o=!0,n("string"!=typeof e||t&&"function"==typeof t,"if the reference target is specified by attribute name, a lookup function is required"),n(!t||"function"==typeof t,"second argument should be a lookup function or additional arguments object"),"string"==typeof e)i=e;else{var r=d(e);n(a(r),"expected model schema or string as first argument for 'ref', got "+r),t=t||function(e){return function(t,n,r){r.rootContext.await(e,t,n)}}(r),i=function(e){for(n(a(e));e;){for(var t in e.props)if("object"==typeof e.props[t]&&!0===e.props[t].identifier)return t;e=e["extends"]}return null}(r),n(!!i,"provided model schema doesn't define an identifier() property and cannot be used by 'ref'.")}}"object"==typeof t&&r===undefined&&(r=t,t=undefined);var f={serializer:function(e){return o||s(),e?e[i]:null},deserializer:function(e,n,r){o||s(),null===e||e===undefined?n(null,e):t(e,n,r)}};return f=p(f,r)}function N(e,t){n(s(e=e||v),"expected prop schema as first argument"),n(!f(e),"provided prop is aliased, please put aliases first");var r={serializer:function(t){return t===undefined?g:(n(t&&"length"in t&&"map"in t,"expected array (like) object"),t.map(e.serializer))},deserializer:function(t,n,r){Array.isArray(t)?i(t,function(n,i,o){function a(t,a){"function"==typeof e.afterDeserialize?D(s,t,a,n,o,r,e):i(t,a)}function s(t,n){t&&n!==undefined&&"function"==typeof e.afterDeserialize?e.deserializer(n,a,r):i(t,n)}E(function(t,n){t?i(t):e.deserializer(n,a,r)},n,t,o,r,e)},n):n("[serializr] expected JSON array")}};return r=p(r,t)}w.prototype.createCallback=function(e){return this.pendingCallbacks++,function(e){var t=!1;return function(){if(!t)return t=!0,e.apply(null,arguments);n(!1,"callback was invoked twice")}}(function(t,n){t?this.hasError||(this.hasError=!0,this.onReadyCb(t),C["delete"](this)):this.hasError||(e(n),--this.pendingCallbacks===this.pendingRefsCount&&(this.pendingRefsCount>0?(this.onReadyCb(new Error('Unresolvable references in json: "'+Object.keys(this.pendingRefs).filter(function(e){return this.pendingRefs[e].length>0},this).join('", "')+'"')),C["delete"](this)):(this.onReadyCb(null,this.target),C["delete"](this))))}.bind(this))},w.prototype.await=function(e,t,r){if(n(this.isRoot),t in this.resolvedRefs){var i=this.resolvedRefs[t].filter(function(t){return c(t.modelSchema,e)})[0];if(i)return void r(null,i.value)}this.pendingRefsCount++,this.pendingRefs[t]||(this.pendingRefs[t]=[]),this.pendingRefs[t].push({modelSchema:e,uuid:t,callback:r})},w.prototype.resolve=function(e,t,r){if(n(this.isRoot),this.resolvedRefs[t]||(this.resolvedRefs[t]=[]),this.resolvedRefs[t].push({modelSchema:e,value:r}),t in this.pendingRefs)for(var i=this.pendingRefs[t].length-1;i>=0;i--){var o=this.pendingRefs[t][i];c(e,o.modelSchema)&&(this.pendingRefs[t].splice(i,1),this.pendingRefsCount--,o.callback(null,r))}},w.prototype.setTarget=function(e){this.isRoot&&this.target&&C["delete"](this.target),this.target=e,C.set(this.target,this)},w.prototype.cancelAwaits=function(){n(this.isRoot);var e=this;Object.keys(this.pendingRefs).forEach(function(t){e.pendingRefs[t].forEach(function(n){e.pendingRefsCount--,n.callback(new Error("Reference resolution canceled for "+t))})}),this.pendingRefs={},this.pendingRefsCount=0},e.createSimpleSchema=function(e){return{factory:function(){return{}},props:e}},e.createModelSchema=y,e.getDefaultModelSchema=d,e.setDefaultModelSchema=h,e.serializable=function(e,t,r){if(1===arguments.length){var i=!0===e?v:e;return n(s(i),"@serializable expects prop schema"),j.bind(null,i)}return j(m(),e,t,r)},e.serialize=x,e.serializeAll=function(e){n(1===arguments.length&&"function"==typeof e,"@serializeAll can only be used as class decorator");var t=d(e);return t&&e.hasOwnProperty("serializeInfo")||h(e,t=y(e,{})),d(e).props["*"]=!0,e},e.cancelDeserialize=function(e){n("object"==typeof e&&e&&!Array.isArray(e),"cancelDeserialize needs an object");var t,r=(t=e,C.get(t));r&&r.cancelAwaits()},e.deserialize=function(e,t,o,s){if(n(arguments.length>=2,"deserialize expects at least 2 arguments"),n(a(e=d(e)),"first argument should be model schema"),Array.isArray(t)){var f=[];return i(t,function(t,n){var r=k(null,e,t,n,s);f.push(r)},o||r),f}return k(null,e,t,o,s)},e.update=function(e,t,i,o,s){2===arguments.length||"function"==typeof arguments[2]?(e=d(t=arguments[0]),i=arguments[1],o=arguments[2],s=arguments[3]):e=d(e),n(a(e),"update failed to determine schema"),n("object"==typeof t&&t&&!Array.isArray(t),"update needs an object");var f=new w(null,e,i,o,s);f.setTarget(t);var u=f.createCallback(r),c=A(f,e,i,t);return u(),c},e.primitive=m,e.identifier=function(e,t){var r,i;"function"==typeof e?(r=e,i=t):i=e,n(!i||"object"==typeof i,"Additional property arguments should be an object, register function should be omitted or a funtion");var o={identifier:!0,serializer:v.serializer,deserializer:function(e,t,n){v.deserializer(e,function(e,i){!function(e,t,n){n.rootContext.resolve(n.modelSchema,e,n.target)}(i,n.target,n),r&&r(i,n.target,n),t(e,i)})}};return o=p(o,i)},e.date=function(e){var t={serializer:function(e){return null===e||e===undefined?e:(n(e instanceof Date,"Expected Date object"),e.getTime())},deserializer:function(e,t){null!==e&&e!==undefined?t(null,new Date(e)):t(null,e)}};return t=p(t,e)},e.alias=function(e,t){return n(e&&"string"==typeof e,"expected prop name as first argument"),n(s(t=t&&!0!==t?t:v),"expected prop schema as second argument"),n(!f(t),"provided prop is already aliased"),{jsonname:e,serializer:t.serializer,deserializer:t.deserializer,identifier:u(t),beforeDeserialize:t.beforeDeserialize,afterDeserialize:t.afterDeserialize}},e.custom=function(e,t,r){n("function"==typeof e,"first argument should be function"),n("function"==typeof t,"second argument should be a function or promise");var i={serializer:e,deserializer:function(e,n,i,o){4===t.length?t(e,i,o,n,r):n(null,t(e,i,o,null,r))}};return i=p(i,r)},e.object=O,e.child=O,e.reference=I,e.ref=I,e.list=N,e.map=function(e,t){n(s(e=e||v),"expected prop schema as first argument"),n(!f(e),"provided prop is aliased, please put aliases first");var r={serializer:function(t){n(t&&"object"==typeof t,"expected object or Map");var r=l(t),i={};if(r)t.forEach(function(t,n){i[n]=e.serializer(t)});else for(var o in t)i[o]=e.serializer(t[o]);return i},deserializer:function(n,r,i,o){if(n&&"object"==typeof n){var a=Object.keys(n);N(e,t).deserializer(a.map(function(e){return n[e]}),function(e,t){if(e)r(e);else{var n,i=l(o);i?(o.clear(),n=o):n={};for(var s=0,f=a.length;s<f;s++)i?n.set(a[s],t[s]):n[a[s]]=t[s];r(null,n)}},i)}else r("[serializr] expected JSON object")}};return r=p(r,t)},e.mapAsArray=function(e,t,r){n(s(e=e||v),"expected prop schema as first argument"),n(!!t,"expected key property name as second argument");var i={serializer:function(t){n(t&&"object"==typeof t,"expected object or Map");var r=l(t),i=[];if(r)t.forEach(function(t){i.push(e.serializer(t))});else for(var o in t)i.push(e.serializer(t[o]));return i},deserializer:function(n,i,o,a){N(e,r).deserializer(n,function(e,r){if(e)i(e);else{var o,s=l(a);s?(a.clear(),o=a):o={};for(var f=0,u=n.length;f<u;f++)s?o.set(r[f][t],r[f]):o[r[f][t].toString()]=r[f];i(null,o)}},o)}};return i=p(i,r)},e.raw=function(e){var t={serializer:function(e){return e},deserializer:function(e,t){t(null,e)}};return t=p(t,e)},e.SKIP=g,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define("serializr",["exports"],t):t((e=e||self).serializr={})}(this,function(e){"use strict";var t={j:function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}};function n(e,n){if(!e){var r=Array.prototype.slice.call(arguments,2),i=[],o=0,a=n.replace(/%([a-zA-Z%])/g,function(e,n){if("%%"===e)return e;var a=t[n];if("function"==typeof a){var s=r[o++];return i.push(s),a(s)}return e});throw console&&i.length>0&&console.log.apply(console,i),new Error("[serializr] "+(a||"Illegal State"))}}function r(e){if(e)throw new Error(e)}function i(e,t,n){if(0!==e.length){var r=e.filter(function(){return!0}).length,i=[],o=!1;e.forEach(function(e,a){t(e,function(e,t,a){t?o||(o=!0,n(t)):(i[e]=a,0==--r&&n(null,i))}.bind(null,a),a)})}else n(null,[])}function o(e){return null===e||"object"!=typeof e&&"function"!=typeof e}function a(e){return e&&e.factory&&e.props}function s(e){return e&&e.serializer&&e.deserializer}function f(e){return"object"==typeof e&&!!e.jsonname}function u(e){return"object"==typeof e&&!0===e.identifier}function c(e,t){for(;e;){if(e===t)return!0;e=e["extends"]}return!1}function l(e){return e&&"function"==typeof e.keys&&"function"==typeof e.clear}function p(e,t){if(t){n(s(e),"expected a propSchema");["beforeDeserialize","afterDeserialize"].forEach(function(n){"function"==typeof t[n]&&(e[n]=t[n])})}return e}function d(e){return e?a(e)?e:a(e.serializeInfo)?e.serializeInfo:e.constructor&&e.constructor.serializeInfo?e.constructor.serializeInfo:void 0:null}function h(e,t){return n(a(t)),e.serializeInfo=t}function y(e,t,r){n(e!==Object,"one cannot simply put define a model schema for Object"),n("function"==typeof e,"expected constructor function");var i={targetClass:e,factory:r||function(){return new e},props:t};if(e.prototype.constructor!==Object){var o=d(e.prototype.constructor);o&&o.targetClass!==e&&(i["extends"]=o)}return h(e,i),i}function m(e){var t={serializer:function(e){return n(o(e),"this value is not primitive: "+e),e},deserializer:function(e,t){o(e)?t(null,e):t("[serializr] this value is not primitive: "+e)}};return t=p(t,e)}var g="undefined"!=typeof Symbol?Symbol("SKIP"):{SKIP:!0},v=m(),b=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm,z=/([^\s,]+)/g;function j(e,t,r,i){var o,a,f;if(n(arguments.length>=2,"too few arguments. Please use @serializable as property decorator"),r===undefined&&"function"==typeof t&&t.prototype&&i!==undefined&&"number"==typeof i){n(s(e),"Constructor params must use alias(name)"),n(e.jsonname,"Constructor params must use alias(name)");var u=(a=t.toString().replace(b,""),null===(f=a.slice(a.indexOf("(")+1,a.indexOf(")")).match(z))&&(f=[]),f);u.length>=i&&(r=u[i],e.paramNumber=i,i=undefined,t=t.prototype,o=function(e){for(var n=[],r=0;r<t.constructor.length;r++)Object.keys(e.modelSchema.props).forEach(function(t){var i=e.modelSchema.props[t];i.paramNumber===r&&(n[r]=e.json[i.jsonname])});return new(Function.prototype.bind.apply(t.constructor,[null].concat(n)))})}n("string"==typeof r,"incorrect usage of @serializable decorator");var c=d(t);return c&&t.constructor.hasOwnProperty("serializeInfo")||(c=y(t.constructor,{},o)),c&&c.targetClass!==t.constructor&&(c=y(t.constructor,{},o)),c.props[r]=e,!i||i.get||i.set||(i.writable=!0),i}function x(e,t){n(1===arguments.length||2===arguments.length,"serialize expects one or 2 arguments");var r=1===arguments.length?e:t,i=1===arguments.length?null:e;if(Array.isArray(r)){if(0===r.length)return[];i||(i=d(r[0]))}else i||(i=d(r));return n(!!i,"Failed to find default schema for "+e),Array.isArray(r)?r.map(function(e){return R(i,e)}):R(i,r)}function R(e,t){var r;return n(e&&"object"==typeof e,"Expected schema"),n(t&&"object"==typeof t,"Expected object"),r=e["extends"]?R(e["extends"],t):{},Object.keys(e.props).forEach(function(i){var a=e.props[i];if("*"===i)return n(!0===a,"prop schema '*' can only be used with 'true'"),void function(e,t,n){for(var r in t)if(t.hasOwnProperty(r)&&!(r in e.props)){var i=t[r];o(i)&&(n[r]=i)}}(e,t,r);if(!0===a&&(a=v),!1!==a){var s=a.serializer(t[i],i,t);s!==g&&(r[a.jsonname||i]=s)}}),r}var C=new WeakMap;function w(e,t,n,i,o){this.parentContext=e,this.isRoot=!e,this.pendingCallbacks=0,this.pendingRefsCount=0,this.onReadyCb=i||r,this.json=n,this.target=null,this.hasError=!1,this.modelSchema=t,this.isRoot?(this.rootContext=this,this.args=o,this.pendingRefs={},this.resolvedRefs={}):(this.rootContext=e.rootContext,this.args=e.args)}function S(e,t){for(var n in e.props)if("object"==typeof e.props[n]&&e.props[n].jsonname===t)return!0;return!1}function k(e,t,i,o,a){if(null!==i&&i!==undefined&&"object"==typeof i){var s=new w(e,t,i,o,a),f=t.factory(s);n(!!f,"No object returned from factory"),s.setTarget(f);var u=s.createCallback(r);return A(s,t,i,f),u(),f}o(null,null)}function A(e,t,r,i){t["extends"]&&A(e,t["extends"],r,i),Object.keys(t.props).forEach(function(a){var s=t.props[a];if("*"===a)return n(!0===s,"prop schema '*' can only be used with 'true'"),void function(e,t,r){for(var i in r)if(!(i in e.props||S(e,i))){var a=r[i];n(o(a),"encountered non primitive value while deserializing '*' properties in property '"+i+"': "+a),t[i]=a}}(t,i,r);if(!0===s&&(s=v),!1!==s){var f=s.jsonname||a;E(function(t,n){t||n===undefined||function(t,n,o){t.deserializer(n,function a(s){return function(f,u){D(function(n,r){n&&r!==undefined&&"function"==typeof t.afterDeserialize?t.deserializer(r,a(s),e,i[o]):s(n,r)},f,u,n,r,o,e,t)}}(e.rootContext.createCallback(function(e){e!==g&&(i[o]=e)})),e,i[o])}(s,n,a)},r[f],r,f,e,s)}})}function E(e,t,n,r,i,o){o&&"function"==typeof o.beforeDeserialize?o.beforeDeserialize(e,t,n,r,i,o):e(null,t)}function D(e,t,n,r,i,o,a,s){s&&"function"==typeof s.afterDeserialize?s.afterDeserialize(e,t,n,r,i,o,a,s):e(t,n)}function O(e,t){n("object"==typeof e||"function"==typeof e,"No modelschema provided. If you are importing it from another file be aware of circular dependencies.");var r={serializer:function(t){return n(a(e=d(e)),"expected modelSchema, got "+e),null===t||t===undefined?t:x(e,t)},deserializer:function(r,i,o){n(a(e=d(e)),"expected modelSchema, got "+e),null!==r&&r!==undefined?k(o,e,r,i,t):i(null,r)}};return r=p(r,t)}function I(e,t,r){n(!!e,"No modelschema provided. If you are importing it from another file be aware of circular dependencies.");var i,o=!1;function s(){if(o=!0,n("string"!=typeof e||t&&"function"==typeof t,"if the reference target is specified by attribute name, a lookup function is required"),n(!t||"function"==typeof t,"second argument should be a lookup function or additional arguments object"),"string"==typeof e)i=e;else{var r=d(e);n(a(r),"expected model schema or string as first argument for 'ref', got "+r),t=t||function(e){return function(t,n,r){r.rootContext.await(e,t,n)}}(r),i=function(e){for(n(a(e));e;){for(var t in e.props)if("object"==typeof e.props[t]&&!0===e.props[t].identifier)return t;e=e["extends"]}return null}(r),n(!!i,"provided model schema doesn't define an identifier() property and cannot be used by 'ref'.")}}"object"==typeof t&&r===undefined&&(r=t,t=undefined);var f={serializer:function(e){return o||s(),e?e[i]:null},deserializer:function(e,n,r){o||s(),null===e||e===undefined?n(null,e):t(e,n,r)}};return f=p(f,r)}function N(e,t){n(s(e=e||v),"expected prop schema as first argument"),n(!f(e),"provided prop is aliased, please put aliases first");var r={serializer:function(t){return t===undefined?g:(n(t&&"length"in t&&"map"in t,"expected array (like) object"),t.map(e.serializer))},deserializer:function(t,n,r){Array.isArray(t)?i(t,function(n,i,o){function a(t,a){"function"==typeof e.afterDeserialize?D(s,t,a,n,o,r,e):i(t,a)}function s(t,n){t&&n!==undefined&&"function"==typeof e.afterDeserialize?e.deserializer(n,a,r):i(t,n)}E(function(t,n){t?i(t):e.deserializer(n,a,r)},n,t,o,r,e)},n):n("[serializr] expected JSON array")}};return r=p(r,t)}w.prototype.createCallback=function(e){return this.pendingCallbacks++,function(e){var t=!1;return function(){if(!t)return t=!0,e.apply(null,arguments);n(!1,"callback was invoked twice")}}(function(t,n){t?this.hasError||(this.hasError=!0,this.onReadyCb(t),C["delete"](this)):this.hasError||(e(n),--this.pendingCallbacks===this.pendingRefsCount&&(this.pendingRefsCount>0?(this.onReadyCb(new Error('Unresolvable references in json: "'+Object.keys(this.pendingRefs).filter(function(e){return this.pendingRefs[e].length>0},this).join('", "')+'"')),C["delete"](this)):(this.onReadyCb(null,this.target),C["delete"](this))))}.bind(this))},w.prototype.await=function(e,t,r){if(n(this.isRoot),t in this.resolvedRefs){var i=this.resolvedRefs[t].filter(function(t){return c(t.modelSchema,e)})[0];if(i)return void r(null,i.value)}this.pendingRefsCount++,this.pendingRefs[t]||(this.pendingRefs[t]=[]),this.pendingRefs[t].push({modelSchema:e,uuid:t,callback:r})},w.prototype.resolve=function(e,t,r){if(n(this.isRoot),this.resolvedRefs[t]||(this.resolvedRefs[t]=[]),this.resolvedRefs[t].push({modelSchema:e,value:r}),t in this.pendingRefs)for(var i=this.pendingRefs[t].length-1;i>=0;i--){var o=this.pendingRefs[t][i];c(e,o.modelSchema)&&(this.pendingRefs[t].splice(i,1),this.pendingRefsCount--,o.callback(null,r))}},w.prototype.setTarget=function(e){this.isRoot&&this.target&&C["delete"](this.target),this.target=e,C.set(this.target,this)},w.prototype.cancelAwaits=function(){n(this.isRoot);var e=this;Object.keys(this.pendingRefs).forEach(function(t){e.pendingRefs[t].forEach(function(n){e.pendingRefsCount--,n.callback(new Error("Reference resolution canceled for "+t))})}),this.pendingRefs={},this.pendingRefsCount=0},e.createSimpleSchema=function(e){return{factory:function(){return{}},props:e}},e.createModelSchema=y,e.getDefaultModelSchema=d,e.setDefaultModelSchema=h,e.serializable=function(e,t,r){if(1===arguments.length){var i=!0===e?v:e;return n(s(i),"@serializable expects prop schema"),j.bind(null,i)}return j(m(),e,t,r)},e.serialize=x,e.serializeAll=function(e){n(1===arguments.length&&"function"==typeof e,"@serializeAll can only be used as class decorator");var t=d(e);return t&&e.hasOwnProperty("serializeInfo")||h(e,t=y(e,{})),d(e).props["*"]=!0,e},e.cancelDeserialize=function(e){n("object"==typeof e&&e&&!Array.isArray(e),"cancelDeserialize needs an object");var t,r=(t=e,C.get(t));r&&r.cancelAwaits()},e.deserialize=function(e,t,o,s){if(n(arguments.length>=2,"deserialize expects at least 2 arguments"),n(a(e=d(e)),"first argument should be model schema"),Array.isArray(t)){var f=[];return i(t,function(t,n){var r=k(null,e,t,n,s);f.push(r)},o||r),f}return k(null,e,t,o,s)},e.update=function(e,t,i,o,s){2===arguments.length||"function"==typeof arguments[2]?(e=d(t=arguments[0]),i=arguments[1],o=arguments[2],s=arguments[3]):e=d(e),n(a(e),"update failed to determine schema"),n("object"==typeof t&&t&&!Array.isArray(t),"update needs an object");var f=new w(null,e,i,o,s);f.setTarget(t);var u=f.createCallback(r),c=A(f,e,i,t);return u(),c},e.primitive=m,e.identifier=function(e,t){var r,i;"function"==typeof e?(r=e,i=t):i=e,n(!i||"object"==typeof i,"Additional property arguments should be an object, register function should be omitted or a funtion");var o={identifier:!0,serializer:v.serializer,deserializer:function(e,t,n){v.deserializer(e,function(e,i){!function(e,t,n){n.rootContext.resolve(n.modelSchema,e,n.target)}(i,n.target,n),r&&r(i,n.target,n),t(e,i)})}};return o=p(o,i)},e.date=function(e){var t={serializer:function(e){return null===e||e===undefined?e:(n(e instanceof Date,"Expected Date object"),e.getTime())},deserializer:function(e,t){null!==e&&e!==undefined?t(null,new Date(e)):t(null,e)}};return t=p(t,e)},e.alias=function(e,t){return n(e&&"string"==typeof e,"expected prop name as first argument"),n(s(t=t&&!0!==t?t:v),"expected prop schema as second argument"),n(!f(t),"provided prop is already aliased"),{jsonname:e,serializer:t.serializer,deserializer:t.deserializer,identifier:u(t),beforeDeserialize:t.beforeDeserialize,afterDeserialize:t.afterDeserialize}},e.custom=function(e,t,r){n("function"==typeof e,"first argument should be function"),n("function"==typeof t,"second argument should be a function or promise");var i={serializer:e,deserializer:function(e,n,i,o){4===t.length?t(e,i,o,n,r):n(null,t(e,i,o,null,r))}};return i=p(i,r)},e.object=O,e.child=O,e.reference=I,e.ref=I,e.list=N,e.map=function(e,t){n(s(e=e||v),"expected prop schema as first argument"),n(!f(e),"provided prop is aliased, please put aliases first");var r={serializer:function(t){n(t&&"object"==typeof t,"expected object or Map");var r=l(t),i={};if(r)t.forEach(function(t,n){i[n]=e.serializer(t)});else for(var o in t)i[o]=e.serializer(t[o]);return i},deserializer:function(n,r,i,o){if(n&&"object"==typeof n){var a=Object.keys(n);N(e,t).deserializer(a.map(function(e){return n[e]}),function(e,t){if(e)r(e);else{var n,i=l(o);i?(o.clear(),n=o):n={};for(var s=0,f=a.length;s<f;s++)i?n.set(a[s],t[s]):n[a[s]]=t[s];r(null,n)}},i)}else r("[serializr] expected JSON object")}};return r=p(r,t)},e.mapAsArray=function(e,t,r){n(s(e=e||v),"expected prop schema as first argument"),n(!!t,"expected key property name as second argument");var i={serializer:function(t){n(t&&"object"==typeof t,"expected object or Map");var r=l(t),i=[];if(r)t.forEach(function(t){i.push(e.serializer(t))});else for(var o in t)i.push(e.serializer(t[o]));return i},deserializer:function(n,i,o,a){N(e,r).deserializer(n,function(e,r){if(e)i(e);else{var o,s=l(a);s?(a.clear(),o=a):o={};for(var f=0,u=n.length;f<u;f++)s?o.set(r[f][t],r[f]):o[r[f][t].toString()]=r[f];i(null,o)}},o)}};return i=p(i,r)},e.raw=function(e){var t={serializer:function(e){return e},deserializer:function(e,t){t(null,e)}};return t=p(t,e)},e.SKIP=g,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=serializr.min.js.map |
{ | ||
"name": "serializr", | ||
"version": "1.5.1", | ||
"version": "1.5.2", | ||
"description": "Serialize and deserialize complex object graphs to JSON", | ||
@@ -59,2 +59,2 @@ "main": "lib/serializr.js", | ||
} | ||
} | ||
} |
@@ -414,3 +414,3 @@ # Serializr | ||
[src/serializr.js:52-52](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/serializr.js#L5-L51 "Source code on GitHub") | ||
[src/serializr.js:52-52](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/serializr.js#L5-L51 "Source code on GitHub") | ||
@@ -461,3 +461,3 @@ JSDOC type defintions for usage w/o typescript. | ||
[src/api/createSimpleSchema.js:17-24](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/api/createSimpleSchema.js#L17-L24 "Source code on GitHub") | ||
[src/api/createSimpleSchema.js:17-24](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/api/createSimpleSchema.js#L17-L24 "Source code on GitHub") | ||
@@ -487,3 +487,3 @@ Creates a model schema that (de)serializes from / to plain javascript objects. | ||
[src/api/createModelSchema.js:29-47](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/api/createModelSchema.js#L29-L47 "Source code on GitHub") | ||
[src/api/createModelSchema.js:29-47](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/api/createModelSchema.js#L29-L47 "Source code on GitHub") | ||
@@ -521,3 +521,3 @@ Creates a model schema that (de)serializes an object created by a constructor function (class). | ||
[src/api/getDefaultModelSchema.js:9-18](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/api/getDefaultModelSchema.js#L9-L18 "Source code on GitHub") | ||
[src/api/getDefaultModelSchema.js:9-18](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/api/getDefaultModelSchema.js#L9-L18 "Source code on GitHub") | ||
@@ -534,3 +534,3 @@ Returns the standard model schema associated with a class / constructor function | ||
[src/api/setDefaultModelSchema.js:15-18](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/api/setDefaultModelSchema.js#L15-L18 "Source code on GitHub") | ||
[src/api/setDefaultModelSchema.js:15-18](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/api/setDefaultModelSchema.js#L15-L18 "Source code on GitHub") | ||
@@ -553,3 +553,3 @@ Sets the default model schema for class / constructor function. | ||
[src/api/serializable.js:93-103](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/api/serializable.js#L93-L103 "Source code on GitHub") | ||
[src/api/serializable.js:93-103](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/api/serializable.js#L93-L103 "Source code on GitHub") | ||
@@ -578,3 +578,3 @@ Decorator that defines a new property mapping on the default model schema for the class | ||
[src/core/serialize.js:16-34](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/core/serialize.js#L16-L34 "Source code on GitHub") | ||
[src/core/serialize.js:16-34](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/core/serialize.js#L16-L34 "Source code on GitHub") | ||
@@ -594,3 +594,3 @@ Serializes an object (graph) into json using the provided model schema. | ||
[src/core/serialize.js:89-100](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/core/serialize.js#L89-L100 "Source code on GitHub") | ||
[src/core/serialize.js:89-100](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/core/serialize.js#L89-L100 "Source code on GitHub") | ||
@@ -605,3 +605,3 @@ The `serializeAll` decorator can be used on a class to signal that all primitive properties should be serialized automatically. | ||
[src/core/cancelDeserialize.js:12-18](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/core/cancelDeserialize.js#L12-L18 "Source code on GitHub") | ||
[src/core/cancelDeserialize.js:12-18](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/core/cancelDeserialize.js#L12-L18 "Source code on GitHub") | ||
@@ -616,3 +616,3 @@ Cancels an asynchronous deserialization or update operation for the specified target object. | ||
[src/core/deserialize.js:45-63](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/core/deserialize.js#L45-L63 "Source code on GitHub") | ||
[src/core/deserialize.js:45-63](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/core/deserialize.js#L45-L63 "Source code on GitHub") | ||
@@ -640,3 +640,3 @@ Deserializes a json structure into an object graph. | ||
[src/core/update.js:22-44](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/core/update.js#L22-L44 "Source code on GitHub") | ||
[src/core/update.js:22-44](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/core/update.js#L22-L44 "Source code on GitHub") | ||
@@ -659,3 +659,3 @@ Similar to deserialize, but updates an existing object instance. | ||
[src/types/primitive.js:18-32](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/types/primitive.js#L18-L32 "Source code on GitHub") | ||
[src/types/primitive.js:18-32](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/types/primitive.js#L18-L32 "Source code on GitHub") | ||
@@ -683,3 +683,3 @@ Indicates that this field contains a primitive value (or Date) which should be serialized literally to json. | ||
[src/types/identifier.js:43-66](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/types/identifier.js#L43-L66 "Source code on GitHub") | ||
[src/types/identifier.js:43-66](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/types/identifier.js#L43-L66 "Source code on GitHub") | ||
@@ -725,3 +725,3 @@ Similar to primitive, but this field will be marked as the identifier for the given Model type. | ||
[src/types/date.js:9-26](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/types/date.js#L9-L26 "Source code on GitHub") | ||
[src/types/date.js:9-26](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/types/date.js#L9-L26 "Source code on GitHub") | ||
@@ -738,3 +738,3 @@ Similar to primitive, serializes instances of Date objects | ||
[src/types/alias.js:20-33](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/types/alias.js#L20-L33 "Source code on GitHub") | ||
[src/types/alias.js:20-33](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/types/alias.js#L20-L33 "Source code on GitHub") | ||
@@ -764,3 +764,3 @@ Alias indicates that this model property should be named differently in the generated json. | ||
[src/types/custom.js:60-75](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/types/custom.js#L60-L75 "Source code on GitHub") | ||
[src/types/custom.js:60-75](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/types/custom.js#L60-L75 "Source code on GitHub") | ||
@@ -830,3 +830,3 @@ Can be used to create simple custom propSchema. Multiple things can be done inside of a custom propSchema, like deserializing and serializing other (polymorphic) objects, skipping the serialization of something or checking the context of the obj being (de)serialized. | ||
[src/types/object.js:35-55](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/types/object.js#L35-L55 "Source code on GitHub") | ||
[src/types/object.js:35-55](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/types/object.js#L35-L55 "Source code on GitHub") | ||
@@ -869,3 +869,3 @@ `object` indicates that this property contains an object that needs to be (de)serialized | ||
[src/types/reference.js:66-105](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/types/reference.js#L66-L105 "Source code on GitHub") | ||
[src/types/reference.js:66-105](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/types/reference.js#L66-L105 "Source code on GitHub") | ||
@@ -935,3 +935,3 @@ `reference` can be used to (de)serialize references that point to other models. | ||
[src/types/list.js:43-105](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/types/list.js#L43-L105 "Source code on GitHub") | ||
[src/types/list.js:43-105](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/types/list.js#L43-L105 "Source code on GitHub") | ||
@@ -975,3 +975,3 @@ List indicates that this property contains a list of things. | ||
[src/types/map.js:14-65](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/types/map.js#L14-L65 "Source code on GitHub") | ||
[src/types/map.js:14-65](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/types/map.js#L14-L65 "Source code on GitHub") | ||
@@ -991,3 +991,3 @@ Similar to list, but map represents a string keyed dynamic collection. | ||
[src/types/mapAsArray.js:19-66](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/types/mapAsArray.js#L19-L66 "Source code on GitHub") | ||
[src/types/mapAsArray.js:19-66](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/types/mapAsArray.js#L19-L66 "Source code on GitHub") | ||
@@ -1012,3 +1012,3 @@ Similar to map, mapAsArray can be used to serialize a map-like collection where the key is | ||
[src/types/raw.js:18-29](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/types/raw.js#L18-L29 "Source code on GitHub") | ||
[src/types/raw.js:18-29](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/types/raw.js#L18-L29 "Source code on GitHub") | ||
@@ -1037,3 +1037,3 @@ Indicates that this field is only need to putted in the serialized json or | ||
[src/constants.js:20-20](https://github.com/mobxjs/serializr/blob/9ab5501e7caee130bb2f67296bc9e259e4b64db8/src/constants.js#L20-L20 "Source code on GitHub") | ||
[src/constants.js:20-20](https://git@github.com/:mobxjs/serializr/blob/132a653e346444c53e17679fcef07f389da1d939/src/constants.js#L20-L20 "Source code on GitHub") | ||
@@ -1040,0 +1040,0 @@ In the event that a property needs to be deserialized, but not serialized, you can use the SKIP symbol to omit the property. This has to be used with the custom serializer. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
257139