New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

serializr

Package Overview
Dependencies
Maintainers
5
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serializr - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

7

lib/es/serializr.js

@@ -1081,3 +1081,8 @@ /**

}
parallel(jsonArray, processItem, done);
parallel(jsonArray, processItem, function (err, result) {
if (err) {
return void done(err);
}
done(undefined, result.filter(function (x) { return SKIP !== x; }));
});
}

@@ -1084,0 +1089,0 @@ };

2

lib/es/serializr.min.js

@@ -16,3 +16,3 @@ /** serializr - (c) Michel Weststrate 2016 - MIT Licensed */

and limitations under the License.
***************************************************************************** */function m(){for(var e=0,n=0,t=arguments.length;n<t;n++)e+=arguments[n].length;var r=Array(e),i=0;for(n=0;n<t;n++)for(var o=arguments[n],u=0,f=o.length;u<f;u++,i++)r[i]=o[u];return r}function y(e){return d({serializer:function(e){return t(o(e),"this value is not primitive: "+e),e},deserializer:function(e,n){o(e)?n(null,e):n("[serializr] this value is not primitive: "+e)}},e)}var b="undefined"!=typeof Symbol?Symbol("SKIP"):{SKIP:!0},j=y(),z=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm,g=/([^\s,]+)/g;function x(e){var n,t=e.toString().replace(z,"");return null!=(n=t.slice(t.indexOf("(")+1,t.indexOf(")")).match(g))?n:[]}function S(e,n,r,i){var o;if(t(arguments.length>=2,"too few arguments. Please use @serializable as property decorator"),r===undefined&&"function"==typeof n&&n.prototype&&i!==undefined&&"number"==typeof i){t(f(e),"Constructor params must use alias(name)"),t(a(e),"Constructor params must use alias(name)");var u=x(n);u.length>=i&&(r=u[i],e.paramNumber=i,i=undefined,n=n.prototype,o=function(e){for(var t,r=[],i=function(n){Object.keys(e.modelSchema.props).forEach((function(t){var i=e.modelSchema.props[t];i.paramNumber===n&&(r[n]=e.json[i.jsonname])}))},o=0;o<n.constructor.length;o++)i(o);return(t=n.constructor).bind.apply(t,m([undefined],r))})}t("string"==typeof r,"incorrect usage of @serializable decorator");var c=p(n);return c&&n.constructor.hasOwnProperty("serializeInfo")||(c=h(n.constructor,{},o)),c&&c.targetClass!==n.constructor&&(c=h(n.constructor,{},o)),c.props[r]=e,!i||i.get||i.set||(i.writable=!0),i}function O(e,n,r){if(!n){var i=!0===e?j:e;return t(f(i),"@serializable expects prop schema"),S.bind(null,i)}S(y(),e,n,r)}function w(e,n){t(1===arguments.length||2===arguments.length,"serialize expects one or 2 arguments");var r=null!=n?n:e,i=n&&e;if(Array.isArray(r)){if(0===r.length)return[];i?"object"!=typeof i&&(i=p(i)):i=p(r[0])}else i?"object"!=typeof i&&(i=p(i)):i=p(r);var o=i;return t(o,"Failed to find default schema for "+e),Array.isArray(r)?r.map((function(e){return A(o,e)})):A(o,r)}function A(e,n){var r;return t(e&&"object"==typeof e&&e.props,"Expected schema"),t(n&&"object"==typeof n,"Expected object"),r=e["extends"]?A(e["extends"],n):{},Object.keys(e.props).forEach((function(t){var i=e.props[t];if(i)if("*"!==t){!0===i&&(i=j);var u=i.serializer(n[t],t,n);u!==b&&(r[i.jsonname||t]=u)}else!function(e,n,t,r){for(var i=0,u=Object.keys(t);i<u.length;i++){var f=u[i];if(!(f in e.props)&&(!0===n||n&&(!n.pattern||n.pattern.test(f)))){var a=t[f];if(!0===n)o(a)&&(r[f]=a);else{var c=n.serializer(a,f,t);if(c===b)return;r[f]=c}}}}(e,i,n,r)})),r}var k=new WeakMap,E=function(){function e(e,n,t,r,i){this.parentContext=e,this.modelSchema=n,this.json=t,this.onReadyCb=r,this.isRoot=!e,this.pendingCallbacks=0,this.pendingRefsCount=0,this.target=undefined,this.hasError=!1,e?(this.rootContext=e.rootContext,this.args=e.args):(this.rootContext=this,this.args=i,this.pendingRefs={},this.resolvedRefs={})}return e.prototype.createCallback=function(e){var n=this;return this.pendingCallbacks++,function(e){var n=!1;return function(){if(!n)return n=!0,e.apply(null,arguments);t(!1,"callback was invoked twice")}}((function(t,r){t?n.hasError||(n.hasError=!0,n.onReadyCb(t),k["delete"](n)):n.hasError||(e(r),--n.pendingCallbacks===n.pendingRefsCount&&(n.pendingRefsCount>0?(n.onReadyCb(Error('Unresolvable references in json: "'+Object.keys(n.pendingRefs).filter((function(e){return n.pendingRefs[e].length>0})).join('", "')+'"')),k["delete"](n)):(n.onReadyCb(null,n.target),k["delete"](n))))}))},e.prototype.await=function(e,n,r){if(t(this.isRoot,"await can only be called on the root context"),n in this.resolvedRefs){var i=this.resolvedRefs[n].filter((function(n){return s(n.modelSchema,e)}))[0];if(i)return void r(null,i.value)}this.pendingRefsCount++,this.pendingRefs[n]||(this.pendingRefs[n]=[]),this.pendingRefs[n].push({modelSchema:e,uuid:n,callback:r})},e.prototype.resolve=function(e,n,r){if(t(this.isRoot,"resolve can only called on the root context"),this.resolvedRefs[n]||(this.resolvedRefs[n]=[]),this.resolvedRefs[n].push({modelSchema:e,value:r}),n in this.pendingRefs)for(var i=this.pendingRefs[n].length-1;i>=0;i--){var o=this.pendingRefs[n][i];s(e,o.modelSchema)&&(this.pendingRefs[n].splice(i,1),this.pendingRefsCount--,o.callback(null,r))}},e.prototype.setTarget=function(e){this.isRoot&&this.target&&k["delete"](this.target),this.target=e,k.set(this.target,this)},e.prototype.cancelAwaits=function(){t(this.isRoot,"cancelAwaits can only be called on the root context");var e=this;Object.keys(this.pendingRefs).forEach((function(n){e.pendingRefs[n].forEach((function(t){e.pendingRefsCount--,t.callback(Error("Reference resolution canceled for "+n))}))})),this.pendingRefs={},this.pendingRefsCount=0},e}();function N(e,n,o,f){void 0===o&&(o=r),t(arguments.length>=2,"deserialize expects at least 2 arguments");var a=p(e);if(t(u(a),"first argument should be model schema"),Array.isArray(n)){var c=[];return i(n,(function(e,n){var t=D(undefined,a,e,n,f);c.push(t)}),o),c}return D(undefined,a,n,o,f)}function D(e,n,i,o,u){if(null!==i&&i!==undefined&&"object"==typeof i){var f=new E(e,n,i,o,u),a=n.factory(f);t(!!a,"No object returned from factory"),f.setTarget(a);var c=f.createCallback(r);return I(f,n,i,a),c(),a}o(null,null)}function I(e,n,r,i){var u;n["extends"]&&I(e,n["extends"],r,i);for(var f=function(f){var a=n.props[f];if(!a)return{value:void 0};if("*"===f)return function(e,n,r,i,u){var f=function(f){if(!(f in n.props||function(e,n){for(var t in e.props){var r=e.props[t];if("object"==typeof r&&r.jsonname===n)return!0}return!1}(n,f))){var a=u[f];!0===r?(t(o(a),"encountered non primitive value while deserializing '*' properties in property '"+f+"': "+a),i[f]=a):!r||r.pattern&&!r.pattern.test(f)||r.deserializer(a,e.rootContext.createCallback((function(e){return e!==b&&(i[f]=e)})),e)}};for(var a in u)f(a)}(e,n,a,i,r),{value:void 0};!0===a&&(a=j);var c=null!=(u=a.jsonname)?u:f;t("symbol"!=typeof c,"You must alias symbol properties. prop = %l",f);var s=r[c],l=a;J((function(n,t){n||t===undefined||function(n,t,o){var u=e.rootContext.createCallback((function(e){return e!==b&&(i[o]=e)}));n.deserializer(t,(function(i,f){return M(u,i,f,t,r,o,e,n)}),e,i[o])}(l,t,f)}),s,r,c,e,a)},a=0,c=Object.keys(n.props);a<c.length;a++){var s=f(c[a]);if("object"==typeof s)return s.value}}var J=function(e,n,t,r,i,o){o&&"function"==typeof o.beforeDeserialize?o.beforeDeserialize(e,n,t,r,i,o):e(null,n)},M=function(e,n,t,r,i,o,u,f){f&&"function"==typeof f.afterDeserialize?f.afterDeserialize(e,n,t,r,i,o,u,f):e(n,t)};function P(e,n){return t("object"==typeof e||"function"==typeof e,"No modelschema provided. If you are importing it from another file be aware of circular dependencies."),d({serializer:function(n){return t(u(e=p(e)),"expected modelSchema, got "+e),null===n||n===undefined?n:w(e,n)},deserializer:function(n,r,i){t(u(e=p(e)),"expected modelSchema, got "+e),null!==n&&n!==undefined?D(i,e,n,r,undefined):r(null,n)}},n)}function C(e,n){var r;if(1===arguments.length)return r=!0,i(e);function i(e){t("function"==typeof e,"@serializeAll can only be used as class decorator");var n=p(e);return n||v(e,n=h(e,{})),n.props["*"]=r,e}return t("object"==typeof e&&e.test,"@serializeAll pattern doesn't have test"),"function"==typeof n&&(n=P(n)),!0===n&&(n=j),t(f(n),"couldn't resolve schema"),r=Object.assign({},n,{pattern:e}),i}function K(e){t("object"==typeof e&&e&&!Array.isArray(e),"cancelDeserialize needs an object");var n,r=(n=e,k.get(n));r&&r.cancelAwaits()}function U(e,n,i,o,f){var a=2===arguments.length||"function"==typeof arguments[2];a?(e=p(n=arguments[0]),i=arguments[1],o=arguments[2],f=arguments[3]):e=p(e),t(u(e),"update failed to determine schema"),t("object"==typeof n&&n&&!Array.isArray(n),"update needs an object");var c=new E(undefined,e,i,o||r,f);c.setTarget(n);var s=c.createCallback(r),l=I(c,e,i,n);return s(),l}function q(e,n){var r,i;return"function"==typeof e?(r=e,i=n):i=e,t(!i||"object"==typeof i,"Additional property arguments should be an object, register function should be omitted or a funtion"),d({identifier:!0,serializer:j.serializer,deserializer:function(e,n,t){j.deserializer(e,(function(e,i){!function(e,n,t){t.rootContext.resolve(t.modelSchema,e,t.target)}(i,t.target,t),r&&r(i,t.target,t),n(e,i)}),t)}},i)}function F(e){return d({serializer:function(e){return null===e||e===undefined?e:(t(e instanceof Date,"Expected Date object"),e.getTime())},deserializer:function(e,n){null!==e&&e!==undefined?n(null,new Date(e)):n(null,e)}},e)}function R(e,n){return t(e&&"string"==typeof e,"expected prop name as first argument"),t(f(n=n&&!0!==n?n:j),"expected prop schema as second argument"),t(!a(n),"provided prop is already aliased"),{jsonname:e,serializer:n.serializer,deserializer:n.deserializer,identifier:c(n)||undefined,beforeDeserialize:n.beforeDeserialize,afterDeserialize:n.afterDeserialize}}function W(e,n,r){return t("function"==typeof e,"first argument should be function"),t("function"==typeof n,"second argument should be a function or promise"),d({serializer:e,deserializer:function(e,t,r,i){var o=n(e,r,i,t);4!==n.length&&t(null,o)}},r)}function Y(e){t(f(e=e&&!0!==e?e:j),"expected prop schema as second argument");var n=e.serializer;return t("function"==typeof n,"expected prop schema to have a callable serializer"),Object.assign({},e,{serializer:function(e,t,r){var i=n(e,t,r);return i===undefined?b:i}})}function Z(e,n,r){t(!!e,"No modelSchema provided. If you are importing it from another file be aware of circular dependencies.");var i="function"==typeof n?n:undefined;r=r||(i?undefined:n);var o,f=!1;function a(){if(f=!0,t("string"!=typeof e||"function"==typeof i,"if the reference target is specified by attribute name, a lookup function is required"),t(!i||"function"==typeof i,"second argument should be a lookup function or additional arguments object"),"string"==typeof e)o=e;else{var n=p(e);t(u(n),"expected model schema or string as first argument for 'ref', got "+n),i=i||function(e){return function(n,t,r){r.rootContext.await(e,n,t)}}(n),o=function(e){t(u(e),"modelSchema must be a ModelSchema");for(var n=e;n;){for(var r in n.props)if(c(n.props[r]))return r;n=n["extends"]}return undefined}(n),t(!!o,"provided model schema doesn't define an identifier() property and cannot be used by 'ref'.")}}return d({serializer:function(e){return f||a(),e?e[o]:null},deserializer:function(e,n,t){f||a(),null===e||e===undefined?n(null,e):i(e,n,t)}},r)}function $(e,n){return t(f(e=e||j),"expected prop schema as first argument"),t(!a(e),"provided prop is aliased, please put aliases first"),d({serializer:function(n){return n===undefined?b:(t(n&&"length"in n&&"map"in n,"expected array (like) object"),n.map(e.serializer))},deserializer:function(n,t,r){Array.isArray(n)?i(n,(function(t,i,o){function u(u,f){"function"==typeof e.afterDeserialize?M(i,u,f,t,n,o,r,e):i(u,f)}J((function(n,t){n?i(n):e.deserializer(t,u,r)}),t,n,o,r,e)}),t):t("[serializr] expected JSON array")}},n)}function B(e,n){return t(f(e=e||j),"expected prop schema as first argument"),t(!a(e),"provided prop is aliased, please put aliases first"),d({serializer:function(n){t(n&&"object"==typeof n,"expected object or Map");var r={};if(l(n))n.forEach((function(t,i){return r[i]=e.serializer(t,i,n)}));else for(var i in n)r[i]=e.serializer(n[i],i,n);return r},deserializer:function(t,r,i,o){if(t&&"object"==typeof t){var u=Object.keys(t);$(e,n).deserializer(u.map((function(e){return t[e]})),(function(e,n){if(e)r(e);else{var t,i=l(o);i?(o.clear(),t=o):t={};for(var f=0,a=u.length;f<a;f++)i?t.set(u[f],n[f]):t[u[f]]=n[f];r(null,t)}}),i)}else r("[serializr] expected JSON object")}},n)}function G(e,n,r){return t(f(e=e||j),"expected prop schema as first argument"),t(!!n,"expected key property name as second argument"),d({serializer:function(n){t(n&&"object"==typeof n,"expected object or Map");var r=[];if(l(n))n.forEach((function(t,i){return r.push(e.serializer(t,i,n))}));else for(var i in n)r.push(e.serializer(n[i],i,n));return r},deserializer:function(t,i,o,u){$(e,r).deserializer(t,(function(e,r){if(e)i(e);else{var o,f=l(u);f?(u.clear(),o=u):o={};for(var a=0,c=t.length;a<c;a++)f?o.set(r[a][n],r[a]):o[r[a][n].toString()]=r[a];i(null,o)}}),o,undefined)}},r)}function H(e){return d({serializer:function(e){return e},deserializer:function(e,n){n(null,e)}},e)}export{b as SKIP,R as alias,K as cancelDeserialize,h as createModelSchema,e as createSimpleSchema,W as custom,F as date,N as deserialize,p as getDefaultModelSchema,q as identifier,$ as list,B as map,G as mapAsArray,P as object,Y as optional,y as primitive,H as raw,Z as reference,O as serializable,w as serialize,C as serializeAll,v as setDefaultModelSchema,U as update};
***************************************************************************** */function m(){for(var e=0,n=0,t=arguments.length;n<t;n++)e+=arguments[n].length;var r=Array(e),i=0;for(n=0;n<t;n++)for(var o=arguments[n],u=0,f=o.length;u<f;u++,i++)r[i]=o[u];return r}function y(e){return d({serializer:function(e){return t(o(e),"this value is not primitive: "+e),e},deserializer:function(e,n){o(e)?n(null,e):n("[serializr] this value is not primitive: "+e)}},e)}var b="undefined"!=typeof Symbol?Symbol("SKIP"):{SKIP:!0},j=y(),z=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm,g=/([^\s,]+)/g;function x(e){var n,t=e.toString().replace(z,"");return null!=(n=t.slice(t.indexOf("(")+1,t.indexOf(")")).match(g))?n:[]}function S(e,n,r,i){var o;if(t(arguments.length>=2,"too few arguments. Please use @serializable as property decorator"),r===undefined&&"function"==typeof n&&n.prototype&&i!==undefined&&"number"==typeof i){t(f(e),"Constructor params must use alias(name)"),t(a(e),"Constructor params must use alias(name)");var u=x(n);u.length>=i&&(r=u[i],e.paramNumber=i,i=undefined,n=n.prototype,o=function(e){for(var t,r=[],i=function(n){Object.keys(e.modelSchema.props).forEach((function(t){var i=e.modelSchema.props[t];i.paramNumber===n&&(r[n]=e.json[i.jsonname])}))},o=0;o<n.constructor.length;o++)i(o);return(t=n.constructor).bind.apply(t,m([undefined],r))})}t("string"==typeof r,"incorrect usage of @serializable decorator");var c=p(n);return c&&n.constructor.hasOwnProperty("serializeInfo")||(c=h(n.constructor,{},o)),c&&c.targetClass!==n.constructor&&(c=h(n.constructor,{},o)),c.props[r]=e,!i||i.get||i.set||(i.writable=!0),i}function O(e,n,r){if(!n){var i=!0===e?j:e;return t(f(i),"@serializable expects prop schema"),S.bind(null,i)}S(y(),e,n,r)}function w(e,n){t(1===arguments.length||2===arguments.length,"serialize expects one or 2 arguments");var r=null!=n?n:e,i=n&&e;if(Array.isArray(r)){if(0===r.length)return[];i?"object"!=typeof i&&(i=p(i)):i=p(r[0])}else i?"object"!=typeof i&&(i=p(i)):i=p(r);var o=i;return t(o,"Failed to find default schema for "+e),Array.isArray(r)?r.map((function(e){return A(o,e)})):A(o,r)}function A(e,n){var r;return t(e&&"object"==typeof e&&e.props,"Expected schema"),t(n&&"object"==typeof n,"Expected object"),r=e["extends"]?A(e["extends"],n):{},Object.keys(e.props).forEach((function(t){var i=e.props[t];if(i)if("*"!==t){!0===i&&(i=j);var u=i.serializer(n[t],t,n);u!==b&&(r[i.jsonname||t]=u)}else!function(e,n,t,r){for(var i=0,u=Object.keys(t);i<u.length;i++){var f=u[i];if(!(f in e.props)&&(!0===n||n&&(!n.pattern||n.pattern.test(f)))){var a=t[f];if(!0===n)o(a)&&(r[f]=a);else{var c=n.serializer(a,f,t);if(c===b)return;r[f]=c}}}}(e,i,n,r)})),r}var k=new WeakMap,E=function(){function e(e,n,t,r,i){this.parentContext=e,this.modelSchema=n,this.json=t,this.onReadyCb=r,this.isRoot=!e,this.pendingCallbacks=0,this.pendingRefsCount=0,this.target=undefined,this.hasError=!1,e?(this.rootContext=e.rootContext,this.args=e.args):(this.rootContext=this,this.args=i,this.pendingRefs={},this.resolvedRefs={})}return e.prototype.createCallback=function(e){var n=this;return this.pendingCallbacks++,function(e){var n=!1;return function(){if(!n)return n=!0,e.apply(null,arguments);t(!1,"callback was invoked twice")}}((function(t,r){t?n.hasError||(n.hasError=!0,n.onReadyCb(t),k["delete"](n)):n.hasError||(e(r),--n.pendingCallbacks===n.pendingRefsCount&&(n.pendingRefsCount>0?(n.onReadyCb(Error('Unresolvable references in json: "'+Object.keys(n.pendingRefs).filter((function(e){return n.pendingRefs[e].length>0})).join('", "')+'"')),k["delete"](n)):(n.onReadyCb(null,n.target),k["delete"](n))))}))},e.prototype.await=function(e,n,r){if(t(this.isRoot,"await can only be called on the root context"),n in this.resolvedRefs){var i=this.resolvedRefs[n].filter((function(n){return s(n.modelSchema,e)}))[0];if(i)return void r(null,i.value)}this.pendingRefsCount++,this.pendingRefs[n]||(this.pendingRefs[n]=[]),this.pendingRefs[n].push({modelSchema:e,uuid:n,callback:r})},e.prototype.resolve=function(e,n,r){if(t(this.isRoot,"resolve can only called on the root context"),this.resolvedRefs[n]||(this.resolvedRefs[n]=[]),this.resolvedRefs[n].push({modelSchema:e,value:r}),n in this.pendingRefs)for(var i=this.pendingRefs[n].length-1;i>=0;i--){var o=this.pendingRefs[n][i];s(e,o.modelSchema)&&(this.pendingRefs[n].splice(i,1),this.pendingRefsCount--,o.callback(null,r))}},e.prototype.setTarget=function(e){this.isRoot&&this.target&&k["delete"](this.target),this.target=e,k.set(this.target,this)},e.prototype.cancelAwaits=function(){t(this.isRoot,"cancelAwaits can only be called on the root context");var e=this;Object.keys(this.pendingRefs).forEach((function(n){e.pendingRefs[n].forEach((function(t){e.pendingRefsCount--,t.callback(Error("Reference resolution canceled for "+n))}))})),this.pendingRefs={},this.pendingRefsCount=0},e}();function N(e,n,o,f){void 0===o&&(o=r),t(arguments.length>=2,"deserialize expects at least 2 arguments");var a=p(e);if(t(u(a),"first argument should be model schema"),Array.isArray(n)){var c=[];return i(n,(function(e,n){var t=D(undefined,a,e,n,f);c.push(t)}),o),c}return D(undefined,a,n,o,f)}function D(e,n,i,o,u){if(null!==i&&i!==undefined&&"object"==typeof i){var f=new E(e,n,i,o,u),a=n.factory(f);t(!!a,"No object returned from factory"),f.setTarget(a);var c=f.createCallback(r);return I(f,n,i,a),c(),a}o(null,null)}function I(e,n,r,i){var u;n["extends"]&&I(e,n["extends"],r,i);for(var f=function(f){var a=n.props[f];if(!a)return{value:void 0};if("*"===f)return function(e,n,r,i,u){var f=function(f){if(!(f in n.props||function(e,n){for(var t in e.props){var r=e.props[t];if("object"==typeof r&&r.jsonname===n)return!0}return!1}(n,f))){var a=u[f];!0===r?(t(o(a),"encountered non primitive value while deserializing '*' properties in property '"+f+"': "+a),i[f]=a):!r||r.pattern&&!r.pattern.test(f)||r.deserializer(a,e.rootContext.createCallback((function(e){return e!==b&&(i[f]=e)})),e)}};for(var a in u)f(a)}(e,n,a,i,r),{value:void 0};!0===a&&(a=j);var c=null!=(u=a.jsonname)?u:f;t("symbol"!=typeof c,"You must alias symbol properties. prop = %l",f);var s=r[c],l=a;J((function(n,t){n||t===undefined||function(n,t,o){var u=e.rootContext.createCallback((function(e){return e!==b&&(i[o]=e)}));n.deserializer(t,(function(i,f){return M(u,i,f,t,r,o,e,n)}),e,i[o])}(l,t,f)}),s,r,c,e,a)},a=0,c=Object.keys(n.props);a<c.length;a++){var s=f(c[a]);if("object"==typeof s)return s.value}}var J=function(e,n,t,r,i,o){o&&"function"==typeof o.beforeDeserialize?o.beforeDeserialize(e,n,t,r,i,o):e(null,n)},M=function(e,n,t,r,i,o,u,f){f&&"function"==typeof f.afterDeserialize?f.afterDeserialize(e,n,t,r,i,o,u,f):e(n,t)};function P(e,n){return t("object"==typeof e||"function"==typeof e,"No modelschema provided. If you are importing it from another file be aware of circular dependencies."),d({serializer:function(n){return t(u(e=p(e)),"expected modelSchema, got "+e),null===n||n===undefined?n:w(e,n)},deserializer:function(n,r,i){t(u(e=p(e)),"expected modelSchema, got "+e),null!==n&&n!==undefined?D(i,e,n,r,undefined):r(null,n)}},n)}function C(e,n){var r;if(1===arguments.length)return r=!0,i(e);function i(e){t("function"==typeof e,"@serializeAll can only be used as class decorator");var n=p(e);return n||v(e,n=h(e,{})),n.props["*"]=r,e}return t("object"==typeof e&&e.test,"@serializeAll pattern doesn't have test"),"function"==typeof n&&(n=P(n)),!0===n&&(n=j),t(f(n),"couldn't resolve schema"),r=Object.assign({},n,{pattern:e}),i}function K(e){t("object"==typeof e&&e&&!Array.isArray(e),"cancelDeserialize needs an object");var n,r=(n=e,k.get(n));r&&r.cancelAwaits()}function U(e,n,i,o,f){var a=2===arguments.length||"function"==typeof arguments[2];a?(e=p(n=arguments[0]),i=arguments[1],o=arguments[2],f=arguments[3]):e=p(e),t(u(e),"update failed to determine schema"),t("object"==typeof n&&n&&!Array.isArray(n),"update needs an object");var c=new E(undefined,e,i,o||r,f);c.setTarget(n);var s=c.createCallback(r),l=I(c,e,i,n);return s(),l}function q(e,n){var r,i;return"function"==typeof e?(r=e,i=n):i=e,t(!i||"object"==typeof i,"Additional property arguments should be an object, register function should be omitted or a funtion"),d({identifier:!0,serializer:j.serializer,deserializer:function(e,n,t){j.deserializer(e,(function(e,i){!function(e,n,t){t.rootContext.resolve(t.modelSchema,e,t.target)}(i,t.target,t),r&&r(i,t.target,t),n(e,i)}),t)}},i)}function F(e){return d({serializer:function(e){return null===e||e===undefined?e:(t(e instanceof Date,"Expected Date object"),e.getTime())},deserializer:function(e,n){null!==e&&e!==undefined?n(null,new Date(e)):n(null,e)}},e)}function R(e,n){return t(e&&"string"==typeof e,"expected prop name as first argument"),t(f(n=n&&!0!==n?n:j),"expected prop schema as second argument"),t(!a(n),"provided prop is already aliased"),{jsonname:e,serializer:n.serializer,deserializer:n.deserializer,identifier:c(n)||undefined,beforeDeserialize:n.beforeDeserialize,afterDeserialize:n.afterDeserialize}}function W(e,n,r){return t("function"==typeof e,"first argument should be function"),t("function"==typeof n,"second argument should be a function or promise"),d({serializer:e,deserializer:function(e,t,r,i){var o=n(e,r,i,t);4!==n.length&&t(null,o)}},r)}function Y(e){t(f(e=e&&!0!==e?e:j),"expected prop schema as second argument");var n=e.serializer;return t("function"==typeof n,"expected prop schema to have a callable serializer"),Object.assign({},e,{serializer:function(e,t,r){var i=n(e,t,r);return i===undefined?b:i}})}function Z(e,n,r){t(!!e,"No modelSchema provided. If you are importing it from another file be aware of circular dependencies.");var i="function"==typeof n?n:undefined;r=r||(i?undefined:n);var o,f=!1;function a(){if(f=!0,t("string"!=typeof e||"function"==typeof i,"if the reference target is specified by attribute name, a lookup function is required"),t(!i||"function"==typeof i,"second argument should be a lookup function or additional arguments object"),"string"==typeof e)o=e;else{var n=p(e);t(u(n),"expected model schema or string as first argument for 'ref', got "+n),i=i||function(e){return function(n,t,r){r.rootContext.await(e,n,t)}}(n),o=function(e){t(u(e),"modelSchema must be a ModelSchema");for(var n=e;n;){for(var r in n.props)if(c(n.props[r]))return r;n=n["extends"]}return undefined}(n),t(!!o,"provided model schema doesn't define an identifier() property and cannot be used by 'ref'.")}}return d({serializer:function(e){return f||a(),e?e[o]:null},deserializer:function(e,n,t){f||a(),null===e||e===undefined?n(null,e):i(e,n,t)}},r)}function $(e,n){return t(f(e=e||j),"expected prop schema as first argument"),t(!a(e),"provided prop is aliased, please put aliases first"),d({serializer:function(n){return n===undefined?b:(t(n&&"length"in n&&"map"in n,"expected array (like) object"),n.map(e.serializer))},deserializer:function(n,t,r){Array.isArray(n)?i(n,(function(t,i,o){function u(u,f){"function"==typeof e.afterDeserialize?M(i,u,f,t,n,o,r,e):i(u,f)}J((function(n,t){n?i(n):e.deserializer(t,u,r)}),t,n,o,r,e)}),(function(e,n){e?t(e):t(undefined,n.filter((function(e){return b!==e})))})):t("[serializr] expected JSON array")}},n)}function B(e,n){return t(f(e=e||j),"expected prop schema as first argument"),t(!a(e),"provided prop is aliased, please put aliases first"),d({serializer:function(n){t(n&&"object"==typeof n,"expected object or Map");var r={};if(l(n))n.forEach((function(t,i){return r[i]=e.serializer(t,i,n)}));else for(var i in n)r[i]=e.serializer(n[i],i,n);return r},deserializer:function(t,r,i,o){if(t&&"object"==typeof t){var u=Object.keys(t);$(e,n).deserializer(u.map((function(e){return t[e]})),(function(e,n){if(e)r(e);else{var t,i=l(o);i?(o.clear(),t=o):t={};for(var f=0,a=u.length;f<a;f++)i?t.set(u[f],n[f]):t[u[f]]=n[f];r(null,t)}}),i)}else r("[serializr] expected JSON object")}},n)}function G(e,n,r){return t(f(e=e||j),"expected prop schema as first argument"),t(!!n,"expected key property name as second argument"),d({serializer:function(n){t(n&&"object"==typeof n,"expected object or Map");var r=[];if(l(n))n.forEach((function(t,i){return r.push(e.serializer(t,i,n))}));else for(var i in n)r.push(e.serializer(n[i],i,n));return r},deserializer:function(t,i,o,u){$(e,r).deserializer(t,(function(e,r){if(e)i(e);else{var o,f=l(u);f?(u.clear(),o=u):o={};for(var a=0,c=t.length;a<c;a++)f?o.set(r[a][n],r[a]):o[r[a][n].toString()]=r[a];i(null,o)}}),o,undefined)}},r)}function H(e){return d({serializer:function(e){return e},deserializer:function(e,n){n(null,e)}},e)}export{b as SKIP,R as alias,K as cancelDeserialize,h as createModelSchema,e as createSimpleSchema,W as custom,F as date,N as deserialize,p as getDefaultModelSchema,q as identifier,$ as list,B as map,G as mapAsArray,P as object,Y as optional,y as primitive,H as raw,Z as reference,O as serializable,w as serialize,C as serializeAll,v as setDefaultModelSchema,U as update};
//# sourceMappingURL=serializr.min.js.map

