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