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

normalizr

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

normalizr - npm Package Compare versions

Comparing version 3.5.0 to 3.6.0

5

CHANGELOG.md

@@ -0,1 +1,6 @@

# v3.6.0
* **Added** `fallbackStrategy` for denormalization (#422)
* **Fixed** entities can be `undefined` in TS defs if none found (#435)
# v3.5.0

@@ -2,0 +7,0 @@

15

dist/normalizr.amd.js

@@ -115,3 +115,7 @@ define(['exports'], function (exports) { 'use strict';

return _extends({}, input);
} : _options$processStrat;
} : _options$processStrat,
_options$fallbackStra = _options.fallbackStrategy,
fallbackStrategy = _options$fallbackStra === void 0 ? function (key, schema) {
return undefined;
} : _options$fallbackStra;
this._key = key;

@@ -122,2 +126,3 @@ this._getId = typeof idAttribute === 'function' ? idAttribute : getDefaultGetId(idAttribute);

this._processStrategy = processStrategy;
this._fallbackStrategy = fallbackStrategy;
this.define(definition);

@@ -145,2 +150,6 @@ }

_proto.fallback = function fallback(id, schema) {
return this._fallbackStrategy(id, schema);
};
_proto.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {

@@ -533,2 +542,6 @@ var _this = this;

if (entity === undefined && schema instanceof EntitySchema) {
entity = schema.fallback(id, schema);
}
if (typeof entity !== 'object' || entity === null) {

@@ -535,0 +548,0 @@ return entity;

2

dist/normalizr.amd.min.js

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

define(["exports"],function(t){"use strict";function e(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function n(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}function r(){return(r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function i(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function o(t){return!(!t||"function"!=typeof t.hasOwnProperty||!(t.hasOwnProperty("__ownerID")||t._map&&t._map.hasOwnProperty("__ownerID")))}function u(t,e,n){return Object.keys(t).reduce(function(e,r){var i=""+r;return e.has(i)?e.set(i,n(e.get(i),t[i])):e},e)}var a=function(t){return function(e){return o(e)?e.get(t):e[t]}},c=function(){function t(t,e,n){if(void 0===e&&(e={}),void 0===n&&(n={}),!t||"string"!=typeof t)throw new Error("Expected a string key for Entity, but found "+t+".");var i=n,o=i.idAttribute,u=void 0===o?"id":o,c=i.mergeStrategy,f=void 0===c?function(t,e){return r({},t,e)}:c,s=i.processStrategy,h=void 0===s?function(t){return r({},t)}:s;this._key=t,this._getId="function"==typeof u?u:a(u),this._idAttribute=u,this._mergeStrategy=f,this._processStrategy=h,this.define(e)}var e=t.prototype;return e.define=function(t){this.schema=Object.keys(t).reduce(function(e,n){var i,o=t[n];return r({},e,((i={})[n]=o,i))},this.schema||{})},e.getId=function(t,e,n){return this._getId(t,e,n)},e.merge=function(t,e){return this._mergeStrategy(t,e)},e.normalize=function(t,e,n,r,i,o){var u=this,a=this.getId(t,e,n),c=this.key;if(c in o||(o[c]={}),a in o[c]||(o[c][a]=[]),o[c][a].some(function(e){return e===t}))return a;o[c][a].push(t);var f=this._processStrategy(t,e,n);return Object.keys(this.schema).forEach(function(e){if(f.hasOwnProperty(e)&&"object"==typeof f[e]){var n=u.schema[e],a="function"==typeof n?n(t):n;f[e]=r(f[e],f,e,a,i,o)}}),i(this,f,t,e,n),a},e.denormalize=function(t,e){var n=this;return o(t)?u(this.schema,t,e):(Object.keys(this.schema).forEach(function(r){if(t.hasOwnProperty(r)){var i=n.schema[r];t[r]=e(t[r],i)}}),t)},n(t,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),t}(),f=function(){function t(t,e){e&&(this._schemaAttribute="string"==typeof e?function(t){return t[e]}:e),this.define(t)}var e=t.prototype;return e.define=function(t){this.schema=t},e.getSchemaAttribute=function(t,e,n){return!this.isSingleSchema&&this._schemaAttribute(t,e,n)},e.inferSchema=function(t,e,n){if(this.isSingleSchema)return this.schema;var r=this.getSchemaAttribute(t,e,n);return this.schema[r]},e.normalizeValue=function(t,e,n,r,i,o){var u=this.inferSchema(t,e,n);if(!u)return t;var a=r(t,e,n,u,i,o);return this.isSingleSchema||null==a?a:{id:a,schema:this.getSchemaAttribute(t,e,n)}},e.denormalizeValue=function(t,e){var n=o(t)?t.get("schema"):t.schema;return this.isSingleSchema||n?e((this.isSingleSchema?void 0:o(t)?t.get("id"):t.id)||t,this.isSingleSchema?this.schema:this.schema[n]):t},n(t,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),t}(),s=function(t){function e(e,n){if(!n)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return t.call(this,e,n)||this}i(e,t);var n=e.prototype;return n.normalize=function(t,e,n,r,i,o){return this.normalizeValue(t,e,n,r,i,o)},n.denormalize=function(t,e){return this.denormalizeValue(t,e)},e}(f),h=function(t){function e(){return t.apply(this,arguments)||this}i(e,t);var n=e.prototype;return n.normalize=function(t,e,n,i,o,u){var a=this;return Object.keys(t).reduce(function(e,n,c){var f,s=t[n];return null!=s?r({},e,((f={})[n]=a.normalizeValue(s,t,n,i,o,u),f)):e},{})},n.denormalize=function(t,e){var n=this;return Object.keys(t).reduce(function(i,o){var u,a=t[o];return r({},i,((u={})[o]=n.denormalizeValue(a,e),u))},{})},e}(f),l=function(t){if(Array.isArray(t)&&t.length>1)throw new Error("Expected schema definition to be a single schema, but found "+t.length+".");return t[0]},y=function(t){return Array.isArray(t)?t:Object.keys(t).map(function(e){return t[e]})},m=function(t,e,n,r,i,o,u){return t=l(t),y(e).map(function(e,a){return i(e,n,r,t,o,u)})},p=function(t,e,n){return t=l(t),e&&e.map?e.map(function(e){return n(e,t)}):e},d=function(t){function e(){return t.apply(this,arguments)||this}i(e,t);var n=e.prototype;return n.normalize=function(t,e,n,r,i,o){var u=this;return y(t).map(function(t,a){return u.normalizeValue(t,e,n,r,i,o)}).filter(function(t){return null!=t})},n.denormalize=function(t,e){var n=this;return t&&t.map?t.map(function(t){return n.denormalizeValue(t,e)}):t},e}(f),v=function(t,e,n,i,o,u,a){var c=r({},e);return Object.keys(t).forEach(function(n){var r=t[n],i="function"==typeof r?r(e):r,f=o(e[n],e,n,i,u,a);null==f?delete c[n]:c[n]=f}),c},g=function(t,e,n){if(o(e))return u(t,e,n);var i=r({},e);return Object.keys(t).forEach(function(e){null!=i[e]&&(i[e]=n(i[e],t[e]))}),i},b=function t(e,n,r,i,o,u){return"object"==typeof e&&e?"object"!=typeof i||i.normalize&&"function"==typeof i.normalize?i.normalize(e,n,r,t,o,u):(Array.isArray(i)?m:v)(i,e,n,r,t,o,u):e},z={Array:d,Entity:c,Object:function(){function t(t){this.define(t)}var e=t.prototype;return e.define=function(t){this.schema=Object.keys(t).reduce(function(e,n){var i,o=t[n];return r({},e,((i={})[n]=o,i))},this.schema||{})},e.normalize=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return v.apply(void 0,[this.schema].concat(e))},e.denormalize=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return g.apply(void 0,[this.schema].concat(e))},t}(),Union:s,Values:h},k=function(t){var e={},n=S(t);return function t(i,u){return"object"!=typeof u||u.denormalize&&"function"==typeof u.denormalize?null==i?i:u instanceof c?function(t,e,n,i,u){var a=i(t,e);if("object"!=typeof a||null===a)return a;if(u[e.key]||(u[e.key]={}),!u[e.key][t]){var c=o(a)?a:r({},a);u[e.key][t]=c,u[e.key][t]=e.denormalize(c,n)}return u[e.key][t]}(i,u,t,n,e):u.denormalize(i,t):(Array.isArray(u)?p:g)(u,i,t)}},S=function(t){var e=o(t);return function(n,r){var i=r.key;return"object"==typeof n?n:e?t.getIn([i,n.toString()]):t[i]&&t[i][n]}};t.denormalize=function(t,e,n){if(void 0!==t)return k(n)(t,e)},t.normalize=function(t,e){if(!t||"object"!=typeof t)throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+(null===t?"null":typeof t)+'".');var n={},r=function(t){return function(e,n,r,i,o){var u=e.key,a=e.getId(r,i,o);u in t||(t[u]={});var c=t[u][a];t[u][a]=c?e.merge(c,n):n}}(n);return{entities:n,result:b(t,t,null,e,r,{})}},t.schema=z,Object.defineProperty(t,"__esModule",{value:!0})});
define(["exports"],function(t){"use strict";function e(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function n(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}function r(){return(r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function i(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function o(t){return!(!t||"function"!=typeof t.hasOwnProperty||!(t.hasOwnProperty("__ownerID")||t._map&&t._map.hasOwnProperty("__ownerID")))}function u(t,e,n){return Object.keys(t).reduce(function(e,r){var i=""+r;return e.has(i)?e.set(i,n(e.get(i),t[i])):e},e)}var a=function(t){return function(e){return o(e)?e.get(t):e[t]}},c=function(){function t(t,e,n){if(void 0===e&&(e={}),void 0===n&&(n={}),!t||"string"!=typeof t)throw new Error("Expected a string key for Entity, but found "+t+".");var i=n,o=i.idAttribute,u=void 0===o?"id":o,c=i.mergeStrategy,f=void 0===c?function(t,e){return r({},t,e)}:c,s=i.processStrategy,h=void 0===s?function(t){return r({},t)}:s,l=i.fallbackStrategy,y=void 0===l?function(t,e){}:l;this._key=t,this._getId="function"==typeof u?u:a(u),this._idAttribute=u,this._mergeStrategy=f,this._processStrategy=h,this._fallbackStrategy=y,this.define(e)}var e=t.prototype;return e.define=function(t){this.schema=Object.keys(t).reduce(function(e,n){var i,o=t[n];return r({},e,((i={})[n]=o,i))},this.schema||{})},e.getId=function(t,e,n){return this._getId(t,e,n)},e.merge=function(t,e){return this._mergeStrategy(t,e)},e.fallback=function(t,e){return this._fallbackStrategy(t,e)},e.normalize=function(t,e,n,r,i,o){var u=this,a=this.getId(t,e,n),c=this.key;if(c in o||(o[c]={}),a in o[c]||(o[c][a]=[]),o[c][a].some(function(e){return e===t}))return a;o[c][a].push(t);var f=this._processStrategy(t,e,n);return Object.keys(this.schema).forEach(function(e){if(f.hasOwnProperty(e)&&"object"==typeof f[e]){var n=u.schema[e],a="function"==typeof n?n(t):n;f[e]=r(f[e],f,e,a,i,o)}}),i(this,f,t,e,n),a},e.denormalize=function(t,e){var n=this;return o(t)?u(this.schema,t,e):(Object.keys(this.schema).forEach(function(r){if(t.hasOwnProperty(r)){var i=n.schema[r];t[r]=e(t[r],i)}}),t)},n(t,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),t}(),f=function(){function t(t,e){e&&(this._schemaAttribute="string"==typeof e?function(t){return t[e]}:e),this.define(t)}var e=t.prototype;return e.define=function(t){this.schema=t},e.getSchemaAttribute=function(t,e,n){return!this.isSingleSchema&&this._schemaAttribute(t,e,n)},e.inferSchema=function(t,e,n){if(this.isSingleSchema)return this.schema;var r=this.getSchemaAttribute(t,e,n);return this.schema[r]},e.normalizeValue=function(t,e,n,r,i,o){var u=this.inferSchema(t,e,n);if(!u)return t;var a=r(t,e,n,u,i,o);return this.isSingleSchema||null==a?a:{id:a,schema:this.getSchemaAttribute(t,e,n)}},e.denormalizeValue=function(t,e){var n=o(t)?t.get("schema"):t.schema;return this.isSingleSchema||n?e((this.isSingleSchema?void 0:o(t)?t.get("id"):t.id)||t,this.isSingleSchema?this.schema:this.schema[n]):t},n(t,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),t}(),s=function(t){function e(e,n){if(!n)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return t.call(this,e,n)||this}i(e,t);var n=e.prototype;return n.normalize=function(t,e,n,r,i,o){return this.normalizeValue(t,e,n,r,i,o)},n.denormalize=function(t,e){return this.denormalizeValue(t,e)},e}(f),h=function(t){function e(){return t.apply(this,arguments)||this}i(e,t);var n=e.prototype;return n.normalize=function(t,e,n,i,o,u){var a=this;return Object.keys(t).reduce(function(e,n,c){var f,s=t[n];return null!=s?r({},e,((f={})[n]=a.normalizeValue(s,t,n,i,o,u),f)):e},{})},n.denormalize=function(t,e){var n=this;return Object.keys(t).reduce(function(i,o){var u,a=t[o];return r({},i,((u={})[o]=n.denormalizeValue(a,e),u))},{})},e}(f),l=function(t){if(Array.isArray(t)&&t.length>1)throw new Error("Expected schema definition to be a single schema, but found "+t.length+".");return t[0]},y=function(t){return Array.isArray(t)?t:Object.keys(t).map(function(e){return t[e]})},m=function(t,e,n,r,i,o,u){return t=l(t),y(e).map(function(e,a){return i(e,n,r,t,o,u)})},p=function(t,e,n){return t=l(t),e&&e.map?e.map(function(e){return n(e,t)}):e},d=function(t){function e(){return t.apply(this,arguments)||this}i(e,t);var n=e.prototype;return n.normalize=function(t,e,n,r,i,o){var u=this;return y(t).map(function(t,a){return u.normalizeValue(t,e,n,r,i,o)}).filter(function(t){return null!=t})},n.denormalize=function(t,e){var n=this;return t&&t.map?t.map(function(t){return n.denormalizeValue(t,e)}):t},e}(f),v=function(t,e,n,i,o,u,a){var c=r({},e);return Object.keys(t).forEach(function(n){var r=t[n],i="function"==typeof r?r(e):r,f=o(e[n],e,n,i,u,a);null==f?delete c[n]:c[n]=f}),c},g=function(t,e,n){if(o(e))return u(t,e,n);var i=r({},e);return Object.keys(t).forEach(function(e){null!=i[e]&&(i[e]=n(i[e],t[e]))}),i},b=function t(e,n,r,i,o,u){return"object"==typeof e&&e?"object"!=typeof i||i.normalize&&"function"==typeof i.normalize?i.normalize(e,n,r,t,o,u):(Array.isArray(i)?m:v)(i,e,n,r,t,o,u):e},k={Array:d,Entity:c,Object:function(){function t(t){this.define(t)}var e=t.prototype;return e.define=function(t){this.schema=Object.keys(t).reduce(function(e,n){var i,o=t[n];return r({},e,((i={})[n]=o,i))},this.schema||{})},e.normalize=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return v.apply(void 0,[this.schema].concat(e))},e.denormalize=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return g.apply(void 0,[this.schema].concat(e))},t}(),Union:s,Values:h},S=function(t){var e={},n=z(t);return function t(i,u){return"object"!=typeof u||u.denormalize&&"function"==typeof u.denormalize?null==i?i:u instanceof c?function(t,e,n,i,u){var a=i(t,e);if(void 0===a&&e instanceof c&&(a=e.fallback(t,e)),"object"!=typeof a||null===a)return a;if(u[e.key]||(u[e.key]={}),!u[e.key][t]){var f=o(a)?a:r({},a);u[e.key][t]=f,u[e.key][t]=e.denormalize(f,n)}return u[e.key][t]}(i,u,t,n,e):u.denormalize(i,t):(Array.isArray(u)?p:g)(u,i,t)}},z=function(t){var e=o(t);return function(n,r){var i=r.key;return"object"==typeof n?n:e?t.getIn([i,n.toString()]):t[i]&&t[i][n]}};t.denormalize=function(t,e,n){if(void 0!==t)return S(n)(t,e)},t.normalize=function(t,e){if(!t||"object"!=typeof t)throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+(null===t?"null":typeof t)+'".');var n={},r=function(t){return function(e,n,r,i,o){var u=e.key,a=e.getId(r,i,o);u in t||(t[u]={});var c=t[u][a];t[u][a]=c?e.merge(c,n):n}}(n);return{entities:n,result:b(t,t,null,e,r,{})}},t.schema=k,Object.defineProperty(t,"__esModule",{value:!0})});

@@ -116,3 +116,7 @@ var normalizr = (function (exports) {

return _extends({}, input);
} : _options$processStrat;
} : _options$processStrat,
_options$fallbackStra = _options.fallbackStrategy,
fallbackStrategy = _options$fallbackStra === void 0 ? function (key, schema) {
return undefined;
} : _options$fallbackStra;
this._key = key;

@@ -123,2 +127,3 @@ this._getId = typeof idAttribute === 'function' ? idAttribute : getDefaultGetId(idAttribute);

this._processStrategy = processStrategy;
this._fallbackStrategy = fallbackStrategy;
this.define(definition);

@@ -146,2 +151,6 @@ }

_proto.fallback = function fallback(id, schema) {
return this._fallbackStrategy(id, schema);
};
_proto.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {

@@ -534,2 +543,6 @@ var _this = this;

if (entity === undefined && schema instanceof EntitySchema) {
entity = schema.fallback(id, schema);
}
if (typeof entity !== 'object' || entity === null) {

@@ -536,0 +549,0 @@ return entity;

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

var normalizr=function(t){"use strict";function e(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function n(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}function r(){return(r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function i(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function o(t){return!(!t||"function"!=typeof t.hasOwnProperty||!(t.hasOwnProperty("__ownerID")||t._map&&t._map.hasOwnProperty("__ownerID")))}function u(t,e,n){return Object.keys(t).reduce(function(e,r){var i=""+r;return e.has(i)?e.set(i,n(e.get(i),t[i])):e},e)}var a=function(t){return function(e){return o(e)?e.get(t):e[t]}},c=function(){function t(t,e,n){if(void 0===e&&(e={}),void 0===n&&(n={}),!t||"string"!=typeof t)throw new Error("Expected a string key for Entity, but found "+t+".");var i=n,o=i.idAttribute,u=void 0===o?"id":o,c=i.mergeStrategy,f=void 0===c?function(t,e){return r({},t,e)}:c,s=i.processStrategy,h=void 0===s?function(t){return r({},t)}:s;this._key=t,this._getId="function"==typeof u?u:a(u),this._idAttribute=u,this._mergeStrategy=f,this._processStrategy=h,this.define(e)}var e=t.prototype;return e.define=function(t){this.schema=Object.keys(t).reduce(function(e,n){var i,o=t[n];return r({},e,((i={})[n]=o,i))},this.schema||{})},e.getId=function(t,e,n){return this._getId(t,e,n)},e.merge=function(t,e){return this._mergeStrategy(t,e)},e.normalize=function(t,e,n,r,i,o){var u=this,a=this.getId(t,e,n),c=this.key;if(c in o||(o[c]={}),a in o[c]||(o[c][a]=[]),o[c][a].some(function(e){return e===t}))return a;o[c][a].push(t);var f=this._processStrategy(t,e,n);return Object.keys(this.schema).forEach(function(e){if(f.hasOwnProperty(e)&&"object"==typeof f[e]){var n=u.schema[e],a="function"==typeof n?n(t):n;f[e]=r(f[e],f,e,a,i,o)}}),i(this,f,t,e,n),a},e.denormalize=function(t,e){var n=this;return o(t)?u(this.schema,t,e):(Object.keys(this.schema).forEach(function(r){if(t.hasOwnProperty(r)){var i=n.schema[r];t[r]=e(t[r],i)}}),t)},n(t,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),t}(),f=function(){function t(t,e){e&&(this._schemaAttribute="string"==typeof e?function(t){return t[e]}:e),this.define(t)}var e=t.prototype;return e.define=function(t){this.schema=t},e.getSchemaAttribute=function(t,e,n){return!this.isSingleSchema&&this._schemaAttribute(t,e,n)},e.inferSchema=function(t,e,n){if(this.isSingleSchema)return this.schema;var r=this.getSchemaAttribute(t,e,n);return this.schema[r]},e.normalizeValue=function(t,e,n,r,i,o){var u=this.inferSchema(t,e,n);if(!u)return t;var a=r(t,e,n,u,i,o);return this.isSingleSchema||null==a?a:{id:a,schema:this.getSchemaAttribute(t,e,n)}},e.denormalizeValue=function(t,e){var n=o(t)?t.get("schema"):t.schema;return this.isSingleSchema||n?e((this.isSingleSchema?void 0:o(t)?t.get("id"):t.id)||t,this.isSingleSchema?this.schema:this.schema[n]):t},n(t,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),t}(),s=function(t){function e(e,n){if(!n)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return t.call(this,e,n)||this}i(e,t);var n=e.prototype;return n.normalize=function(t,e,n,r,i,o){return this.normalizeValue(t,e,n,r,i,o)},n.denormalize=function(t,e){return this.denormalizeValue(t,e)},e}(f),h=function(t){function e(){return t.apply(this,arguments)||this}i(e,t);var n=e.prototype;return n.normalize=function(t,e,n,i,o,u){var a=this;return Object.keys(t).reduce(function(e,n,c){var f,s=t[n];return null!=s?r({},e,((f={})[n]=a.normalizeValue(s,t,n,i,o,u),f)):e},{})},n.denormalize=function(t,e){var n=this;return Object.keys(t).reduce(function(i,o){var u,a=t[o];return r({},i,((u={})[o]=n.denormalizeValue(a,e),u))},{})},e}(f),l=function(t){if(Array.isArray(t)&&t.length>1)throw new Error("Expected schema definition to be a single schema, but found "+t.length+".");return t[0]},y=function(t){return Array.isArray(t)?t:Object.keys(t).map(function(e){return t[e]})},m=function(t,e,n,r,i,o,u){return t=l(t),y(e).map(function(e,a){return i(e,n,r,t,o,u)})},p=function(t,e,n){return t=l(t),e&&e.map?e.map(function(e){return n(e,t)}):e},d=function(t){function e(){return t.apply(this,arguments)||this}i(e,t);var n=e.prototype;return n.normalize=function(t,e,n,r,i,o){var u=this;return y(t).map(function(t,a){return u.normalizeValue(t,e,n,r,i,o)}).filter(function(t){return null!=t})},n.denormalize=function(t,e){var n=this;return t&&t.map?t.map(function(t){return n.denormalizeValue(t,e)}):t},e}(f),v=function(t,e,n,i,o,u,a){var c=r({},e);return Object.keys(t).forEach(function(n){var r=t[n],i="function"==typeof r?r(e):r,f=o(e[n],e,n,i,u,a);null==f?delete c[n]:c[n]=f}),c},g=function(t,e,n){if(o(e))return u(t,e,n);var i=r({},e);return Object.keys(t).forEach(function(e){null!=i[e]&&(i[e]=n(i[e],t[e]))}),i},b=function t(e,n,r,i,o,u){return"object"==typeof e&&e?"object"!=typeof i||i.normalize&&"function"==typeof i.normalize?i.normalize(e,n,r,t,o,u):(Array.isArray(i)?m:v)(i,e,n,r,t,o,u):e},z={Array:d,Entity:c,Object:function(){function t(t){this.define(t)}var e=t.prototype;return e.define=function(t){this.schema=Object.keys(t).reduce(function(e,n){var i,o=t[n];return r({},e,((i={})[n]=o,i))},this.schema||{})},e.normalize=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return v.apply(void 0,[this.schema].concat(e))},e.denormalize=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return g.apply(void 0,[this.schema].concat(e))},t}(),Union:s,Values:h},k=function(t){var e={},n=S(t);return function t(i,u){return"object"!=typeof u||u.denormalize&&"function"==typeof u.denormalize?null==i?i:u instanceof c?function(t,e,n,i,u){var a=i(t,e);if("object"!=typeof a||null===a)return a;if(u[e.key]||(u[e.key]={}),!u[e.key][t]){var c=o(a)?a:r({},a);u[e.key][t]=c,u[e.key][t]=e.denormalize(c,n)}return u[e.key][t]}(i,u,t,n,e):u.denormalize(i,t):(Array.isArray(u)?p:g)(u,i,t)}},S=function(t){var e=o(t);return function(n,r){var i=r.key;return"object"==typeof n?n:e?t.getIn([i,n.toString()]):t[i]&&t[i][n]}};return t.denormalize=function(t,e,n){if(void 0!==t)return k(n)(t,e)},t.normalize=function(t,e){if(!t||"object"!=typeof t)throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+(null===t?"null":typeof t)+'".');var n={},r=function(t){return function(e,n,r,i,o){var u=e.key,a=e.getId(r,i,o);u in t||(t[u]={});var c=t[u][a];t[u][a]=c?e.merge(c,n):n}}(n);return{entities:n,result:b(t,t,null,e,r,{})}},t.schema=z,t}({});
var normalizr=function(t){"use strict";function e(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function n(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}function r(){return(r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function i(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function o(t){return!(!t||"function"!=typeof t.hasOwnProperty||!(t.hasOwnProperty("__ownerID")||t._map&&t._map.hasOwnProperty("__ownerID")))}function u(t,e,n){return Object.keys(t).reduce(function(e,r){var i=""+r;return e.has(i)?e.set(i,n(e.get(i),t[i])):e},e)}var a=function(t){return function(e){return o(e)?e.get(t):e[t]}},c=function(){function t(t,e,n){if(void 0===e&&(e={}),void 0===n&&(n={}),!t||"string"!=typeof t)throw new Error("Expected a string key for Entity, but found "+t+".");var i=n,o=i.idAttribute,u=void 0===o?"id":o,c=i.mergeStrategy,f=void 0===c?function(t,e){return r({},t,e)}:c,s=i.processStrategy,h=void 0===s?function(t){return r({},t)}:s,l=i.fallbackStrategy,y=void 0===l?function(t,e){}:l;this._key=t,this._getId="function"==typeof u?u:a(u),this._idAttribute=u,this._mergeStrategy=f,this._processStrategy=h,this._fallbackStrategy=y,this.define(e)}var e=t.prototype;return e.define=function(t){this.schema=Object.keys(t).reduce(function(e,n){var i,o=t[n];return r({},e,((i={})[n]=o,i))},this.schema||{})},e.getId=function(t,e,n){return this._getId(t,e,n)},e.merge=function(t,e){return this._mergeStrategy(t,e)},e.fallback=function(t,e){return this._fallbackStrategy(t,e)},e.normalize=function(t,e,n,r,i,o){var u=this,a=this.getId(t,e,n),c=this.key;if(c in o||(o[c]={}),a in o[c]||(o[c][a]=[]),o[c][a].some(function(e){return e===t}))return a;o[c][a].push(t);var f=this._processStrategy(t,e,n);return Object.keys(this.schema).forEach(function(e){if(f.hasOwnProperty(e)&&"object"==typeof f[e]){var n=u.schema[e],a="function"==typeof n?n(t):n;f[e]=r(f[e],f,e,a,i,o)}}),i(this,f,t,e,n),a},e.denormalize=function(t,e){var n=this;return o(t)?u(this.schema,t,e):(Object.keys(this.schema).forEach(function(r){if(t.hasOwnProperty(r)){var i=n.schema[r];t[r]=e(t[r],i)}}),t)},n(t,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),t}(),f=function(){function t(t,e){e&&(this._schemaAttribute="string"==typeof e?function(t){return t[e]}:e),this.define(t)}var e=t.prototype;return e.define=function(t){this.schema=t},e.getSchemaAttribute=function(t,e,n){return!this.isSingleSchema&&this._schemaAttribute(t,e,n)},e.inferSchema=function(t,e,n){if(this.isSingleSchema)return this.schema;var r=this.getSchemaAttribute(t,e,n);return this.schema[r]},e.normalizeValue=function(t,e,n,r,i,o){var u=this.inferSchema(t,e,n);if(!u)return t;var a=r(t,e,n,u,i,o);return this.isSingleSchema||null==a?a:{id:a,schema:this.getSchemaAttribute(t,e,n)}},e.denormalizeValue=function(t,e){var n=o(t)?t.get("schema"):t.schema;return this.isSingleSchema||n?e((this.isSingleSchema?void 0:o(t)?t.get("id"):t.id)||t,this.isSingleSchema?this.schema:this.schema[n]):t},n(t,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),t}(),s=function(t){function e(e,n){if(!n)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return t.call(this,e,n)||this}i(e,t);var n=e.prototype;return n.normalize=function(t,e,n,r,i,o){return this.normalizeValue(t,e,n,r,i,o)},n.denormalize=function(t,e){return this.denormalizeValue(t,e)},e}(f),h=function(t){function e(){return t.apply(this,arguments)||this}i(e,t);var n=e.prototype;return n.normalize=function(t,e,n,i,o,u){var a=this;return Object.keys(t).reduce(function(e,n,c){var f,s=t[n];return null!=s?r({},e,((f={})[n]=a.normalizeValue(s,t,n,i,o,u),f)):e},{})},n.denormalize=function(t,e){var n=this;return Object.keys(t).reduce(function(i,o){var u,a=t[o];return r({},i,((u={})[o]=n.denormalizeValue(a,e),u))},{})},e}(f),l=function(t){if(Array.isArray(t)&&t.length>1)throw new Error("Expected schema definition to be a single schema, but found "+t.length+".");return t[0]},y=function(t){return Array.isArray(t)?t:Object.keys(t).map(function(e){return t[e]})},m=function(t,e,n,r,i,o,u){return t=l(t),y(e).map(function(e,a){return i(e,n,r,t,o,u)})},p=function(t,e,n){return t=l(t),e&&e.map?e.map(function(e){return n(e,t)}):e},d=function(t){function e(){return t.apply(this,arguments)||this}i(e,t);var n=e.prototype;return n.normalize=function(t,e,n,r,i,o){var u=this;return y(t).map(function(t,a){return u.normalizeValue(t,e,n,r,i,o)}).filter(function(t){return null!=t})},n.denormalize=function(t,e){var n=this;return t&&t.map?t.map(function(t){return n.denormalizeValue(t,e)}):t},e}(f),v=function(t,e,n,i,o,u,a){var c=r({},e);return Object.keys(t).forEach(function(n){var r=t[n],i="function"==typeof r?r(e):r,f=o(e[n],e,n,i,u,a);null==f?delete c[n]:c[n]=f}),c},g=function(t,e,n){if(o(e))return u(t,e,n);var i=r({},e);return Object.keys(t).forEach(function(e){null!=i[e]&&(i[e]=n(i[e],t[e]))}),i},b=function t(e,n,r,i,o,u){return"object"==typeof e&&e?"object"!=typeof i||i.normalize&&"function"==typeof i.normalize?i.normalize(e,n,r,t,o,u):(Array.isArray(i)?m:v)(i,e,n,r,t,o,u):e},k={Array:d,Entity:c,Object:function(){function t(t){this.define(t)}var e=t.prototype;return e.define=function(t){this.schema=Object.keys(t).reduce(function(e,n){var i,o=t[n];return r({},e,((i={})[n]=o,i))},this.schema||{})},e.normalize=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return v.apply(void 0,[this.schema].concat(e))},e.denormalize=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return g.apply(void 0,[this.schema].concat(e))},t}(),Union:s,Values:h},S=function(t){var e={},n=z(t);return function t(i,u){return"object"!=typeof u||u.denormalize&&"function"==typeof u.denormalize?null==i?i:u instanceof c?function(t,e,n,i,u){var a=i(t,e);if(void 0===a&&e instanceof c&&(a=e.fallback(t,e)),"object"!=typeof a||null===a)return a;if(u[e.key]||(u[e.key]={}),!u[e.key][t]){var f=o(a)?a:r({},a);u[e.key][t]=f,u[e.key][t]=e.denormalize(f,n)}return u[e.key][t]}(i,u,t,n,e):u.denormalize(i,t):(Array.isArray(u)?p:g)(u,i,t)}},z=function(t){var e=o(t);return function(n,r){var i=r.key;return"object"==typeof n?n:e?t.getIn([i,n.toString()]):t[i]&&t[i][n]}};return t.denormalize=function(t,e,n){if(void 0!==t)return S(n)(t,e)},t.normalize=function(t,e){if(!t||"object"!=typeof t)throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+(null===t?"null":typeof t)+'".');var n={},r=function(t){return function(e,n,r,i,o){var u=e.key,a=e.getId(r,i,o);u in t||(t[u]={});var c=t[u][a];t[u][a]=c?e.merge(c,n):n}}(n);return{entities:n,result:b(t,t,null,e,r,{})}},t.schema=k,t}({});

@@ -113,3 +113,7 @@ function _defineProperties(target, props) {

return _extends({}, input);
} : _options$processStrat;
} : _options$processStrat,
_options$fallbackStra = _options.fallbackStrategy,
fallbackStrategy = _options$fallbackStra === void 0 ? function (key, schema) {
return undefined;
} : _options$fallbackStra;
this._key = key;

@@ -120,2 +124,3 @@ this._getId = typeof idAttribute === 'function' ? idAttribute : getDefaultGetId(idAttribute);

this._processStrategy = processStrategy;
this._fallbackStrategy = fallbackStrategy;
this.define(definition);

@@ -143,2 +148,6 @@ }

_proto.fallback = function fallback(id, schema) {
return this._fallbackStrategy(id, schema);
};
_proto.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {

@@ -531,2 +540,6 @@ var _this = this;

if (entity === undefined && schema instanceof EntitySchema) {
entity = schema.fallback(id, schema);
}
if (typeof entity !== 'object' || entity === null) {

@@ -533,0 +546,0 @@ return entity;

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

function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function e(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}function n(){return(n=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function r(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function i(t){return!(!t||"function"!=typeof t.hasOwnProperty||!(t.hasOwnProperty("__ownerID")||t._map&&t._map.hasOwnProperty("__ownerID")))}function o(t,e,n){return Object.keys(t).reduce(function(e,r){var i=""+r;return e.has(i)?e.set(i,n(e.get(i),t[i])):e},e)}var u=function(t){return function(e){return i(e)?e.get(t):e[t]}},a=function(){function t(t,e,r){if(void 0===e&&(e={}),void 0===r&&(r={}),!t||"string"!=typeof t)throw new Error("Expected a string key for Entity, but found "+t+".");var i=r,o=i.idAttribute,a=void 0===o?"id":o,c=i.mergeStrategy,f=void 0===c?function(t,e){return n({},t,e)}:c,s=i.processStrategy,h=void 0===s?function(t){return n({},t)}:s;this._key=t,this._getId="function"==typeof a?a:u(a),this._idAttribute=a,this._mergeStrategy=f,this._processStrategy=h,this.define(e)}var r=t.prototype;return r.define=function(t){this.schema=Object.keys(t).reduce(function(e,r){var i,o=t[r];return n({},e,((i={})[r]=o,i))},this.schema||{})},r.getId=function(t,e,n){return this._getId(t,e,n)},r.merge=function(t,e){return this._mergeStrategy(t,e)},r.normalize=function(t,e,n,r,i,o){var u=this,a=this.getId(t,e,n),c=this.key;if(c in o||(o[c]={}),a in o[c]||(o[c][a]=[]),o[c][a].some(function(e){return e===t}))return a;o[c][a].push(t);var f=this._processStrategy(t,e,n);return Object.keys(this.schema).forEach(function(e){if(f.hasOwnProperty(e)&&"object"==typeof f[e]){var n=u.schema[e],a="function"==typeof n?n(t):n;f[e]=r(f[e],f,e,a,i,o)}}),i(this,f,t,e,n),a},r.denormalize=function(t,e){var n=this;return i(t)?o(this.schema,t,e):(Object.keys(this.schema).forEach(function(r){if(t.hasOwnProperty(r)){var i=n.schema[r];t[r]=e(t[r],i)}}),t)},e(t,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),t}(),c=function(){function t(t,e){e&&(this._schemaAttribute="string"==typeof e?function(t){return t[e]}:e),this.define(t)}var n=t.prototype;return n.define=function(t){this.schema=t},n.getSchemaAttribute=function(t,e,n){return!this.isSingleSchema&&this._schemaAttribute(t,e,n)},n.inferSchema=function(t,e,n){if(this.isSingleSchema)return this.schema;var r=this.getSchemaAttribute(t,e,n);return this.schema[r]},n.normalizeValue=function(t,e,n,r,i,o){var u=this.inferSchema(t,e,n);if(!u)return t;var a=r(t,e,n,u,i,o);return this.isSingleSchema||null==a?a:{id:a,schema:this.getSchemaAttribute(t,e,n)}},n.denormalizeValue=function(t,e){var n=i(t)?t.get("schema"):t.schema;return this.isSingleSchema||n?e((this.isSingleSchema?void 0:i(t)?t.get("id"):t.id)||t,this.isSingleSchema?this.schema:this.schema[n]):t},e(t,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),t}(),f=function(t){function e(e,n){if(!n)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return t.call(this,e,n)||this}r(e,t);var n=e.prototype;return n.normalize=function(t,e,n,r,i,o){return this.normalizeValue(t,e,n,r,i,o)},n.denormalize=function(t,e){return this.denormalizeValue(t,e)},e}(c),s=function(t){function e(){return t.apply(this,arguments)||this}r(e,t);var i=e.prototype;return i.normalize=function(t,e,r,i,o,u){var a=this;return Object.keys(t).reduce(function(e,r,c){var f,s=t[r];return null!=s?n({},e,((f={})[r]=a.normalizeValue(s,t,r,i,o,u),f)):e},{})},i.denormalize=function(t,e){var r=this;return Object.keys(t).reduce(function(i,o){var u,a=t[o];return n({},i,((u={})[o]=r.denormalizeValue(a,e),u))},{})},e}(c),h=function(t){if(Array.isArray(t)&&t.length>1)throw new Error("Expected schema definition to be a single schema, but found "+t.length+".");return t[0]},l=function(t){return Array.isArray(t)?t:Object.keys(t).map(function(e){return t[e]})},y=function(t,e,n,r,i,o,u){return t=h(t),l(e).map(function(e,a){return i(e,n,r,t,o,u)})},m=function(t,e,n){return t=h(t),e&&e.map?e.map(function(e){return n(e,t)}):e},p=function(t){function e(){return t.apply(this,arguments)||this}r(e,t);var n=e.prototype;return n.normalize=function(t,e,n,r,i,o){var u=this;return l(t).map(function(t,a){return u.normalizeValue(t,e,n,r,i,o)}).filter(function(t){return null!=t})},n.denormalize=function(t,e){var n=this;return t&&t.map?t.map(function(t){return n.denormalizeValue(t,e)}):t},e}(c),d=function(t,e,r,i,o,u,a){var c=n({},e);return Object.keys(t).forEach(function(n){var r=t[n],i="function"==typeof r?r(e):r,f=o(e[n],e,n,i,u,a);null==f?delete c[n]:c[n]=f}),c},v=function(t,e,r){if(i(e))return o(t,e,r);var u=n({},e);return Object.keys(t).forEach(function(e){null!=u[e]&&(u[e]=r(u[e],t[e]))}),u},g=function t(e,n,r,i,o,u){return"object"==typeof e&&e?"object"!=typeof i||i.normalize&&"function"==typeof i.normalize?i.normalize(e,n,r,t,o,u):(Array.isArray(i)?y:d)(i,e,n,r,t,o,u):e},b={Array:p,Entity:a,Object:function(){function t(t){this.define(t)}var e=t.prototype;return e.define=function(t){this.schema=Object.keys(t).reduce(function(e,r){var i,o=t[r];return n({},e,((i={})[r]=o,i))},this.schema||{})},e.normalize=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return d.apply(void 0,[this.schema].concat(e))},e.denormalize=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return v.apply(void 0,[this.schema].concat(e))},t}(),Union:f,Values:s},z=function(t,e){if(!t||"object"!=typeof t)throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+(null===t?"null":typeof t)+'".');var n={},r=function(t){return function(e,n,r,i,o){var u=e.key,a=e.getId(r,i,o);u in t||(t[u]={});var c=t[u][a];t[u][a]=c?e.merge(c,n):n}}(n);return{entities:n,result:g(t,t,null,e,r,{})}},k=function(t){var e={},r=S(t);return function t(o,u){return"object"!=typeof u||u.denormalize&&"function"==typeof u.denormalize?null==o?o:u instanceof a?function(t,e,r,o,u){var a=o(t,e);if("object"!=typeof a||null===a)return a;if(u[e.key]||(u[e.key]={}),!u[e.key][t]){var c=i(a)?a:n({},a);u[e.key][t]=c,u[e.key][t]=e.denormalize(c,r)}return u[e.key][t]}(o,u,t,r,e):u.denormalize(o,t):(Array.isArray(u)?m:v)(u,o,t)}},S=function(t){var e=i(t);return function(n,r){var i=r.key;return"object"==typeof n?n:e?t.getIn([i,n.toString()]):t[i]&&t[i][n]}},j=function(t,e,n){if(void 0!==t)return k(n)(t,e)};export{j as denormalize,z as normalize,b as schema};
function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function e(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}function n(){return(n=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function r(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function i(t){return!(!t||"function"!=typeof t.hasOwnProperty||!(t.hasOwnProperty("__ownerID")||t._map&&t._map.hasOwnProperty("__ownerID")))}function o(t,e,n){return Object.keys(t).reduce(function(e,r){var i=""+r;return e.has(i)?e.set(i,n(e.get(i),t[i])):e},e)}var u=function(t){return function(e){return i(e)?e.get(t):e[t]}},a=function(){function t(t,e,r){if(void 0===e&&(e={}),void 0===r&&(r={}),!t||"string"!=typeof t)throw new Error("Expected a string key for Entity, but found "+t+".");var i=r,o=i.idAttribute,a=void 0===o?"id":o,c=i.mergeStrategy,f=void 0===c?function(t,e){return n({},t,e)}:c,s=i.processStrategy,h=void 0===s?function(t){return n({},t)}:s,l=i.fallbackStrategy,y=void 0===l?function(t,e){}:l;this._key=t,this._getId="function"==typeof a?a:u(a),this._idAttribute=a,this._mergeStrategy=f,this._processStrategy=h,this._fallbackStrategy=y,this.define(e)}var r=t.prototype;return r.define=function(t){this.schema=Object.keys(t).reduce(function(e,r){var i,o=t[r];return n({},e,((i={})[r]=o,i))},this.schema||{})},r.getId=function(t,e,n){return this._getId(t,e,n)},r.merge=function(t,e){return this._mergeStrategy(t,e)},r.fallback=function(t,e){return this._fallbackStrategy(t,e)},r.normalize=function(t,e,n,r,i,o){var u=this,a=this.getId(t,e,n),c=this.key;if(c in o||(o[c]={}),a in o[c]||(o[c][a]=[]),o[c][a].some(function(e){return e===t}))return a;o[c][a].push(t);var f=this._processStrategy(t,e,n);return Object.keys(this.schema).forEach(function(e){if(f.hasOwnProperty(e)&&"object"==typeof f[e]){var n=u.schema[e],a="function"==typeof n?n(t):n;f[e]=r(f[e],f,e,a,i,o)}}),i(this,f,t,e,n),a},r.denormalize=function(t,e){var n=this;return i(t)?o(this.schema,t,e):(Object.keys(this.schema).forEach(function(r){if(t.hasOwnProperty(r)){var i=n.schema[r];t[r]=e(t[r],i)}}),t)},e(t,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),t}(),c=function(){function t(t,e){e&&(this._schemaAttribute="string"==typeof e?function(t){return t[e]}:e),this.define(t)}var n=t.prototype;return n.define=function(t){this.schema=t},n.getSchemaAttribute=function(t,e,n){return!this.isSingleSchema&&this._schemaAttribute(t,e,n)},n.inferSchema=function(t,e,n){if(this.isSingleSchema)return this.schema;var r=this.getSchemaAttribute(t,e,n);return this.schema[r]},n.normalizeValue=function(t,e,n,r,i,o){var u=this.inferSchema(t,e,n);if(!u)return t;var a=r(t,e,n,u,i,o);return this.isSingleSchema||null==a?a:{id:a,schema:this.getSchemaAttribute(t,e,n)}},n.denormalizeValue=function(t,e){var n=i(t)?t.get("schema"):t.schema;return this.isSingleSchema||n?e((this.isSingleSchema?void 0:i(t)?t.get("id"):t.id)||t,this.isSingleSchema?this.schema:this.schema[n]):t},e(t,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),t}(),f=function(t){function e(e,n){if(!n)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return t.call(this,e,n)||this}r(e,t);var n=e.prototype;return n.normalize=function(t,e,n,r,i,o){return this.normalizeValue(t,e,n,r,i,o)},n.denormalize=function(t,e){return this.denormalizeValue(t,e)},e}(c),s=function(t){function e(){return t.apply(this,arguments)||this}r(e,t);var i=e.prototype;return i.normalize=function(t,e,r,i,o,u){var a=this;return Object.keys(t).reduce(function(e,r,c){var f,s=t[r];return null!=s?n({},e,((f={})[r]=a.normalizeValue(s,t,r,i,o,u),f)):e},{})},i.denormalize=function(t,e){var r=this;return Object.keys(t).reduce(function(i,o){var u,a=t[o];return n({},i,((u={})[o]=r.denormalizeValue(a,e),u))},{})},e}(c),h=function(t){if(Array.isArray(t)&&t.length>1)throw new Error("Expected schema definition to be a single schema, but found "+t.length+".");return t[0]},l=function(t){return Array.isArray(t)?t:Object.keys(t).map(function(e){return t[e]})},y=function(t,e,n,r,i,o,u){return t=h(t),l(e).map(function(e,a){return i(e,n,r,t,o,u)})},m=function(t,e,n){return t=h(t),e&&e.map?e.map(function(e){return n(e,t)}):e},p=function(t){function e(){return t.apply(this,arguments)||this}r(e,t);var n=e.prototype;return n.normalize=function(t,e,n,r,i,o){var u=this;return l(t).map(function(t,a){return u.normalizeValue(t,e,n,r,i,o)}).filter(function(t){return null!=t})},n.denormalize=function(t,e){var n=this;return t&&t.map?t.map(function(t){return n.denormalizeValue(t,e)}):t},e}(c),d=function(t,e,r,i,o,u,a){var c=n({},e);return Object.keys(t).forEach(function(n){var r=t[n],i="function"==typeof r?r(e):r,f=o(e[n],e,n,i,u,a);null==f?delete c[n]:c[n]=f}),c},v=function(t,e,r){if(i(e))return o(t,e,r);var u=n({},e);return Object.keys(t).forEach(function(e){null!=u[e]&&(u[e]=r(u[e],t[e]))}),u},g=function t(e,n,r,i,o,u){return"object"==typeof e&&e?"object"!=typeof i||i.normalize&&"function"==typeof i.normalize?i.normalize(e,n,r,t,o,u):(Array.isArray(i)?y:d)(i,e,n,r,t,o,u):e},b={Array:p,Entity:a,Object:function(){function t(t){this.define(t)}var e=t.prototype;return e.define=function(t){this.schema=Object.keys(t).reduce(function(e,r){var i,o=t[r];return n({},e,((i={})[r]=o,i))},this.schema||{})},e.normalize=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return d.apply(void 0,[this.schema].concat(e))},e.denormalize=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return v.apply(void 0,[this.schema].concat(e))},t}(),Union:f,Values:s},k=function(t,e){if(!t||"object"!=typeof t)throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+(null===t?"null":typeof t)+'".');var n={},r=function(t){return function(e,n,r,i,o){var u=e.key,a=e.getId(r,i,o);u in t||(t[u]={});var c=t[u][a];t[u][a]=c?e.merge(c,n):n}}(n);return{entities:n,result:g(t,t,null,e,r,{})}},S=function(t){var e={},r=z(t);return function t(o,u){return"object"!=typeof u||u.denormalize&&"function"==typeof u.denormalize?null==o?o:u instanceof a?function(t,e,r,o,u){var c=o(t,e);if(void 0===c&&e instanceof a&&(c=e.fallback(t,e)),"object"!=typeof c||null===c)return c;if(u[e.key]||(u[e.key]={}),!u[e.key][t]){var f=i(c)?c:n({},c);u[e.key][t]=f,u[e.key][t]=e.denormalize(f,r)}return u[e.key][t]}(o,u,t,r,e):u.denormalize(o,t):(Array.isArray(u)?m:v)(u,o,t)}},z=function(t){var e=i(t);return function(n,r){var i=r.key;return"object"==typeof n?n:e?t.getIn([i,n.toString()]):t[i]&&t[i][n]}},_=function(t,e,n){if(void 0!==t)return S(n)(t,e)};export{_ as denormalize,k as normalize,b as schema};

@@ -117,3 +117,7 @@ 'use strict';

return _extends({}, input);
} : _options$processStrat;
} : _options$processStrat,
_options$fallbackStra = _options.fallbackStrategy,
fallbackStrategy = _options$fallbackStra === void 0 ? function (key, schema) {
return undefined;
} : _options$fallbackStra;
this._key = key;

@@ -124,2 +128,3 @@ this._getId = typeof idAttribute === 'function' ? idAttribute : getDefaultGetId(idAttribute);

this._processStrategy = processStrategy;
this._fallbackStrategy = fallbackStrategy;
this.define(definition);

@@ -147,2 +152,6 @@ }

_proto.fallback = function fallback(id, schema) {
return this._fallbackStrategy(id, schema);
};
_proto.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {

@@ -535,2 +544,6 @@ var _this = this;

if (entity === undefined && schema instanceof EntitySchema) {
entity = schema.fallback(id, schema);
}
if (typeof entity !== 'object' || entity === null) {

@@ -537,0 +550,0 @@ return entity;

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

"use strict";function _defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),e}function _extends(){return(_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function _inheritsLoose(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function isImmutable(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(e.hasOwnProperty("__ownerID")||e._map&&e._map.hasOwnProperty("__ownerID")))}function denormalizeImmutable(e,t,n){return Object.keys(e).reduce(function(t,r){var i=""+r;return t.has(i)?t.set(i,n(t.get(i),e[i])):t},t)}Object.defineProperty(exports,"__esModule",{value:!0});var getDefaultGetId=function(e){return function(t){return isImmutable(t)?t.get(e):t[e]}},EntitySchema=function(){function e(e,t,n){if(void 0===t&&(t={}),void 0===n&&(n={}),!e||"string"!=typeof e)throw new Error("Expected a string key for Entity, but found "+e+".");var r=n,i=r.idAttribute,o=void 0===i?"id":i,a=r.mergeStrategy,u=void 0===a?function(e,t){return _extends({},e,t)}:a,c=r.processStrategy,s=void 0===c?function(e){return _extends({},e)}:c;this._key=e,this._getId="function"==typeof o?o:getDefaultGetId(o),this._idAttribute=o,this._mergeStrategy=u,this._processStrategy=s,this.define(t)}var t=e.prototype;return t.define=function(e){this.schema=Object.keys(e).reduce(function(t,n){var r,i=e[n];return _extends({},t,((r={})[n]=i,r))},this.schema||{})},t.getId=function(e,t,n){return this._getId(e,t,n)},t.merge=function(e,t){return this._mergeStrategy(e,t)},t.normalize=function(e,t,n,r,i,o){var a=this,u=this.getId(e,t,n),c=this.key;if(c in o||(o[c]={}),u in o[c]||(o[c][u]=[]),o[c][u].some(function(t){return t===e}))return u;o[c][u].push(e);var s=this._processStrategy(e,t,n);return Object.keys(this.schema).forEach(function(t){if(s.hasOwnProperty(t)&&"object"==typeof s[t]){var n=a.schema[t],u="function"==typeof n?n(e):n;s[t]=r(s[t],s,t,u,i,o)}}),i(this,s,e,t,n),u},t.denormalize=function(e,t){var n=this;return isImmutable(e)?denormalizeImmutable(this.schema,e,t):(Object.keys(this.schema).forEach(function(r){if(e.hasOwnProperty(r)){var i=n.schema[r];e[r]=t(e[r],i)}}),e)},_createClass(e,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),e}(),PolymorphicSchema=function(){function e(e,t){t&&(this._schemaAttribute="string"==typeof t?function(e){return e[t]}:t),this.define(e)}var t=e.prototype;return t.define=function(e){this.schema=e},t.getSchemaAttribute=function(e,t,n){return!this.isSingleSchema&&this._schemaAttribute(e,t,n)},t.inferSchema=function(e,t,n){if(this.isSingleSchema)return this.schema;var r=this.getSchemaAttribute(e,t,n);return this.schema[r]},t.normalizeValue=function(e,t,n,r,i,o){var a=this.inferSchema(e,t,n);if(!a)return e;var u=r(e,t,n,a,i,o);return this.isSingleSchema||null==u?u:{id:u,schema:this.getSchemaAttribute(e,t,n)}},t.denormalizeValue=function(e,t){var n=isImmutable(e)?e.get("schema"):e.schema;return this.isSingleSchema||n?t((this.isSingleSchema?void 0:isImmutable(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[n]):e},_createClass(e,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),e}(),UnionSchema=function(e){function t(t,n){if(!n)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return e.call(this,t,n)||this}_inheritsLoose(t,e);var n=t.prototype;return n.normalize=function(e,t,n,r,i,o){return this.normalizeValue(e,t,n,r,i,o)},n.denormalize=function(e,t){return this.denormalizeValue(e,t)},t}(PolymorphicSchema),ValuesSchema=function(e){function t(){return e.apply(this,arguments)||this}_inheritsLoose(t,e);var n=t.prototype;return n.normalize=function(e,t,n,r,i,o){var a=this;return Object.keys(e).reduce(function(t,n,u){var c,s=e[n];return null!=s?_extends({},t,((c={})[n]=a.normalizeValue(s,e,n,r,i,o),c)):t},{})},n.denormalize=function(e,t){var n=this;return Object.keys(e).reduce(function(r,i){var o,a=e[i];return _extends({},r,((o={})[i]=n.denormalizeValue(a,t),o))},{})},t}(PolymorphicSchema),validateSchema=function(e){if(Array.isArray(e)&&e.length>1)throw new Error("Expected schema definition to be a single schema, but found "+e.length+".");return e[0]},getValues=function(e){return Array.isArray(e)?e:Object.keys(e).map(function(t){return e[t]})},normalize=function(e,t,n,r,i,o,a){return e=validateSchema(e),getValues(t).map(function(t,u){return i(t,n,r,e,o,a)})},denormalize=function(e,t,n){return e=validateSchema(e),t&&t.map?t.map(function(t){return n(t,e)}):t},ArraySchema=function(e){function t(){return e.apply(this,arguments)||this}_inheritsLoose(t,e);var n=t.prototype;return n.normalize=function(e,t,n,r,i,o){var a=this;return getValues(e).map(function(e,u){return a.normalizeValue(e,t,n,r,i,o)}).filter(function(e){return null!=e})},n.denormalize=function(e,t){var n=this;return e&&e.map?e.map(function(e){return n.denormalizeValue(e,t)}):e},t}(PolymorphicSchema),_normalize=function(e,t,n,r,i,o,a){var u=_extends({},t);return Object.keys(e).forEach(function(n){var r=e[n],c="function"==typeof r?r(t):r,s=i(t[n],t,n,c,o,a);null==s?delete u[n]:u[n]=s}),u},_denormalize=function(e,t,n){if(isImmutable(t))return denormalizeImmutable(e,t,n);var r=_extends({},t);return Object.keys(e).forEach(function(t){null!=r[t]&&(r[t]=n(r[t],e[t]))}),r},ObjectSchema=function(){function e(e){this.define(e)}var t=e.prototype;return t.define=function(e){this.schema=Object.keys(e).reduce(function(t,n){var r,i=e[n];return _extends({},t,((r={})[n]=i,r))},this.schema||{})},t.normalize=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return _normalize.apply(void 0,[this.schema].concat(t))},t.denormalize=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return _denormalize.apply(void 0,[this.schema].concat(t))},e}(),visit=function e(t,n,r,i,o,a){return"object"==typeof t&&t?"object"!=typeof i||i.normalize&&"function"==typeof i.normalize?i.normalize(t,n,r,e,o,a):(Array.isArray(i)?normalize:_normalize)(i,t,n,r,e,o,a):t},addEntities=function(e){return function(t,n,r,i,o){var a=t.key,u=t.getId(r,i,o);a in e||(e[a]={});var c=e[a][u];e[a][u]=c?t.merge(c,n):n}},schema={Array:ArraySchema,Entity:EntitySchema,Object:ObjectSchema,Union:UnionSchema,Values:ValuesSchema},normalize$1=function(e,t){if(!e||"object"!=typeof e)throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+(null===e?"null":typeof e)+'".');var n={},r=addEntities(n);return{entities:n,result:visit(e,e,null,t,r,{})}},unvisitEntity=function(e,t,n,r,i){var o=r(e,t);if("object"!=typeof o||null===o)return o;if(i[t.key]||(i[t.key]={}),!i[t.key][e]){var a=isImmutable(o)?o:_extends({},o);i[t.key][e]=a,i[t.key][e]=t.denormalize(a,n)}return i[t.key][e]},getUnvisit=function(e){var t={},n=getEntities(e);return function e(r,i){return"object"!=typeof i||i.denormalize&&"function"==typeof i.denormalize?null==r?r:i instanceof EntitySchema?unvisitEntity(r,i,e,n,t):i.denormalize(r,e):(Array.isArray(i)?denormalize:_denormalize)(i,r,e)}},getEntities=function(e){var t=isImmutable(e);return function(n,r){var i=r.key;return"object"==typeof n?n:t?e.getIn([i,n.toString()]):e[i]&&e[i][n]}},denormalize$1=function(e,t,n){if(void 0!==e)return getUnvisit(n)(e,t)};exports.denormalize=denormalize$1,exports.normalize=normalize$1,exports.schema=schema;
"use strict";function _defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),e}function _extends(){return(_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function _inheritsLoose(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function isImmutable(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(e.hasOwnProperty("__ownerID")||e._map&&e._map.hasOwnProperty("__ownerID")))}function denormalizeImmutable(e,t,n){return Object.keys(e).reduce(function(t,r){var i=""+r;return t.has(i)?t.set(i,n(t.get(i),e[i])):t},t)}Object.defineProperty(exports,"__esModule",{value:!0});var getDefaultGetId=function(e){return function(t){return isImmutable(t)?t.get(e):t[e]}},EntitySchema=function(){function e(e,t,n){if(void 0===t&&(t={}),void 0===n&&(n={}),!e||"string"!=typeof e)throw new Error("Expected a string key for Entity, but found "+e+".");var r=n,i=r.idAttribute,o=void 0===i?"id":i,a=r.mergeStrategy,u=void 0===a?function(e,t){return _extends({},e,t)}:a,c=r.processStrategy,s=void 0===c?function(e){return _extends({},e)}:c,f=r.fallbackStrategy,h=void 0===f?function(e,t){}:f;this._key=e,this._getId="function"==typeof o?o:getDefaultGetId(o),this._idAttribute=o,this._mergeStrategy=u,this._processStrategy=s,this._fallbackStrategy=h,this.define(t)}var t=e.prototype;return t.define=function(e){this.schema=Object.keys(e).reduce(function(t,n){var r,i=e[n];return _extends({},t,((r={})[n]=i,r))},this.schema||{})},t.getId=function(e,t,n){return this._getId(e,t,n)},t.merge=function(e,t){return this._mergeStrategy(e,t)},t.fallback=function(e,t){return this._fallbackStrategy(e,t)},t.normalize=function(e,t,n,r,i,o){var a=this,u=this.getId(e,t,n),c=this.key;if(c in o||(o[c]={}),u in o[c]||(o[c][u]=[]),o[c][u].some(function(t){return t===e}))return u;o[c][u].push(e);var s=this._processStrategy(e,t,n);return Object.keys(this.schema).forEach(function(t){if(s.hasOwnProperty(t)&&"object"==typeof s[t]){var n=a.schema[t],u="function"==typeof n?n(e):n;s[t]=r(s[t],s,t,u,i,o)}}),i(this,s,e,t,n),u},t.denormalize=function(e,t){var n=this;return isImmutable(e)?denormalizeImmutable(this.schema,e,t):(Object.keys(this.schema).forEach(function(r){if(e.hasOwnProperty(r)){var i=n.schema[r];e[r]=t(e[r],i)}}),e)},_createClass(e,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),e}(),PolymorphicSchema=function(){function e(e,t){t&&(this._schemaAttribute="string"==typeof t?function(e){return e[t]}:t),this.define(e)}var t=e.prototype;return t.define=function(e){this.schema=e},t.getSchemaAttribute=function(e,t,n){return!this.isSingleSchema&&this._schemaAttribute(e,t,n)},t.inferSchema=function(e,t,n){if(this.isSingleSchema)return this.schema;var r=this.getSchemaAttribute(e,t,n);return this.schema[r]},t.normalizeValue=function(e,t,n,r,i,o){var a=this.inferSchema(e,t,n);if(!a)return e;var u=r(e,t,n,a,i,o);return this.isSingleSchema||null==u?u:{id:u,schema:this.getSchemaAttribute(e,t,n)}},t.denormalizeValue=function(e,t){var n=isImmutable(e)?e.get("schema"):e.schema;return this.isSingleSchema||n?t((this.isSingleSchema?void 0:isImmutable(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[n]):e},_createClass(e,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),e}(),UnionSchema=function(e){function t(t,n){if(!n)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return e.call(this,t,n)||this}_inheritsLoose(t,e);var n=t.prototype;return n.normalize=function(e,t,n,r,i,o){return this.normalizeValue(e,t,n,r,i,o)},n.denormalize=function(e,t){return this.denormalizeValue(e,t)},t}(PolymorphicSchema),ValuesSchema=function(e){function t(){return e.apply(this,arguments)||this}_inheritsLoose(t,e);var n=t.prototype;return n.normalize=function(e,t,n,r,i,o){var a=this;return Object.keys(e).reduce(function(t,n,u){var c,s=e[n];return null!=s?_extends({},t,((c={})[n]=a.normalizeValue(s,e,n,r,i,o),c)):t},{})},n.denormalize=function(e,t){var n=this;return Object.keys(e).reduce(function(r,i){var o,a=e[i];return _extends({},r,((o={})[i]=n.denormalizeValue(a,t),o))},{})},t}(PolymorphicSchema),validateSchema=function(e){if(Array.isArray(e)&&e.length>1)throw new Error("Expected schema definition to be a single schema, but found "+e.length+".");return e[0]},getValues=function(e){return Array.isArray(e)?e:Object.keys(e).map(function(t){return e[t]})},normalize=function(e,t,n,r,i,o,a){return e=validateSchema(e),getValues(t).map(function(t,u){return i(t,n,r,e,o,a)})},denormalize=function(e,t,n){return e=validateSchema(e),t&&t.map?t.map(function(t){return n(t,e)}):t},ArraySchema=function(e){function t(){return e.apply(this,arguments)||this}_inheritsLoose(t,e);var n=t.prototype;return n.normalize=function(e,t,n,r,i,o){var a=this;return getValues(e).map(function(e,u){return a.normalizeValue(e,t,n,r,i,o)}).filter(function(e){return null!=e})},n.denormalize=function(e,t){var n=this;return e&&e.map?e.map(function(e){return n.denormalizeValue(e,t)}):e},t}(PolymorphicSchema),_normalize=function(e,t,n,r,i,o,a){var u=_extends({},t);return Object.keys(e).forEach(function(n){var r=e[n],c="function"==typeof r?r(t):r,s=i(t[n],t,n,c,o,a);null==s?delete u[n]:u[n]=s}),u},_denormalize=function(e,t,n){if(isImmutable(t))return denormalizeImmutable(e,t,n);var r=_extends({},t);return Object.keys(e).forEach(function(t){null!=r[t]&&(r[t]=n(r[t],e[t]))}),r},ObjectSchema=function(){function e(e){this.define(e)}var t=e.prototype;return t.define=function(e){this.schema=Object.keys(e).reduce(function(t,n){var r,i=e[n];return _extends({},t,((r={})[n]=i,r))},this.schema||{})},t.normalize=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return _normalize.apply(void 0,[this.schema].concat(t))},t.denormalize=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return _denormalize.apply(void 0,[this.schema].concat(t))},e}(),visit=function e(t,n,r,i,o,a){return"object"==typeof t&&t?"object"!=typeof i||i.normalize&&"function"==typeof i.normalize?i.normalize(t,n,r,e,o,a):(Array.isArray(i)?normalize:_normalize)(i,t,n,r,e,o,a):t},addEntities=function(e){return function(t,n,r,i,o){var a=t.key,u=t.getId(r,i,o);a in e||(e[a]={});var c=e[a][u];e[a][u]=c?t.merge(c,n):n}},schema={Array:ArraySchema,Entity:EntitySchema,Object:ObjectSchema,Union:UnionSchema,Values:ValuesSchema},normalize$1=function(e,t){if(!e||"object"!=typeof e)throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+(null===e?"null":typeof e)+'".');var n={},r=addEntities(n);return{entities:n,result:visit(e,e,null,t,r,{})}},unvisitEntity=function(e,t,n,r,i){var o=r(e,t);if(void 0===o&&t instanceof EntitySchema&&(o=t.fallback(e,t)),"object"!=typeof o||null===o)return o;if(i[t.key]||(i[t.key]={}),!i[t.key][e]){var a=isImmutable(o)?o:_extends({},o);i[t.key][e]=a,i[t.key][e]=t.denormalize(a,n)}return i[t.key][e]},getUnvisit=function(e){var t={},n=getEntities(e);return function e(r,i){return"object"!=typeof i||i.denormalize&&"function"==typeof i.denormalize?null==r?r:i instanceof EntitySchema?unvisitEntity(r,i,e,n,t):i.denormalize(r,e):(Array.isArray(i)?denormalize:_denormalize)(i,r,e)}},getEntities=function(e){var t=isImmutable(e);return function(n,r){var i=r.key;return"object"==typeof n?n:t?e.getIn([i,n.toString()]):e[i]&&e[i][n]}},denormalize$1=function(e,t,n){if(void 0!==e)return getUnvisit(n)(e,t)};exports.denormalize=denormalize$1,exports.normalize=normalize$1,exports.schema=schema;

@@ -119,3 +119,7 @@ (function (global, factory) {

return _extends({}, input);
} : _options$processStrat;
} : _options$processStrat,
_options$fallbackStra = _options.fallbackStrategy,
fallbackStrategy = _options$fallbackStra === void 0 ? function (key, schema) {
return undefined;
} : _options$fallbackStra;
this._key = key;

@@ -126,2 +130,3 @@ this._getId = typeof idAttribute === 'function' ? idAttribute : getDefaultGetId(idAttribute);

this._processStrategy = processStrategy;
this._fallbackStrategy = fallbackStrategy;
this.define(definition);

@@ -149,2 +154,6 @@ }

_proto.fallback = function fallback(id, schema) {
return this._fallbackStrategy(id, schema);
};
_proto.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {

@@ -537,2 +546,6 @@ var _this = this;

if (entity === undefined && schema instanceof EntitySchema) {
entity = schema.fallback(id, schema);
}
if (typeof entity !== 'object' || entity === null) {

@@ -539,0 +552,0 @@ return entity;

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

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).normalizr={})}(this,function(t){"use strict";function e(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function n(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}function r(){return(r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function i(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function o(t){return!(!t||"function"!=typeof t.hasOwnProperty||!(t.hasOwnProperty("__ownerID")||t._map&&t._map.hasOwnProperty("__ownerID")))}function u(t,e,n){return Object.keys(t).reduce(function(e,r){var i=""+r;return e.has(i)?e.set(i,n(e.get(i),t[i])):e},e)}var c=function(t){return function(e){return o(e)?e.get(t):e[t]}},a=function(){function t(t,e,n){if(void 0===e&&(e={}),void 0===n&&(n={}),!t||"string"!=typeof t)throw new Error("Expected a string key for Entity, but found "+t+".");var i=n,o=i.idAttribute,u=void 0===o?"id":o,a=i.mergeStrategy,f=void 0===a?function(t,e){return r({},t,e)}:a,s=i.processStrategy,h=void 0===s?function(t){return r({},t)}:s;this._key=t,this._getId="function"==typeof u?u:c(u),this._idAttribute=u,this._mergeStrategy=f,this._processStrategy=h,this.define(e)}var e=t.prototype;return e.define=function(t){this.schema=Object.keys(t).reduce(function(e,n){var i,o=t[n];return r({},e,((i={})[n]=o,i))},this.schema||{})},e.getId=function(t,e,n){return this._getId(t,e,n)},e.merge=function(t,e){return this._mergeStrategy(t,e)},e.normalize=function(t,e,n,r,i,o){var u=this,c=this.getId(t,e,n),a=this.key;if(a in o||(o[a]={}),c in o[a]||(o[a][c]=[]),o[a][c].some(function(e){return e===t}))return c;o[a][c].push(t);var f=this._processStrategy(t,e,n);return Object.keys(this.schema).forEach(function(e){if(f.hasOwnProperty(e)&&"object"==typeof f[e]){var n=u.schema[e],c="function"==typeof n?n(t):n;f[e]=r(f[e],f,e,c,i,o)}}),i(this,f,t,e,n),c},e.denormalize=function(t,e){var n=this;return o(t)?u(this.schema,t,e):(Object.keys(this.schema).forEach(function(r){if(t.hasOwnProperty(r)){var i=n.schema[r];t[r]=e(t[r],i)}}),t)},n(t,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),t}(),f=function(){function t(t,e){e&&(this._schemaAttribute="string"==typeof e?function(t){return t[e]}:e),this.define(t)}var e=t.prototype;return e.define=function(t){this.schema=t},e.getSchemaAttribute=function(t,e,n){return!this.isSingleSchema&&this._schemaAttribute(t,e,n)},e.inferSchema=function(t,e,n){if(this.isSingleSchema)return this.schema;var r=this.getSchemaAttribute(t,e,n);return this.schema[r]},e.normalizeValue=function(t,e,n,r,i,o){var u=this.inferSchema(t,e,n);if(!u)return t;var c=r(t,e,n,u,i,o);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(t,e,n)}},e.denormalizeValue=function(t,e){var n=o(t)?t.get("schema"):t.schema;return this.isSingleSchema||n?e((this.isSingleSchema?void 0:o(t)?t.get("id"):t.id)||t,this.isSingleSchema?this.schema:this.schema[n]):t},n(t,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),t}(),s=function(t){function e(e,n){if(!n)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return t.call(this,e,n)||this}i(e,t);var n=e.prototype;return n.normalize=function(t,e,n,r,i,o){return this.normalizeValue(t,e,n,r,i,o)},n.denormalize=function(t,e){return this.denormalizeValue(t,e)},e}(f),h=function(t){function e(){return t.apply(this,arguments)||this}i(e,t);var n=e.prototype;return n.normalize=function(t,e,n,i,o,u){var c=this;return Object.keys(t).reduce(function(e,n,a){var f,s=t[n];return null!=s?r({},e,((f={})[n]=c.normalizeValue(s,t,n,i,o,u),f)):e},{})},n.denormalize=function(t,e){var n=this;return Object.keys(t).reduce(function(i,o){var u,c=t[o];return r({},i,((u={})[o]=n.denormalizeValue(c,e),u))},{})},e}(f),l=function(t){if(Array.isArray(t)&&t.length>1)throw new Error("Expected schema definition to be a single schema, but found "+t.length+".");return t[0]},y=function(t){return Array.isArray(t)?t:Object.keys(t).map(function(e){return t[e]})},m=function(t,e,n,r,i,o,u){return t=l(t),y(e).map(function(e,c){return i(e,n,r,t,o,u)})},p=function(t,e,n){return t=l(t),e&&e.map?e.map(function(e){return n(e,t)}):e},d=function(t){function e(){return t.apply(this,arguments)||this}i(e,t);var n=e.prototype;return n.normalize=function(t,e,n,r,i,o){var u=this;return y(t).map(function(t,c){return u.normalizeValue(t,e,n,r,i,o)}).filter(function(t){return null!=t})},n.denormalize=function(t,e){var n=this;return t&&t.map?t.map(function(t){return n.denormalizeValue(t,e)}):t},e}(f),v=function(t,e,n,i,o,u,c){var a=r({},e);return Object.keys(t).forEach(function(n){var r=t[n],i="function"==typeof r?r(e):r,f=o(e[n],e,n,i,u,c);null==f?delete a[n]:a[n]=f}),a},g=function(t,e,n){if(o(e))return u(t,e,n);var i=r({},e);return Object.keys(t).forEach(function(e){null!=i[e]&&(i[e]=n(i[e],t[e]))}),i},b=function t(e,n,r,i,o,u){return"object"==typeof e&&e?"object"!=typeof i||i.normalize&&"function"==typeof i.normalize?i.normalize(e,n,r,t,o,u):(Array.isArray(i)?m:v)(i,e,n,r,t,o,u):e},z={Array:d,Entity:a,Object:function(){function t(t){this.define(t)}var e=t.prototype;return e.define=function(t){this.schema=Object.keys(t).reduce(function(e,n){var i,o=t[n];return r({},e,((i={})[n]=o,i))},this.schema||{})},e.normalize=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return v.apply(void 0,[this.schema].concat(e))},e.denormalize=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return g.apply(void 0,[this.schema].concat(e))},t}(),Union:s,Values:h},k=function(t){var e={},n=S(t);return function t(i,u){return"object"!=typeof u||u.denormalize&&"function"==typeof u.denormalize?null==i?i:u instanceof a?function(t,e,n,i,u){var c=i(t,e);if("object"!=typeof c||null===c)return c;if(u[e.key]||(u[e.key]={}),!u[e.key][t]){var a=o(c)?c:r({},c);u[e.key][t]=a,u[e.key][t]=e.denormalize(a,n)}return u[e.key][t]}(i,u,t,n,e):u.denormalize(i,t):(Array.isArray(u)?p:g)(u,i,t)}},S=function(t){var e=o(t);return function(n,r){var i=r.key;return"object"==typeof n?n:e?t.getIn([i,n.toString()]):t[i]&&t[i][n]}};t.denormalize=function(t,e,n){if(void 0!==t)return k(n)(t,e)},t.normalize=function(t,e){if(!t||"object"!=typeof t)throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+(null===t?"null":typeof t)+'".');var n={},r=function(t){return function(e,n,r,i,o){var u=e.key,c=e.getId(r,i,o);u in t||(t[u]={});var a=t[u][c];t[u][c]=a?e.merge(a,n):n}}(n);return{entities:n,result:b(t,t,null,e,r,{})}},t.schema=z,Object.defineProperty(t,"__esModule",{value:!0})});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).normalizr={})}(this,function(t){"use strict";function e(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function n(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}function r(){return(r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function i(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function o(t){return!(!t||"function"!=typeof t.hasOwnProperty||!(t.hasOwnProperty("__ownerID")||t._map&&t._map.hasOwnProperty("__ownerID")))}function u(t,e,n){return Object.keys(t).reduce(function(e,r){var i=""+r;return e.has(i)?e.set(i,n(e.get(i),t[i])):e},e)}var a=function(t){return function(e){return o(e)?e.get(t):e[t]}},c=function(){function t(t,e,n){if(void 0===e&&(e={}),void 0===n&&(n={}),!t||"string"!=typeof t)throw new Error("Expected a string key for Entity, but found "+t+".");var i=n,o=i.idAttribute,u=void 0===o?"id":o,c=i.mergeStrategy,f=void 0===c?function(t,e){return r({},t,e)}:c,s=i.processStrategy,h=void 0===s?function(t){return r({},t)}:s,l=i.fallbackStrategy,y=void 0===l?function(t,e){}:l;this._key=t,this._getId="function"==typeof u?u:a(u),this._idAttribute=u,this._mergeStrategy=f,this._processStrategy=h,this._fallbackStrategy=y,this.define(e)}var e=t.prototype;return e.define=function(t){this.schema=Object.keys(t).reduce(function(e,n){var i,o=t[n];return r({},e,((i={})[n]=o,i))},this.schema||{})},e.getId=function(t,e,n){return this._getId(t,e,n)},e.merge=function(t,e){return this._mergeStrategy(t,e)},e.fallback=function(t,e){return this._fallbackStrategy(t,e)},e.normalize=function(t,e,n,r,i,o){var u=this,a=this.getId(t,e,n),c=this.key;if(c in o||(o[c]={}),a in o[c]||(o[c][a]=[]),o[c][a].some(function(e){return e===t}))return a;o[c][a].push(t);var f=this._processStrategy(t,e,n);return Object.keys(this.schema).forEach(function(e){if(f.hasOwnProperty(e)&&"object"==typeof f[e]){var n=u.schema[e],a="function"==typeof n?n(t):n;f[e]=r(f[e],f,e,a,i,o)}}),i(this,f,t,e,n),a},e.denormalize=function(t,e){var n=this;return o(t)?u(this.schema,t,e):(Object.keys(this.schema).forEach(function(r){if(t.hasOwnProperty(r)){var i=n.schema[r];t[r]=e(t[r],i)}}),t)},n(t,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),t}(),f=function(){function t(t,e){e&&(this._schemaAttribute="string"==typeof e?function(t){return t[e]}:e),this.define(t)}var e=t.prototype;return e.define=function(t){this.schema=t},e.getSchemaAttribute=function(t,e,n){return!this.isSingleSchema&&this._schemaAttribute(t,e,n)},e.inferSchema=function(t,e,n){if(this.isSingleSchema)return this.schema;var r=this.getSchemaAttribute(t,e,n);return this.schema[r]},e.normalizeValue=function(t,e,n,r,i,o){var u=this.inferSchema(t,e,n);if(!u)return t;var a=r(t,e,n,u,i,o);return this.isSingleSchema||null==a?a:{id:a,schema:this.getSchemaAttribute(t,e,n)}},e.denormalizeValue=function(t,e){var n=o(t)?t.get("schema"):t.schema;return this.isSingleSchema||n?e((this.isSingleSchema?void 0:o(t)?t.get("id"):t.id)||t,this.isSingleSchema?this.schema:this.schema[n]):t},n(t,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),t}(),s=function(t){function e(e,n){if(!n)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return t.call(this,e,n)||this}i(e,t);var n=e.prototype;return n.normalize=function(t,e,n,r,i,o){return this.normalizeValue(t,e,n,r,i,o)},n.denormalize=function(t,e){return this.denormalizeValue(t,e)},e}(f),h=function(t){function e(){return t.apply(this,arguments)||this}i(e,t);var n=e.prototype;return n.normalize=function(t,e,n,i,o,u){var a=this;return Object.keys(t).reduce(function(e,n,c){var f,s=t[n];return null!=s?r({},e,((f={})[n]=a.normalizeValue(s,t,n,i,o,u),f)):e},{})},n.denormalize=function(t,e){var n=this;return Object.keys(t).reduce(function(i,o){var u,a=t[o];return r({},i,((u={})[o]=n.denormalizeValue(a,e),u))},{})},e}(f),l=function(t){if(Array.isArray(t)&&t.length>1)throw new Error("Expected schema definition to be a single schema, but found "+t.length+".");return t[0]},y=function(t){return Array.isArray(t)?t:Object.keys(t).map(function(e){return t[e]})},m=function(t,e,n,r,i,o,u){return t=l(t),y(e).map(function(e,a){return i(e,n,r,t,o,u)})},p=function(t,e,n){return t=l(t),e&&e.map?e.map(function(e){return n(e,t)}):e},d=function(t){function e(){return t.apply(this,arguments)||this}i(e,t);var n=e.prototype;return n.normalize=function(t,e,n,r,i,o){var u=this;return y(t).map(function(t,a){return u.normalizeValue(t,e,n,r,i,o)}).filter(function(t){return null!=t})},n.denormalize=function(t,e){var n=this;return t&&t.map?t.map(function(t){return n.denormalizeValue(t,e)}):t},e}(f),v=function(t,e,n,i,o,u,a){var c=r({},e);return Object.keys(t).forEach(function(n){var r=t[n],i="function"==typeof r?r(e):r,f=o(e[n],e,n,i,u,a);null==f?delete c[n]:c[n]=f}),c},g=function(t,e,n){if(o(e))return u(t,e,n);var i=r({},e);return Object.keys(t).forEach(function(e){null!=i[e]&&(i[e]=n(i[e],t[e]))}),i},b=function t(e,n,r,i,o,u){return"object"==typeof e&&e?"object"!=typeof i||i.normalize&&"function"==typeof i.normalize?i.normalize(e,n,r,t,o,u):(Array.isArray(i)?m:v)(i,e,n,r,t,o,u):e},k={Array:d,Entity:c,Object:function(){function t(t){this.define(t)}var e=t.prototype;return e.define=function(t){this.schema=Object.keys(t).reduce(function(e,n){var i,o=t[n];return r({},e,((i={})[n]=o,i))},this.schema||{})},e.normalize=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return v.apply(void 0,[this.schema].concat(e))},e.denormalize=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return g.apply(void 0,[this.schema].concat(e))},t}(),Union:s,Values:h},S=function(t){var e={},n=z(t);return function t(i,u){return"object"!=typeof u||u.denormalize&&"function"==typeof u.denormalize?null==i?i:u instanceof c?function(t,e,n,i,u){var a=i(t,e);if(void 0===a&&e instanceof c&&(a=e.fallback(t,e)),"object"!=typeof a||null===a)return a;if(u[e.key]||(u[e.key]={}),!u[e.key][t]){var f=o(a)?a:r({},a);u[e.key][t]=f,u[e.key][t]=e.denormalize(f,n)}return u[e.key][t]}(i,u,t,n,e):u.denormalize(i,t):(Array.isArray(u)?p:g)(u,i,t)}},z=function(t){var e=o(t);return function(n,r){var i=r.key;return"object"==typeof n?n:e?t.getIn([i,n.toString()]):t[i]&&t[i][n]}};t.denormalize=function(t,e,n){if(void 0!==t)return S(n)(t,e)},t.normalize=function(t,e){if(!t||"object"!=typeof t)throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+(null===t?"null":typeof t)+'".');var n={},r=function(t){return function(e,n,r,i,o){var u=e.key,a=e.getId(r,i,o);u in t||(t[u]={});var c=t[u][a];t[u][a]=c?e.merge(c,n):n}}(n);return{entities:n,result:b(t,t,null,e,r,{})}},t.schema=k,Object.defineProperty(t,"__esModule",{value:!0})});

@@ -60,3 +60,3 @@ declare namespace schema {

export function normalize<T = any, E = { [key:string]: { [key:string]: T }}, R = any>(
export function normalize<T = any, E = { [key:string]: { [key:string]: T } | undefined}, R = any>(
data: any,

@@ -63,0 +63,0 @@ schema: Schema<T>

{
"name": "normalizr",
"version": "3.5.0",
"version": "3.6.0",
"description": "Normalizes and denormalizes JSON according to schema for Redux and Flux applications",

@@ -5,0 +5,0 @@ "bugs": {

@@ -1,2 +0,2 @@

# normalizr [![build status](https://img.shields.io/travis/paularmstrong/normalizr/master.svg?style=flat-square)](https://travis-ci.org/paularmstrong/normalizr) [![Coverage Status](https://img.shields.io/coveralls/paularmstrong/normalizr/master.svg?style=flat-square)](https://coveralls.io/github/paularmstrong/normalizr?branch=master) [![npm version](https://img.shields.io/npm/v/normalizr.svg?style=flat-square)](https://www.npmjs.com/package/normalizr) [![npm downloads](https://img.shields.io/npm/dm/normalizr.svg?style=flat-square)](https://www.npmjs.com/package/normalizr) [![Greenkeeper badge](https://badges.greenkeeper.io/paularmstrong/normalizr.svg)](https://greenkeeper.io/)
# normalizr [![build status](https://img.shields.io/travis/paularmstrong/normalizr/master.svg?style=flat-square)](https://travis-ci.org/paularmstrong/normalizr) [![Coverage Status](https://img.shields.io/coveralls/paularmstrong/normalizr/master.svg?style=flat-square)](https://coveralls.io/github/paularmstrong/normalizr?branch=master) [![npm version](https://img.shields.io/npm/v/normalizr.svg?style=flat-square)](https://www.npmjs.com/package/normalizr) [![npm downloads](https://img.shields.io/npm/dm/normalizr.svg?style=flat-square)](https://www.npmjs.com/package/normalizr)

@@ -3,0 +3,0 @@ ## Install

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