@@ -1087,3 +1087,8 @@ (function (global, factory) {

}
parallel(jsonArray, processItem, done);
parallel(jsonArray, processItem, function (err, result) {
if (err) {
return void done(err);
}
done(undefined, result.filter(function (x) { return SKIP !== x; }));
});
}

@@ -1090,0 +1095,0 @@ };

@@ -16,3 +16,3 @@ /** serializr - (c) Michel Weststrate 2016 - MIT Licensed */

and limitations under the License.
***************************************************************************** */function m(){for(var e=0,n=0,t=arguments.length;n<t;n++)e+=arguments[n].length;var r=Array(e),i=0;for(n=0;n<t;n++)for(var o=arguments[n],u=0,f=o.length;u<f;u++,i++)r[i]=o[u];return r}function y(e){return d({serializer:function(e){return t(o(e),"this value is not primitive: "+e),e},deserializer:function(e,n){o(e)?n(null,e):n("[serializr] this value is not primitive: "+e)}},e)}var b="undefined"!=typeof Symbol?Symbol("SKIP"):{SKIP:!0},j=y(),z=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm,g=/([^\s,]+)/g;function x(e){var n,t=e.toString().replace(z,"");return null!=(n=t.slice(t.indexOf("(")+1,t.indexOf(")")).match(g))?n:[]}function S(e,n,r,i){var o;if(t(arguments.length>=2,"too few arguments. Please use @serializable as property decorator"),r===undefined&&"function"==typeof n&&n.prototype&&i!==undefined&&"number"==typeof i){t(f(e),"Constructor params must use alias(name)"),t(a(e),"Constructor params must use alias(name)");var u=x(n);u.length>=i&&(r=u[i],e.paramNumber=i,i=undefined,n=n.prototype,o=function(e){for(var t,r=[],i=function(n){Object.keys(e.modelSchema.props).forEach((function(t){var i=e.modelSchema.props[t];i.paramNumber===n&&(r[n]=e.json[i.jsonname])}))},o=0;o<n.constructor.length;o++)i(o);return(t=n.constructor).bind.apply(t,m([undefined],r))})}t("string"==typeof r,"incorrect usage of @serializable decorator");var c=p(n);return c&&n.constructor.hasOwnProperty("serializeInfo")||(c=h(n.constructor,{},o)),c&&c.targetClass!==n.constructor&&(c=h(n.constructor,{},o)),c.props[r]=e,!i||i.get||i.set||(i.writable=!0),i}function O(e,n){t(1===arguments.length||2===arguments.length,"serialize expects one or 2 arguments");var r=null!=n?n:e,i=n&&e;if(Array.isArray(r)){if(0===r.length)return[];i?"object"!=typeof i&&(i=p(i)):i=p(r[0])}else i?"object"!=typeof i&&(i=p(i)):i=p(r);var o=i;return t(o,"Failed to find default schema for "+e),Array.isArray(r)?r.map((function(e){return w(o,e)})):w(o,r)}function w(e,n){var r;return t(e&&"object"==typeof e&&e.props,"Expected schema"),t(n&&"object"==typeof n,"Expected object"),r=e["extends"]?w(e["extends"],n):{},Object.keys(e.props).forEach((function(t){var i=e.props[t];if(i)if("*"!==t){!0===i&&(i=j);var u=i.serializer(n[t],t,n);u!==b&&(r[i.jsonname||t]=u)}else!function(e,n,t,r){for(var i=0,u=Object.keys(t);i<u.length;i++){var f=u[i];if(!(f in e.props)&&(!0===n||n&&(!n.pattern||n.pattern.test(f)))){var a=t[f];if(!0===n)o(a)&&(r[f]=a);else{var c=n.serializer(a,f,t);if(c===b)return;r[f]=c}}}}(e,i,n,r)})),r}var A=new WeakMap,k=function(){function e(e,n,t,r,i){this.parentContext=e,this.modelSchema=n,this.json=t,this.onReadyCb=r,this.isRoot=!e,this.pendingCallbacks=0,this.pendingRefsCount=0,this.target=undefined,this.hasError=!1,e?(this.rootContext=e.rootContext,this.args=e.args):(this.rootContext=this,this.args=i,this.pendingRefs={},this.resolvedRefs={})}return e.prototype.createCallback=function(e){var n=this;return this.pendingCallbacks++,function(e){var n=!1;return function(){if(!n)return n=!0,e.apply(null,arguments);t(!1,"callback was invoked twice")}}((function(t,r){t?n.hasError||(n.hasError=!0,n.onReadyCb(t),A["delete"](n)):n.hasError||(e(r),--n.pendingCallbacks===n.pendingRefsCount&&(n.pendingRefsCount>0?(n.onReadyCb(Error('Unresolvable references in json: "'+Object.keys(n.pendingRefs).filter((function(e){return n.pendingRefs[e].length>0})).join('", "')+'"')),A["delete"](n)):(n.onReadyCb(null,n.target),A["delete"](n))))}))},e.prototype.await=function(e,n,r){if(t(this.isRoot,"await can only be called on the root context"),n in this.resolvedRefs){var i=this.resolvedRefs[n].filter((function(n){return s(n.modelSchema,e)}))[0];if(i)return void r(null,i.value)}this.pendingRefsCount++,this.pendingRefs[n]||(this.pendingRefs[n]=[]),this.pendingRefs[n].push({modelSchema:e,uuid:n,callback:r})},e.prototype.resolve=function(e,n,r){if(t(this.isRoot,"resolve can only called on the root context"),this.resolvedRefs[n]||(this.resolvedRefs[n]=[]),this.resolvedRefs[n].push({modelSchema:e,value:r}),n in this.pendingRefs)for(var i=this.pendingRefs[n].length-1;i>=0;i--){var o=this.pendingRefs[n][i];s(e,o.modelSchema)&&(this.pendingRefs[n].splice(i,1),this.pendingRefsCount--,o.callback(null,r))}},e.prototype.setTarget=function(e){this.isRoot&&this.target&&A["delete"](this.target),this.target=e,A.set(this.target,this)},e.prototype.cancelAwaits=function(){t(this.isRoot,"cancelAwaits can only be called on the root context");var e=this;Object.keys(this.pendingRefs).forEach((function(n){e.pendingRefs[n].forEach((function(t){e.pendingRefsCount--,t.callback(Error("Reference resolution canceled for "+n))}))})),this.pendingRefs={},this.pendingRefsCount=0},e}();function E(e,n,i,o,u){if(null!==i&&i!==undefined&&"object"==typeof i){var f=new k(e,n,i,o,u),a=n.factory(f);t(!!a,"No object returned from factory"),f.setTarget(a);var c=f.createCallback(r);return N(f,n,i,a),c(),a}o(null,null)}function N(e,n,r,i){var u;n["extends"]&&N(e,n["extends"],r,i);for(var f=function(f){var a=n.props[f];if(!a)return{value:void 0};if("*"===f)return function(e,n,r,i,u){var f=function(f){if(!(f in n.props||function(e,n){for(var t in e.props){var r=e.props[t];if("object"==typeof r&&r.jsonname===n)return!0}return!1}(n,f))){var a=u[f];!0===r?(t(o(a),"encountered non primitive value while deserializing '*' properties in property '"+f+"': "+a),i[f]=a):!r||r.pattern&&!r.pattern.test(f)||r.deserializer(a,e.rootContext.createCallback((function(e){return e!==b&&(i[f]=e)})),e)}};for(var a in u)f(a)}(e,n,a,i,r),{value:void 0};!0===a&&(a=j);var c=null!=(u=a.jsonname)?u:f;t("symbol"!=typeof c,"You must alias symbol properties. prop = %l",f);var s=r[c],l=a;D((function(n,t){n||t===undefined||function(n,t,o){var u=e.rootContext.createCallback((function(e){return e!==b&&(i[o]=e)}));n.deserializer(t,(function(i,f){return I(u,i,f,t,r,o,e,n)}),e,i[o])}(l,t,f)}),s,r,c,e,a)},a=0,c=Object.keys(n.props);a<c.length;a++){var s=f(c[a]);if("object"==typeof s)return s.value}}var D=function(e,n,t,r,i,o){o&&"function"==typeof o.beforeDeserialize?o.beforeDeserialize(e,n,t,r,i,o):e(null,n)},I=function(e,n,t,r,i,o,u,f){f&&"function"==typeof f.afterDeserialize?f.afterDeserialize(e,n,t,r,i,o,u,f):e(n,t)};function M(e,n){return t("object"==typeof e||"function"==typeof e,"No modelschema provided. If you are importing it from another file be aware of circular dependencies."),d({serializer:function(n){return t(u(e=p(e)),"expected modelSchema, got "+e),null===n||n===undefined?n:O(e,n)},deserializer:function(n,r,i){t(u(e=p(e)),"expected modelSchema, got "+e),null!==n&&n!==undefined?E(i,e,n,r,undefined):r(null,n)}},n)}function J(e,n){return t(f(e=e||j),"expected prop schema as first argument"),t(!a(e),"provided prop is aliased, please put aliases first"),d({serializer:function(n){return n===undefined?b:(t(n&&"length"in n&&"map"in n,"expected array (like) object"),n.map(e.serializer))},deserializer:function(n,t,r){Array.isArray(n)?i(n,(function(t,i,o){function u(u,f){"function"==typeof e.afterDeserialize?I(i,u,f,t,n,o,r,e):i(u,f)}D((function(n,t){n?i(n):e.deserializer(t,u,r)}),t,n,o,r,e)}),t):t("[serializr] expected JSON array")}},n)}e.SKIP=b,e.alias=function(e,n){return t(e&&"string"==typeof e,"expected prop name as first argument"),t(f(n=n&&!0!==n?n:j),"expected prop schema as second argument"),t(!a(n),"provided prop is already aliased"),{jsonname:e,serializer:n.serializer,deserializer:n.deserializer,identifier:c(n)||undefined,beforeDeserialize:n.beforeDeserialize,afterDeserialize:n.afterDeserialize}},e.cancelDeserialize=function(e){t("object"==typeof e&&e&&!Array.isArray(e),"cancelDeserialize needs an object");var n,r=(n=e,A.get(n));r&&r.cancelAwaits()},e.createModelSchema=h,e.createSimpleSchema=function(e){return{factory:function(){return{}},props:e}},e.custom=function(e,n,r){return t("function"==typeof e,"first argument should be function"),t("function"==typeof n,"second argument should be a function or promise"),d({serializer:e,deserializer:function(e,t,r,i){var o=n(e,r,i,t);4!==n.length&&t(null,o)}},r)},e.date=function(e){return d({serializer:function(e){return null===e||e===undefined?e:(t(e instanceof Date,"Expected Date object"),e.getTime())},deserializer:function(e,n){null!==e&&e!==undefined?n(null,new Date(e)):n(null,e)}},e)},e.deserialize=function(e,n,o,f){void 0===o&&(o=r),t(arguments.length>=2,"deserialize expects at least 2 arguments");var a=p(e);if(t(u(a),"first argument should be model schema"),Array.isArray(n)){var c=[];return i(n,(function(e,n){var t=E(undefined,a,e,n,f);c.push(t)}),o),c}return E(undefined,a,n,o,f)},e.getDefaultModelSchema=p,e.identifier=function(e,n){var r,i;return"function"==typeof e?(r=e,i=n):i=e,t(!i||"object"==typeof i,"Additional property arguments should be an object, register function should be omitted or a funtion"),d({identifier:!0,serializer:j.serializer,deserializer:function(e,n,t){j.deserializer(e,(function(e,i){!function(e,n,t){t.rootContext.resolve(t.modelSchema,e,t.target)}(i,t.target,t),r&&r(i,t.target,t),n(e,i)}),t)}},i)},e.list=J,e.map=function(e,n){return t(f(e=e||j),"expected prop schema as first argument"),t(!a(e),"provided prop is aliased, please put aliases first"),d({serializer:function(n){t(n&&"object"==typeof n,"expected object or Map");var r={};if(l(n))n.forEach((function(t,i){return r[i]=e.serializer(t,i,n)}));else for(var i in n)r[i]=e.serializer(n[i],i,n);return r},deserializer:function(t,r,i,o){if(t&&"object"==typeof t){var u=Object.keys(t);J(e,n).deserializer(u.map((function(e){return t[e]})),(function(e,n){if(e)r(e);else{var t,i=l(o);i?(o.clear(),t=o):t={};for(var f=0,a=u.length;f<a;f++)i?t.set(u[f],n[f]):t[u[f]]=n[f];r(null,t)}}),i)}else r("[serializr] expected JSON object")}},n)},e.mapAsArray=function(e,n,r){return t(f(e=e||j),"expected prop schema as first argument"),t(!!n,"expected key property name as second argument"),d({serializer:function(n){t(n&&"object"==typeof n,"expected object or Map");var r=[];if(l(n))n.forEach((function(t,i){return r.push(e.serializer(t,i,n))}));else for(var i in n)r.push(e.serializer(n[i],i,n));return r},deserializer:function(t,i,o,u){J(e,r).deserializer(t,(function(e,r){if(e)i(e);else{var o,f=l(u);f?(u.clear(),o=u):o={};for(var a=0,c=t.length;a<c;a++)f?o.set(r[a][n],r[a]):o[r[a][n].toString()]=r[a];i(null,o)}}),o,undefined)}},r)},e.object=M,e.optional=function(e){t(f(e=e&&!0!==e?e:j),"expected prop schema as second argument");var n=e.serializer;return t("function"==typeof n,"expected prop schema to have a callable serializer"),Object.assign({},e,{serializer:function(e,t,r){var i=n(e,t,r);return i===undefined?b:i}})},e.primitive=y,e.raw=function(e){return d({serializer:function(e){return e},deserializer:function(e,n){n(null,e)}},e)},e.reference=function(e,n,r){t(!!e,"No modelSchema provided. If you are importing it from another file be aware of circular dependencies.");var i="function"==typeof n?n:undefined;r=r||(i?undefined:n);var o,f=!1;function a(){if(f=!0,t("string"!=typeof e||"function"==typeof i,"if the reference target is specified by attribute name, a lookup function is required"),t(!i||"function"==typeof i,"second argument should be a lookup function or additional arguments object"),"string"==typeof e)o=e;else{var n=p(e);t(u(n),"expected model schema or string as first argument for 'ref', got "+n),i=i||function(e){return function(n,t,r){r.rootContext.await(e,n,t)}}(n),o=function(e){t(u(e),"modelSchema must be a ModelSchema");for(var n=e;n;){for(var r in n.props)if(c(n.props[r]))return r;n=n["extends"]}return undefined}(n),t(!!o,"provided model schema doesn't define an identifier() property and cannot be used by 'ref'.")}}return d({serializer:function(e){return f||a(),e?e[o]:null},deserializer:function(e,n,t){f||a(),null===e||e===undefined?n(null,e):i(e,n,t)}},r)},e.serializable=function(e,n,r){if(!n){var i=!0===e?j:e;return t(f(i),"@serializable expects prop schema"),S.bind(null,i)}S(y(),e,n,r)},e.serialize=O,e.serializeAll=function(e,n){var r;if(1===arguments.length)return r=!0,i(e);function i(e){t("function"==typeof e,"@serializeAll can only be used as class decorator");var n=p(e);return n||v(e,n=h(e,{})),n.props["*"]=r,e}return t("object"==typeof e&&e.test,"@serializeAll pattern doesn't have test"),"function"==typeof n&&(n=M(n)),!0===n&&(n=j),t(f(n),"couldn't resolve schema"),r=Object.assign({},n,{pattern:e}),i},e.setDefaultModelSchema=v,e.update=function(e,n,i,o,f){var a=2===arguments.length||"function"==typeof arguments[2];a?(e=p(n=arguments[0]),i=arguments[1],o=arguments[2],f=arguments[3]):e=p(e),t(u(e),"update failed to determine schema"),t("object"==typeof n&&n&&!Array.isArray(n),"update needs an object");var c=new k(undefined,e,i,o||r,f);c.setTarget(n);var s=c.createCallback(r),l=N(c,e,i,n);return s(),l},Object.defineProperty(e,"t",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).serializr={});
***************************************************************************** */function m(){for(var e=0,n=0,t=arguments.length;n<t;n++)e+=arguments[n].length;var r=Array(e),i=0;for(n=0;n<t;n++)for(var o=arguments[n],u=0,f=o.length;u<f;u++,i++)r[i]=o[u];return r}function y(e){return d({serializer:function(e){return t(o(e),"this value is not primitive: "+e),e},deserializer:function(e,n){o(e)?n(null,e):n("[serializr] this value is not primitive: "+e)}},e)}var b="undefined"!=typeof Symbol?Symbol("SKIP"):{SKIP:!0},j=y(),z=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm,g=/([^\s,]+)/g;function x(e){var n,t=e.toString().replace(z,"");return null!=(n=t.slice(t.indexOf("(")+1,t.indexOf(")")).match(g))?n:[]}function S(e,n,r,i){var o;if(t(arguments.length>=2,"too few arguments. Please use @serializable as property decorator"),r===undefined&&"function"==typeof n&&n.prototype&&i!==undefined&&"number"==typeof i){t(f(e),"Constructor params must use alias(name)"),t(a(e),"Constructor params must use alias(name)");var u=x(n);u.length>=i&&(r=u[i],e.paramNumber=i,i=undefined,n=n.prototype,o=function(e){for(var t,r=[],i=function(n){Object.keys(e.modelSchema.props).forEach((function(t){var i=e.modelSchema.props[t];i.paramNumber===n&&(r[n]=e.json[i.jsonname])}))},o=0;o<n.constructor.length;o++)i(o);return(t=n.constructor).bind.apply(t,m([undefined],r))})}t("string"==typeof r,"incorrect usage of @serializable decorator");var c=p(n);return c&&n.constructor.hasOwnProperty("serializeInfo")||(c=h(n.constructor,{},o)),c&&c.targetClass!==n.constructor&&(c=h(n.constructor,{},o)),c.props[r]=e,!i||i.get||i.set||(i.writable=!0),i}function O(e,n){t(1===arguments.length||2===arguments.length,"serialize expects one or 2 arguments");var r=null!=n?n:e,i=n&&e;if(Array.isArray(r)){if(0===r.length)return[];i?"object"!=typeof i&&(i=p(i)):i=p(r[0])}else i?"object"!=typeof i&&(i=p(i)):i=p(r);var o=i;return t(o,"Failed to find default schema for "+e),Array.isArray(r)?r.map((function(e){return w(o,e)})):w(o,r)}function w(e,n){var r;return t(e&&"object"==typeof e&&e.props,"Expected schema"),t(n&&"object"==typeof n,"Expected object"),r=e["extends"]?w(e["extends"],n):{},Object.keys(e.props).forEach((function(t){var i=e.props[t];if(i)if("*"!==t){!0===i&&(i=j);var u=i.serializer(n[t],t,n);u!==b&&(r[i.jsonname||t]=u)}else!function(e,n,t,r){for(var i=0,u=Object.keys(t);i<u.length;i++){var f=u[i];if(!(f in e.props)&&(!0===n||n&&(!n.pattern||n.pattern.test(f)))){var a=t[f];if(!0===n)o(a)&&(r[f]=a);else{var c=n.serializer(a,f,t);if(c===b)return;r[f]=c}}}}(e,i,n,r)})),r}var A=new WeakMap,k=function(){function e(e,n,t,r,i){this.parentContext=e,this.modelSchema=n,this.json=t,this.onReadyCb=r,this.isRoot=!e,this.pendingCallbacks=0,this.pendingRefsCount=0,this.target=undefined,this.hasError=!1,e?(this.rootContext=e.rootContext,this.args=e.args):(this.rootContext=this,this.args=i,this.pendingRefs={},this.resolvedRefs={})}return e.prototype.createCallback=function(e){var n=this;return this.pendingCallbacks++,function(e){var n=!1;return function(){if(!n)return n=!0,e.apply(null,arguments);t(!1,"callback was invoked twice")}}((function(t,r){t?n.hasError||(n.hasError=!0,n.onReadyCb(t),A["delete"](n)):n.hasError||(e(r),--n.pendingCallbacks===n.pendingRefsCount&&(n.pendingRefsCount>0?(n.onReadyCb(Error('Unresolvable references in json: "'+Object.keys(n.pendingRefs).filter((function(e){return n.pendingRefs[e].length>0})).join('", "')+'"')),A["delete"](n)):(n.onReadyCb(null,n.target),A["delete"](n))))}))},e.prototype.await=function(e,n,r){if(t(this.isRoot,"await can only be called on the root context"),n in this.resolvedRefs){var i=this.resolvedRefs[n].filter((function(n){return s(n.modelSchema,e)}))[0];if(i)return void r(null,i.value)}this.pendingRefsCount++,this.pendingRefs[n]||(this.pendingRefs[n]=[]),this.pendingRefs[n].push({modelSchema:e,uuid:n,callback:r})},e.prototype.resolve=function(e,n,r){if(t(this.isRoot,"resolve can only called on the root context"),this.resolvedRefs[n]||(this.resolvedRefs[n]=[]),this.resolvedRefs[n].push({modelSchema:e,value:r}),n in this.pendingRefs)for(var i=this.pendingRefs[n].length-1;i>=0;i--){var o=this.pendingRefs[n][i];s(e,o.modelSchema)&&(this.pendingRefs[n].splice(i,1),this.pendingRefsCount--,o.callback(null,r))}},e.prototype.setTarget=function(e){this.isRoot&&this.target&&A["delete"](this.target),this.target=e,A.set(this.target,this)},e.prototype.cancelAwaits=function(){t(this.isRoot,"cancelAwaits can only be called on the root context");var e=this;Object.keys(this.pendingRefs).forEach((function(n){e.pendingRefs[n].forEach((function(t){e.pendingRefsCount--,t.callback(Error("Reference resolution canceled for "+n))}))})),this.pendingRefs={},this.pendingRefsCount=0},e}();function E(e,n,i,o,u){if(null!==i&&i!==undefined&&"object"==typeof i){var f=new k(e,n,i,o,u),a=n.factory(f);t(!!a,"No object returned from factory"),f.setTarget(a);var c=f.createCallback(r);return N(f,n,i,a),c(),a}o(null,null)}function N(e,n,r,i){var u;n["extends"]&&N(e,n["extends"],r,i);for(var f=function(f){var a=n.props[f];if(!a)return{value:void 0};if("*"===f)return function(e,n,r,i,u){var f=function(f){if(!(f in n.props||function(e,n){for(var t in e.props){var r=e.props[t];if("object"==typeof r&&r.jsonname===n)return!0}return!1}(n,f))){var a=u[f];!0===r?(t(o(a),"encountered non primitive value while deserializing '*' properties in property '"+f+"': "+a),i[f]=a):!r||r.pattern&&!r.pattern.test(f)||r.deserializer(a,e.rootContext.createCallback((function(e){return e!==b&&(i[f]=e)})),e)}};for(var a in u)f(a)}(e,n,a,i,r),{value:void 0};!0===a&&(a=j);var c=null!=(u=a.jsonname)?u:f;t("symbol"!=typeof c,"You must alias symbol properties. prop = %l",f);var s=r[c],l=a;D((function(n,t){n||t===undefined||function(n,t,o){var u=e.rootContext.createCallback((function(e){return e!==b&&(i[o]=e)}));n.deserializer(t,(function(i,f){return I(u,i,f,t,r,o,e,n)}),e,i[o])}(l,t,f)}),s,r,c,e,a)},a=0,c=Object.keys(n.props);a<c.length;a++){var s=f(c[a]);if("object"==typeof s)return s.value}}var D=function(e,n,t,r,i,o){o&&"function"==typeof o.beforeDeserialize?o.beforeDeserialize(e,n,t,r,i,o):e(null,n)},I=function(e,n,t,r,i,o,u,f){f&&"function"==typeof f.afterDeserialize?f.afterDeserialize(e,n,t,r,i,o,u,f):e(n,t)};function M(e,n){return t("object"==typeof e||"function"==typeof e,"No modelschema provided. If you are importing it from another file be aware of circular dependencies."),d({serializer:function(n){return t(u(e=p(e)),"expected modelSchema, got "+e),null===n||n===undefined?n:O(e,n)},deserializer:function(n,r,i){t(u(e=p(e)),"expected modelSchema, got "+e),null!==n&&n!==undefined?E(i,e,n,r,undefined):r(null,n)}},n)}function J(e,n){return t(f(e=e||j),"expected prop schema as first argument"),t(!a(e),"provided prop is aliased, please put aliases first"),d({serializer:function(n){return n===undefined?b:(t(n&&"length"in n&&"map"in n,"expected array (like) object"),n.map(e.serializer))},deserializer:function(n,t,r){Array.isArray(n)?i(n,(function(t,i,o){function u(u,f){"function"==typeof e.afterDeserialize?I(i,u,f,t,n,o,r,e):i(u,f)}D((function(n,t){n?i(n):e.deserializer(t,u,r)}),t,n,o,r,e)}),(function(e,n){e?t(e):t(undefined,n.filter((function(e){return b!==e})))})):t("[serializr] expected JSON array")}},n)}e.SKIP=b,e.alias=function(e,n){return t(e&&"string"==typeof e,"expected prop name as first argument"),t(f(n=n&&!0!==n?n:j),"expected prop schema as second argument"),t(!a(n),"provided prop is already aliased"),{jsonname:e,serializer:n.serializer,deserializer:n.deserializer,identifier:c(n)||undefined,beforeDeserialize:n.beforeDeserialize,afterDeserialize:n.afterDeserialize}},e.cancelDeserialize=function(e){t("object"==typeof e&&e&&!Array.isArray(e),"cancelDeserialize needs an object");var n,r=(n=e,A.get(n));r&&r.cancelAwaits()},e.createModelSchema=h,e.createSimpleSchema=function(e){return{factory:function(){return{}},props:e}},e.custom=function(e,n,r){return t("function"==typeof e,"first argument should be function"),t("function"==typeof n,"second argument should be a function or promise"),d({serializer:e,deserializer:function(e,t,r,i){var o=n(e,r,i,t);4!==n.length&&t(null,o)}},r)},e.date=function(e){return d({serializer:function(e){return null===e||e===undefined?e:(t(e instanceof Date,"Expected Date object"),e.getTime())},deserializer:function(e,n){null!==e&&e!==undefined?n(null,new Date(e)):n(null,e)}},e)},e.deserialize=function(e,n,o,f){void 0===o&&(o=r),t(arguments.length>=2,"deserialize expects at least 2 arguments");var a=p(e);if(t(u(a),"first argument should be model schema"),Array.isArray(n)){var c=[];return i(n,(function(e,n){var t=E(undefined,a,e,n,f);c.push(t)}),o),c}return E(undefined,a,n,o,f)},e.getDefaultModelSchema=p,e.identifier=function(e,n){var r,i;return"function"==typeof e?(r=e,i=n):i=e,t(!i||"object"==typeof i,"Additional property arguments should be an object, register function should be omitted or a funtion"),d({identifier:!0,serializer:j.serializer,deserializer:function(e,n,t){j.deserializer(e,(function(e,i){!function(e,n,t){t.rootContext.resolve(t.modelSchema,e,t.target)}(i,t.target,t),r&&r(i,t.target,t),n(e,i)}),t)}},i)},e.list=J,e.map=function(e,n){return t(f(e=e||j),"expected prop schema as first argument"),t(!a(e),"provided prop is aliased, please put aliases first"),d({serializer:function(n){t(n&&"object"==typeof n,"expected object or Map");var r={};if(l(n))n.forEach((function(t,i){return r[i]=e.serializer(t,i,n)}));else for(var i in n)r[i]=e.serializer(n[i],i,n);return r},deserializer:function(t,r,i,o){if(t&&"object"==typeof t){var u=Object.keys(t);J(e,n).deserializer(u.map((function(e){return t[e]})),(function(e,n){if(e)r(e);else{var t,i=l(o);i?(o.clear(),t=o):t={};for(var f=0,a=u.length;f<a;f++)i?t.set(u[f],n[f]):t[u[f]]=n[f];r(null,t)}}),i)}else r("[serializr] expected JSON object")}},n)},e.mapAsArray=function(e,n,r){return t(f(e=e||j),"expected prop schema as first argument"),t(!!n,"expected key property name as second argument"),d({serializer:function(n){t(n&&"object"==typeof n,"expected object or Map");var r=[];if(l(n))n.forEach((function(t,i){return r.push(e.serializer(t,i,n))}));else for(var i in n)r.push(e.serializer(n[i],i,n));return r},deserializer:function(t,i,o,u){J(e,r).deserializer(t,(function(e,r){if(e)i(e);else{var o,f=l(u);f?(u.clear(),o=u):o={};for(var a=0,c=t.length;a<c;a++)f?o.set(r[a][n],r[a]):o[r[a][n].toString()]=r[a];i(null,o)}}),o,undefined)}},r)},e.object=M,e.optional=function(e){t(f(e=e&&!0!==e?e:j),"expected prop schema as second argument");var n=e.serializer;return t("function"==typeof n,"expected prop schema to have a callable serializer"),Object.assign({},e,{serializer:function(e,t,r){var i=n(e,t,r);return i===undefined?b:i}})},e.primitive=y,e.raw=function(e){return d({serializer:function(e){return e},deserializer:function(e,n){n(null,e)}},e)},e.reference=function(e,n,r){t(!!e,"No modelSchema provided. If you are importing it from another file be aware of circular dependencies.");var i="function"==typeof n?n:undefined;r=r||(i?undefined:n);var o,f=!1;function a(){if(f=!0,t("string"!=typeof e||"function"==typeof i,"if the reference target is specified by attribute name, a lookup function is required"),t(!i||"function"==typeof i,"second argument should be a lookup function or additional arguments object"),"string"==typeof e)o=e;else{var n=p(e);t(u(n),"expected model schema or string as first argument for 'ref', got "+n),i=i||function(e){return function(n,t,r){r.rootContext.await(e,n,t)}}(n),o=function(e){t(u(e),"modelSchema must be a ModelSchema");for(var n=e;n;){for(var r in n.props)if(c(n.props[r]))return r;n=n["extends"]}return undefined}(n),t(!!o,"provided model schema doesn't define an identifier() property and cannot be used by 'ref'.")}}return d({serializer:function(e){return f||a(),e?e[o]:null},deserializer:function(e,n,t){f||a(),null===e||e===undefined?n(null,e):i(e,n,t)}},r)},e.serializable=function(e,n,r){if(!n){var i=!0===e?j:e;return t(f(i),"@serializable expects prop schema"),S.bind(null,i)}S(y(),e,n,r)},e.serialize=O,e.serializeAll=function(e,n){var r;if(1===arguments.length)return r=!0,i(e);function i(e){t("function"==typeof e,"@serializeAll can only be used as class decorator");var n=p(e);return n||v(e,n=h(e,{})),n.props["*"]=r,e}return t("object"==typeof e&&e.test,"@serializeAll pattern doesn't have test"),"function"==typeof n&&(n=M(n)),!0===n&&(n=j),t(f(n),"couldn't resolve schema"),r=Object.assign({},n,{pattern:e}),i},e.setDefaultModelSchema=v,e.update=function(e,n,i,o,f){var a=2===arguments.length||"function"==typeof arguments[2];a?(e=p(n=arguments[0]),i=arguments[1],o=arguments[2],f=arguments[3]):e=p(e),t(u(e),"update failed to determine schema"),t("object"==typeof n&&n&&!Array.isArray(n),"update needs an object");var c=new k(undefined,e,i,o||r,f);c.setTarget(n);var s=c.createCallback(r),l=N(c,e,i,n);return s(),l},Object.defineProperty(e,"t",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).serializr={});
//# sourceMappingURL=serializr.min.js.map
{
"name": "serializr",
"version": "2.0.1",
"version": "2.0.2",
"description": "Serialize and deserialize complex object graphs to JSON",

@@ -5,0 +5,0 @@ "main": "lib/serializr.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc