Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

serializr

Package Overview
Dependencies
Maintainers
1
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 1.1.2 to 1.1.3

4

CHANGELOG.md

@@ -1,4 +0,4 @@

# 1.1.2
# 1.1.2 / 1.1.3
* Attempt to fix UMD issue
* Fixed UMD build issues

@@ -5,0 +5,0 @@ # 1.1.1

{
"name": "serializr",
"version": "1.1.2",
"version": "1.1.3",
"description": "Serialize and deserialize complex object graphs to JSON",

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

@@ -991,6 +991,6 @@ (function(g) {

} else if (typeof define === "function" && define.amd) {
define("serializer", [], mrFactory)
define("serializr", [], mrFactory)
} else {
g.serializer = mrFactory()
g.serializr = mrFactory()
}
})(function() { return this }())
/** serializr - (c) Michel Weststrate 2016 - MIT Licensed */
!function(e){"use strict";function r(){function e(e){if(e)throw new Error(e)}function r(e){var r=!1;return function(){return r?void t(!1,"callback was invoked twice"):(r=!0,e.apply(null,arguments))}}function t(e,r){if(!e)throw new Error("[serializr] "+(r||"Illegal State"))}function n(e,r,t){if(0===e.length)return void t(null,[]);var n=e.length,i=[],o=!1,s=function(e,r,s){r?o||(o=!0,t(r)):(i[e]=s,0===--n&&t(null,i))};e.forEach(function(e,t){r(e,s.bind(null,t))})}function i(e){return null===e||"object"!=typeof e&&"function"!=typeof e}function o(e){return{factory:function(){return{}},props:e}}function s(e,r,n){t(e!==Object,"one cannot simply put define a model schema for Object"),t("function"==typeof e,"expected constructor function");var i={targetClass:e,factory:n||function(){return new e},props:r};if(e.prototype.constructor!==Object){var o=c(e.prototype.constructor);o&&o.targetClass!==e&&(i.extends=o)}return l(e,i),i}function a(e,r,n){if(1===arguments.length){var i=e===!0?T:e;return t(p(i),"@serializable expects prop schema"),u.bind(null,i)}return u(S(),e,r,n)}function u(e,r,n,i){t(arguments.length>=2,"too few arguments. Please use @serializable as property decorator"),t("string"==typeof n,"incorrect usage of @serializable decorator");var o=c(r);return o&&r.constructor.hasOwnProperty("serializeInfo")||(o=s(r.constructor,{})),o&&o.targetClass!==r.constructor&&(o=s(r.constructor,{})),o.props[n]=e,!i||i.get||i.set||(i.writable=!0),i}function c(e){return e?f(e)?e:f(e.serializeInfo)?e.serializeInfo:e.constructor&&e.constructor.serializeInfo?e.constructor.serializeInfo:void 0:null}function l(e,r){return t(f(r)),e.serializeInfo=r}function f(e){return e&&e.factory&&e.props}function p(e){return e&&e.serializer&&e.deserializer}function d(e){return"object"==typeof e&&!!e.jsonname}function h(e){return"object"==typeof e&&e.identifier===!0}function v(e){for(t(f(e));e;){for(var r in e.props)if("object"==typeof e.props[r]&&e.props[r].identifier===!0)return r;e=e.extends}return null}function m(e,r){for(;e;){if(e===r)return!0;e=e.extends}return!1}function g(e,r){t(1===arguments.length||2===arguments.length,"serialize expects one or 2 arguments");var n=1===arguments.length?e:r,i=1===arguments.length?null:e;if(Array.isArray(n)){if(0===n.length)return[];i||(i=c(n[0]))}else i||(i=c(n));return t(!!i,"Failed to find default schema for "+e),Array.isArray(n)?n.map(function(e){return y(i,e)}):y(i,n)}function y(e,r){t(e&&"object"==typeof e,"Expected schema"),t(r&&"object"==typeof r,"Expected object");var n;return n=e.extends?y(e.extends,r):{},Object.keys(e.props).forEach(function(i){var o=e.props[i];if("*"===i)return t(o===!0,"prop schema '*' can onle be used with 'true'"),void b(e,r,n);if(o===!0&&(o=T),o!==!1){var s=o.serializer(r[i]);n[o.jsonname||i]=s}}),n}function b(e,r,n){for(var o in r)if(r.hasOwnProperty(o)&&!(o in e.props)){var s=r[o];t(i(s),"encountered non primitive value while serializing '*' properties in property '"+o+"': "+s),n[o]=s}}function z(r,i,o,s){if(t(arguments.length>=2,"deserialize expects at least 2 arguments"),r=c(r),t(f(r),"first argument should be model schema"),Array.isArray(i)){var a=[];return n(i,function(e,t){var n=j(null,r,e,t,s);a.push(n)},o||e),a}return j(null,r,i,o,s)}function j(r,n,i,o,s){if(null===i||void 0===i)return void o(null,null);var a=new w(r,n,i,o,s),u=n.factory(a);t(!!u,"No object returned from factory"),a.target=u;var c=a.createCallback(e);return x(a,n,i,u),c(),u}function x(e,r,n,i){r.extends&&x(e,r.extends,n,i),Object.keys(r.props).forEach(function(o){var s=r.props[o];if("*"===o)return t(s===!0,"prop schema '*' can onle be used with 'true'"),void C(r,i,n);if(s===!0&&(s=T),s!==!1){var a=s.jsonname||o;a in n&&s.deserializer(n[a],e.rootContext.createCallback(function(e){i[o]=e}),e,i[o])}})}function R(e,r){for(var t in e.props)if("object"==typeof e.props[t]&&e.props[t].jsonname===r)return!0;return!1}function C(e,r,n){for(var o in n)if(!(o in e.props||R(e,o))){var s=n[o];t(i(s),"encountered non primitive value while deserializing '*' properties in property '"+o+"': "+s),r[o]=s}}function w(r,t,n,i,o){this.parentContext=r,this.isRoot=!r,this.pendingCallbacks=0,this.pendingRefsCount=0,this.onReadyCb=i||e,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=r,this.args=r.args)}function k(r,n,i,o,s){var a=2===arguments.length||"function"==typeof arguments[2];a&&(n=arguments[0],r=c(n),i=arguments[1],o=arguments[2],s=arguments[2]),t(f(r),"update failed to determine schema"),t("object"==typeof n&&n&&!Array.isArray(n),"update needs an object");var u=new w(null,r,i,o,s);u.target=n;var l=u.createCallback(e);x(u,r,i,n),l()}function S(){return{serializer:function(e){return t(i(e),"this value is not primitive: "+e),e},deserializer:function(e,r){return i(e)?void r(null,e):void r("[serializr] this value is not primitive: "+e)}}}function E(e){return t(!e||"function"==typeof e,"First argument should be ommitted or function"),{identifier:!0,serializer:T.serializer,deserializer:function(r,t,n){T.deserializer(r,function(r,i){O(i,n.target,n),e&&e(i,n.target,n),t(r,i)})}}}function O(e,r,t){t.rootContext.resolve(t.modelSchema,e,t.target)}function A(){return{serializer:function(e){return null===e||void 0===e?e:(t(e instanceof Date,"Expected Date object"),e.getTime())},deserializer:function(e,r){return null===e||void 0===e?void r(null,e):void r(null,new Date(e))}}}function I(e,r){return t(e&&"string"==typeof e,"expected prop name as first argument"),r=r&&r!==!0?r:T,t(p(r),"expected prop schema as second argument"),t(!d(r),"provided prop is already aliased"),{jsonname:e,serializer:r.serializer,deserializer:r.deserializer,identifier:h(r)}}function D(e,r){return t("function"==typeof e,"first argument should be function"),t("function"==typeof r,"second argument should be function"),{serializer:e,deserializer:function(e,t){t(null,r(e))}}}function N(e){return t("object"==typeof e||"function"==typeof e,"No modelschema provided. If you are importing it from another file be aware of circular dependencies."),{serializer:function(r){return e=c(e),t(f(e),"expected modelSchema, got "+e),null===r||void 0===r?r:g(e,r)},deserializer:function(r,n,i){return e=c(e),t(f(e),"expected modelSchema, got "+e),null===r||void 0===r?void n(null,r):void j(i,e,r,n)}}}function M(e,r){function n(){if(o=!0,t("string"!=typeof e||r,"if the reference target is specified by attribute name, a lookup function is required"),t(!r||"function"==typeof r,"second argument should be a lookup function"),"string"==typeof e)i=e;else{var n=c(e);t(f(n),"expected model schema or string as first argument for 'ref', got "+n),r=r||P(n),i=v(n),t(!!i,"provided model schema doesn't define an identifier() property and cannot be used by 'ref'.")}}t(!!e,"No modelschema provided. If you are importing it from another file be aware of circular dependencies.");var i,o=!1;return{serializer:function(e){return o||n(),e?e[i]:null},deserializer:function(e,t,i){o||n(),null===e||void 0===e?t(null,e):r(e,t,i)}}}function P(e){return function(r,t,n){n.rootContext.await(e,r,t)}}function F(e){return e=e||T,t(p(e),"expected prop schema as second argument"),t(!d(e),"provided prop is aliased, please put aliases first"),{serializer:function(r){return t(r&&"length"in r&&"map"in r,"expected array (like) object"),r.map(e.serializer)},deserializer:function(r,t,i){return Array.isArray(r)?void n(r,function(r,t){return e.deserializer(r,t,i)},t):void t("[serializr] expected JSON array")}}}function J(e){return e&&"function"==typeof e.keys&&"function"==typeof e.clear}function q(e){return e=e||T,t(p(e),"expected prop schema as second argument"),t(!d(e),"provided prop is aliased, please put aliases first"),{serializer:function(r){t(r&&"object"==typeof r,"expected object or Map");var n=J(r),i={};if(n)r.forEach(function(r,t){i[t]=e.serializer(r)});else for(var o in r)i[o]=e.serializer(r[o]);return i},deserializer:function(r,t,n,i){if(!r||"object"!=typeof r)return void t("[serializr] expected JSON object");var o=Object.keys(r);F(e).deserializer(o.map(function(e){return r[e]}),function(e,r){if(e)return void t(e);var n,s=J(i);s?(i.clear(),n=i):n={};for(var a=0,u=o.length;a<u;a++)s?n.set(o[a],r[a]):n[o[a]]=r[a];t(null,n)},n)}}}w.prototype.createCallback=function(e){return this.pendingCallbacks++,r(function(r,t){r?this.hasError||(this.hasError=!0,this.onReadyCb(r)):this.hasError||(e(t),--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('", "')+'"')):this.onReadyCb(null,this.target)))}.bind(this))},w.prototype.await=function(e,r,n){if(t(this.isRoot),r in this.resolvedRefs){var i=this.resolvedRefs[r].filter(function(r){return m(r.modelSchema,e)})[0];if(i)return void n(null,i.value)}this.pendingRefsCount++,this.pendingRefs[r]||(this.pendingRefs[r]=[]),this.pendingRefs[r].push({modelSchema:e,uuid:r,callback:n})},w.prototype.resolve=function(e,r,n){if(t(this.isRoot),this.resolvedRefs[r]||(this.resolvedRefs[r]=[]),this.resolvedRefs[r].push({modelSchema:e,value:n}),r in this.pendingRefs)for(var i=this.pendingRefs[r].length-1;i>=0;i--){var o=this.pendingRefs[r][i];m(e,o.modelSchema)&&(this.pendingRefs[r].splice(i,1),this.pendingRefsCount--,o.callback(null,n))}};var T=S();return{createModelSchema:s,createSimpleSchema:o,setDefaultModelSchema:c,getDefaultModelSchema:c,serializable:a,serialize:g,deserialize:z,update:k,primitive:S,identifier:E,date:A,alias:I,list:F,map:q,object:N,child:N,reference:M,ref:M,custom:D}}"object"==typeof exports?module.exports=r():"function"==typeof define&&define.amd?define("serializer",[],r):e.serializer=r()}(function(){return this}());
!function(e){"use strict";function r(){function e(e){if(e)throw new Error(e)}function r(e){var r=!1;return function(){return r?void t(!1,"callback was invoked twice"):(r=!0,e.apply(null,arguments))}}function t(e,r){if(!e)throw new Error("[serializr] "+(r||"Illegal State"))}function n(e,r,t){if(0===e.length)return void t(null,[]);var n=e.length,i=[],o=!1,s=function(e,r,s){r?o||(o=!0,t(r)):(i[e]=s,0===--n&&t(null,i))};e.forEach(function(e,t){r(e,s.bind(null,t))})}function i(e){return null===e||"object"!=typeof e&&"function"!=typeof e}function o(e){return{factory:function(){return{}},props:e}}function s(e,r,n){t(e!==Object,"one cannot simply put define a model schema for Object"),t("function"==typeof e,"expected constructor function");var i={targetClass:e,factory:n||function(){return new e},props:r};if(e.prototype.constructor!==Object){var o=c(e.prototype.constructor);o&&o.targetClass!==e&&(i.extends=o)}return l(e,i),i}function a(e,r,n){if(1===arguments.length){var i=e===!0?T:e;return t(p(i),"@serializable expects prop schema"),u.bind(null,i)}return u(S(),e,r,n)}function u(e,r,n,i){t(arguments.length>=2,"too few arguments. Please use @serializable as property decorator"),t("string"==typeof n,"incorrect usage of @serializable decorator");var o=c(r);return o&&r.constructor.hasOwnProperty("serializeInfo")||(o=s(r.constructor,{})),o&&o.targetClass!==r.constructor&&(o=s(r.constructor,{})),o.props[n]=e,!i||i.get||i.set||(i.writable=!0),i}function c(e){return e?f(e)?e:f(e.serializeInfo)?e.serializeInfo:e.constructor&&e.constructor.serializeInfo?e.constructor.serializeInfo:void 0:null}function l(e,r){return t(f(r)),e.serializeInfo=r}function f(e){return e&&e.factory&&e.props}function p(e){return e&&e.serializer&&e.deserializer}function d(e){return"object"==typeof e&&!!e.jsonname}function h(e){return"object"==typeof e&&e.identifier===!0}function v(e){for(t(f(e));e;){for(var r in e.props)if("object"==typeof e.props[r]&&e.props[r].identifier===!0)return r;e=e.extends}return null}function m(e,r){for(;e;){if(e===r)return!0;e=e.extends}return!1}function g(e,r){t(1===arguments.length||2===arguments.length,"serialize expects one or 2 arguments");var n=1===arguments.length?e:r,i=1===arguments.length?null:e;if(Array.isArray(n)){if(0===n.length)return[];i||(i=c(n[0]))}else i||(i=c(n));return t(!!i,"Failed to find default schema for "+e),Array.isArray(n)?n.map(function(e){return y(i,e)}):y(i,n)}function y(e,r){t(e&&"object"==typeof e,"Expected schema"),t(r&&"object"==typeof r,"Expected object");var n;return n=e.extends?y(e.extends,r):{},Object.keys(e.props).forEach(function(i){var o=e.props[i];if("*"===i)return t(o===!0,"prop schema '*' can onle be used with 'true'"),void b(e,r,n);if(o===!0&&(o=T),o!==!1){var s=o.serializer(r[i]);n[o.jsonname||i]=s}}),n}function b(e,r,n){for(var o in r)if(r.hasOwnProperty(o)&&!(o in e.props)){var s=r[o];t(i(s),"encountered non primitive value while serializing '*' properties in property '"+o+"': "+s),n[o]=s}}function z(r,i,o,s){if(t(arguments.length>=2,"deserialize expects at least 2 arguments"),r=c(r),t(f(r),"first argument should be model schema"),Array.isArray(i)){var a=[];return n(i,function(e,t){var n=j(null,r,e,t,s);a.push(n)},o||e),a}return j(null,r,i,o,s)}function j(r,n,i,o,s){if(null===i||void 0===i)return void o(null,null);var a=new w(r,n,i,o,s),u=n.factory(a);t(!!u,"No object returned from factory"),a.target=u;var c=a.createCallback(e);return x(a,n,i,u),c(),u}function x(e,r,n,i){r.extends&&x(e,r.extends,n,i),Object.keys(r.props).forEach(function(o){var s=r.props[o];if("*"===o)return t(s===!0,"prop schema '*' can onle be used with 'true'"),void C(r,i,n);if(s===!0&&(s=T),s!==!1){var a=s.jsonname||o;a in n&&s.deserializer(n[a],e.rootContext.createCallback(function(e){i[o]=e}),e,i[o])}})}function R(e,r){for(var t in e.props)if("object"==typeof e.props[t]&&e.props[t].jsonname===r)return!0;return!1}function C(e,r,n){for(var o in n)if(!(o in e.props||R(e,o))){var s=n[o];t(i(s),"encountered non primitive value while deserializing '*' properties in property '"+o+"': "+s),r[o]=s}}function w(r,t,n,i,o){this.parentContext=r,this.isRoot=!r,this.pendingCallbacks=0,this.pendingRefsCount=0,this.onReadyCb=i||e,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=r,this.args=r.args)}function k(r,n,i,o,s){var a=2===arguments.length||"function"==typeof arguments[2];a&&(n=arguments[0],r=c(n),i=arguments[1],o=arguments[2],s=arguments[2]),t(f(r),"update failed to determine schema"),t("object"==typeof n&&n&&!Array.isArray(n),"update needs an object");var u=new w(null,r,i,o,s);u.target=n;var l=u.createCallback(e);x(u,r,i,n),l()}function S(){return{serializer:function(e){return t(i(e),"this value is not primitive: "+e),e},deserializer:function(e,r){return i(e)?void r(null,e):void r("[serializr] this value is not primitive: "+e)}}}function E(e){return t(!e||"function"==typeof e,"First argument should be ommitted or function"),{identifier:!0,serializer:T.serializer,deserializer:function(r,t,n){T.deserializer(r,function(r,i){O(i,n.target,n),e&&e(i,n.target,n),t(r,i)})}}}function O(e,r,t){t.rootContext.resolve(t.modelSchema,e,t.target)}function A(){return{serializer:function(e){return null===e||void 0===e?e:(t(e instanceof Date,"Expected Date object"),e.getTime())},deserializer:function(e,r){return null===e||void 0===e?void r(null,e):void r(null,new Date(e))}}}function I(e,r){return t(e&&"string"==typeof e,"expected prop name as first argument"),r=r&&r!==!0?r:T,t(p(r),"expected prop schema as second argument"),t(!d(r),"provided prop is already aliased"),{jsonname:e,serializer:r.serializer,deserializer:r.deserializer,identifier:h(r)}}function D(e,r){return t("function"==typeof e,"first argument should be function"),t("function"==typeof r,"second argument should be function"),{serializer:e,deserializer:function(e,t){t(null,r(e))}}}function N(e){return t("object"==typeof e||"function"==typeof e,"No modelschema provided. If you are importing it from another file be aware of circular dependencies."),{serializer:function(r){return e=c(e),t(f(e),"expected modelSchema, got "+e),null===r||void 0===r?r:g(e,r)},deserializer:function(r,n,i){return e=c(e),t(f(e),"expected modelSchema, got "+e),null===r||void 0===r?void n(null,r):void j(i,e,r,n)}}}function M(e,r){function n(){if(o=!0,t("string"!=typeof e||r,"if the reference target is specified by attribute name, a lookup function is required"),t(!r||"function"==typeof r,"second argument should be a lookup function"),"string"==typeof e)i=e;else{var n=c(e);t(f(n),"expected model schema or string as first argument for 'ref', got "+n),r=r||P(n),i=v(n),t(!!i,"provided model schema doesn't define an identifier() property and cannot be used by 'ref'.")}}t(!!e,"No modelschema provided. If you are importing it from another file be aware of circular dependencies.");var i,o=!1;return{serializer:function(e){return o||n(),e?e[i]:null},deserializer:function(e,t,i){o||n(),null===e||void 0===e?t(null,e):r(e,t,i)}}}function P(e){return function(r,t,n){n.rootContext.await(e,r,t)}}function F(e){return e=e||T,t(p(e),"expected prop schema as second argument"),t(!d(e),"provided prop is aliased, please put aliases first"),{serializer:function(r){return t(r&&"length"in r&&"map"in r,"expected array (like) object"),r.map(e.serializer)},deserializer:function(r,t,i){return Array.isArray(r)?void n(r,function(r,t){return e.deserializer(r,t,i)},t):void t("[serializr] expected JSON array")}}}function J(e){return e&&"function"==typeof e.keys&&"function"==typeof e.clear}function q(e){return e=e||T,t(p(e),"expected prop schema as second argument"),t(!d(e),"provided prop is aliased, please put aliases first"),{serializer:function(r){t(r&&"object"==typeof r,"expected object or Map");var n=J(r),i={};if(n)r.forEach(function(r,t){i[t]=e.serializer(r)});else for(var o in r)i[o]=e.serializer(r[o]);return i},deserializer:function(r,t,n,i){if(!r||"object"!=typeof r)return void t("[serializr] expected JSON object");var o=Object.keys(r);F(e).deserializer(o.map(function(e){return r[e]}),function(e,r){if(e)return void t(e);var n,s=J(i);s?(i.clear(),n=i):n={};for(var a=0,u=o.length;a<u;a++)s?n.set(o[a],r[a]):n[o[a]]=r[a];t(null,n)},n)}}}w.prototype.createCallback=function(e){return this.pendingCallbacks++,r(function(r,t){r?this.hasError||(this.hasError=!0,this.onReadyCb(r)):this.hasError||(e(t),--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('", "')+'"')):this.onReadyCb(null,this.target)))}.bind(this))},w.prototype.await=function(e,r,n){if(t(this.isRoot),r in this.resolvedRefs){var i=this.resolvedRefs[r].filter(function(r){return m(r.modelSchema,e)})[0];if(i)return void n(null,i.value)}this.pendingRefsCount++,this.pendingRefs[r]||(this.pendingRefs[r]=[]),this.pendingRefs[r].push({modelSchema:e,uuid:r,callback:n})},w.prototype.resolve=function(e,r,n){if(t(this.isRoot),this.resolvedRefs[r]||(this.resolvedRefs[r]=[]),this.resolvedRefs[r].push({modelSchema:e,value:n}),r in this.pendingRefs)for(var i=this.pendingRefs[r].length-1;i>=0;i--){var o=this.pendingRefs[r][i];m(e,o.modelSchema)&&(this.pendingRefs[r].splice(i,1),this.pendingRefsCount--,o.callback(null,n))}};var T=S();return{createModelSchema:s,createSimpleSchema:o,setDefaultModelSchema:c,getDefaultModelSchema:c,serializable:a,serialize:g,deserialize:z,update:k,primitive:S,identifier:E,date:A,alias:I,list:F,map:q,object:N,child:N,reference:M,ref:M,custom:D}}"object"==typeof exports?module.exports=r():"function"==typeof define&&define.amd?define("serializr",[],r):e.serializr=r()}(function(){return this}());
//# sourceMappingURL=serializr.min.js.map

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