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

@rest-hooks/normalizr

Package Overview
Dependencies
Maintainers
1
Versions
126
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rest-hooks/normalizr - npm Package Compare versions

Comparing version 6.0.0-beta.1 to 6.0.0-beta.2

19

CHANGELOG.md

@@ -6,2 +6,21 @@ # Change Log

## [6.0.0-beta.2](https://github.com/coinbase/rest-hooks/compare/@rest-hooks/normalizr@6.0.0-beta.1...@rest-hooks/normalizr@6.0.0-beta.2) (2020-05-08)
### 💅 Enhancement
* Detect more cases of network mismatching schema ([#331](https://github.com/coinbase/rest-hooks/issues/331)) ([2af464f](https://github.com/coinbase/rest-hooks/commit/2af464f54318c5f099899150371c911133a717cb))
### 🐛 Bug Fix
* Allow for multiple pk methods ([#333](https://github.com/coinbase/rest-hooks/issues/333)) ([7ea9ed9](https://github.com/coinbase/rest-hooks/commit/7ea9ed9ee4701b2ba1bb1cf29743ae755ed909e8))
### 🏠 Internal
* Improve test coverage ([#330](https://github.com/coinbase/rest-hooks/issues/330)) ([edc5f73](https://github.com/coinbase/rest-hooks/commit/edc5f73471fc2b68a95b4ef09d883e7dab016d7d))
## [6.0.0-beta.1](https://github.com/coinbase/rest-hooks/compare/@rest-hooks/normalizr@6.0.0-beta.0...@rest-hooks/normalizr@6.0.0-beta.1) (2020-05-04)

@@ -8,0 +27,0 @@

48

dist/normalizr.amd.js

@@ -321,8 +321,40 @@ define(['exports'], function (exports) { 'use strict';

const processedEntity = this.fromJS(input, parent, key);
/* istanbul ignore else */
if (process.env.NODE_ENV !== 'production') {
const instanceSample = new this();
const keysOfRecord = new Set(Object.keys(instanceSample));
let [sameCount, diffCount] = [0, 0];
let extraKey = false;
for (const keyOfProps of Entity.keysDefined(processedEntity)) {
if (keysOfRecord.has(keyOfProps)) {
sameCount++;
} else {
diffCount++;
extraKey = true;
}
}
diffCount += keysOfRecord.size - sameCount;
if (diffCount > sameCount && keysOfRecord.size && extraKey) {
const error = new Error(`Attempted to initialize ${this.name} with substantially different than expected keys
This is likely due to a malformed response.
Try inspecting the network response or fetch() return value.
Expected keys: ${Object.keys(instanceSample)}
Value: ${JSON.stringify(Entity.toObjectDefined(processedEntity), null, 2)}`);
error.status = 400;
throw error;
}
}
const id = processedEntity.pk(parent, key);
/* istanbul ignore next */
if (id === undefined) {
if (process.env.NODE_ENV !== 'production' && id === undefined) {
throw new Error(`Missing usable resource key when normalizing response.
if (id === undefined || id === '') {
/* istanbul ignore else */
if (process.env.NODE_ENV !== 'production') {
const error = new Error(`Missing usable resource key when normalizing response.

@@ -332,5 +364,7 @@ This is likely due to a malformed response.

Entity: ${this}
Entity: ${this.name}
Value: ${input && JSON.stringify(input, null, 2)}
`);
error.status = 400;
throw error;
} else {

@@ -362,3 +396,3 @@ throw new Error('undefined pk');

});
addEntity(this, processedEntity, input, parent, key);
addEntity(this, processedEntity, processedEntity, parent, key);
return id;

@@ -517,3 +551,3 @@ }

const schemaKey = schema.key;
const id = schema.pk(processedEntity, parent, key);
const id = schema.pk(value, parent, key);

@@ -520,0 +554,0 @@ if (!(schemaKey in entities)) {

2

dist/normalizr.amd.min.js

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

define(["exports"],(function(e){"use strict";function t(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(Object.hasOwnProperty.call(e,"__ownerID")||e._map&&Object.hasOwnProperty.call(e._map,"__ownerID")))}function n(e,t,n){let r=!0;return[Object.keys(e).reduce((t,i)=>{const s=`${i}`,[o,c]=n(t.get(s),e[s]);return c||(r=!1),t.has(s)?t.set(s,o):t},t),r]}class r{constructor(e,t){t&&(this._schemaAttribute="string"==typeof t?e=>e[t]:t),this.define(e)}get isSingleSchema(){return!this._schemaAttribute}define(e){this.schema=e}getSchemaAttribute(e,t,n){return!this.isSingleSchema&&this._schemaAttribute(e,t,n)}inferSchema(e,t,n){if(this.isSingleSchema)return this.schema;const r=this.getSchemaAttribute(e,t,n);return this.schema[r]}normalizeValue(e,t,n,r,i,s){const o=this.inferSchema(e,t,n);if(!o)return e;const c=r(e,t,n,o,i,s);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,n)}}denormalizeValue(e,n){const r=t(e)?e.get("schema"):e.schema;return this.isSingleSchema||r?n((this.isSingleSchema?void 0:t(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[r]):[e,!0]}}const i=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]},s=e=>Array.isArray(e)?e:Object.keys(e).map(t=>e[t]),o=(e,t,n,r,o,c,a)=>(e=i(e),s(t).map((t,i)=>o(t,n,r,e,c,a))),c=(e,t,n)=>{e=i(e);let r=!0;return void 0===t&&e&&([,r]=n(void 0,e)),[t&&t.map?t.map(t=>n(t,e)).filter(([,e])=>e).map(([e])=>e):t,r]};const a=(e,t,n,r,i,s,o)=>{const c=Object.assign({},t);return Object.keys(e).forEach(n=>{const r=e[n],a=i(t[n],t,n,r,s,o);null==a?delete c[n]:c[n]=a}),c},u=(e,r,i)=>{if(t(r))return n(e,r,i);const s=Object.assign({},r);let o=!0;return Object.keys(e).forEach(t=>{const[n,r]=i(s[t],e[t]);void 0!==s[t]&&(s[t]=n),r||(o=!1)}),[s,o]};const l=Symbol("Defined Members"),h=Symbol("unq");class m{toString(){return this[h]}static fromJS(e={},t,n){const r=new this(e);return Object.assign(r,e),Object.defineProperty(r,l,{value:Object.keys(e),writable:!1}),Object.defineProperty(r,h,{value:`${Math.random()}`,writable:!1}),r}static merge(e,t){const n=Object.assign(this.toObjectDefined(e),this.toObjectDefined(t));return this.fromJS(n)}static hasDefined(e,t){return e[l].includes(t)}static toObjectDefined(e){const t={};for(const n of e[l])t[n]=e[n];return t}static keysDefined(e){return e[l]}}class f extends m{static get key(){if("production"!==process.env.NODE_ENV&&""===this.name)throw new Error("Entity classes without a name must define `static get key()`");return this.name}static pk(e,t,n){return this.prototype.pk.call(e,t,n)||n}static asSchema(){return this}static normalize(e,t,n,r,i,s){const o=this.fromJS(e,t,n),c=o.pk(t,n);if(void 0===c)throw"production"!==process.env.NODE_ENV&&void 0===c?new Error(`Missing usable resource key when normalizing response.\n\n This is likely due to a malformed response.\n Try inspecting the network response or fetch() return value.\n\n Entity: ${this}\n Value: ${e&&JSON.stringify(e,null,2)}\n `):new Error("undefined pk");const a=this.key;return a in s||(s[a]={}),c in s[a]||(s[a][c]=[]),s[a][c].some(t=>t===e)||(s[a][c].push(e),Object.keys(this.schema).forEach(e=>{if(Object.hasOwnProperty.call(o,e)&&"object"==typeof o[e]){const t=this.schema[e];o[e]=r(o[e],o,e,t,i,s)}}),i(this,o,e,t,n)),c}static denormalize(e,r){if(t(e)){const[t,i]=n(this.schema,e,r);return[this.fromJS(t.toObject()),i]}let i=!0;const s=e;return Object.keys(this.schema).forEach(t=>{const n=this.schema[t],[o,c]=r(e[t],n);c||(i=!1),this.hasDefined(e,t)&&s[t]!==o&&(s[t]=o)}),[s,i]}}function d(e){return null!==e&&void 0!==e.pk}f.schema={},"production"!==process.env.NODE_ENV&&(f.fromJS=function(e){if(void 0===this.prototype.pk)throw new Error("cannot construct on abstract types");return m.fromJS.call(this,e)});class y extends f{static denormalize(e,t){return[e,!0]}}const p=e=>{const n={},r=b(e);return[function e(i,s){if(!s)return[i,!0];if("object"==typeof s&&(!s.denormalize||"function"!=typeof s.denormalize)){return(Array.isArray(s)?c:u)(s,i,e)}return null===i?[i,!0]:d(s)?void 0===i?[i,!1]:((e,n,r,i,s)=>{const o=i(e,n);if("object"!=typeof o||null===o)return[o,!1];s[n.key]||(s[n.key]={});let c=!0;if(!s[n.key][e]){const i=t(o)||o instanceof y?o:n.fromJS(o);s[n.key][e]=i,[s[n.key][e],c]=n.denormalize(i,r)}return[s[n.key][e],c]})(i,s,e,r,n):"function"==typeof s.denormalize?s.denormalize(i,e):[i,!0]},n]},b=e=>{const n=t(e);return(t,r)=>{const i=r.key;return"object"==typeof t?t:n?e.getIn([i,t]):e[i]&&e[i][t]}},O=(e,t,n,r,i,s)=>{if("object"!=typeof e||!e||!r)return e;if("object"==typeof r&&(!r.normalize||"function"!=typeof r.normalize)){return(Array.isArray(r)?o:a)(r,e,t,n,O,i,s)}return r.normalize(e,t,n,O,i,s)};var g=Object.freeze({__proto__:null,Union:class extends r{constructor(e,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');super(e,t)}normalize(e,t,n,r,i,s){return this.normalizeValue(e,t,n,r,i,s)}denormalize(e,t){return this.denormalizeValue(e,t)}},Values:class extends r{normalize(e,t,n,r,i,s){return Object.keys(e).reduce((t,n,o)=>{const c=e[n];return null!=c?Object.assign({},t,{[n]:this.normalizeValue(c,e,n,r,i,s)}):t},{})}denormalize(e,t){let n=!0;return[Object.keys(e).reduce((r,i)=>{const s=e[i],[o,c]=this.denormalizeValue(s,t);return c||(n=!1),Object.assign({},r,{[i]:o})},{}),n]}},Array:class extends r{normalize(e,t,n,r,i,o){return s(e).map((e,s)=>this.normalizeValue(e,t,n,r,i,o)).filter(e=>null!=e)}denormalize(e,t){let n=!0;return void 0===e&&this.schema&&([,n]=t(void 0,this.schema)),[e&&e.map?e.map(e=>this.denormalizeValue(e,t)).filter(([,e])=>e).map(([e])=>e):e,n]}},Object:class{constructor(e){this.define(e)}define(e){this.schema=Object.keys(e).reduce((t,n)=>{const r=e[n];return Object.assign({},t,{[n]:r})},this.schema||{})}normalize(...e){return a(this.schema,...e)}denormalize(...e){return u(this.schema,...e)}}});e.Entity=f,e.FlatEntity=y,e.SimpleRecord=m,e.denormalize=(e,t,n)=>{if("production"!==process.env.NODE_ENV&&void 0===t)throw new Error("schema needed");if(void 0!==e){const[r,i]=p(n);return[...r(e,t),i]}return[void 0,!1,{}]},e.isEntity=d,e.normalize=(e,t)=>{const n=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(t);if(null===e||typeof e!==n)throw new Error(`Unexpected input given to normalize. Expected type to be "${n}", found "${null===e?"null":typeof e}".`);const r={},i={},s=((e,t)=>(n,r,i,s,o)=>{const c=n.key,a=n.pk(r,s,o);c in e||(e[c]={});const u=e[c][a];if(e[c][a]=u?n.merge(u,r):r,Array.isArray(n.indexes)){const r=e[c][a];c in t||(t[c]={});for(const e of n.indexes){e in t[c]||(t[c][e]={});const n=t[c][e];u&&delete n[u[e]],e in r?n[r[e]]=a:"production"!==process.env.NODE_ENV&&console.warn(`Index not found in entity. Indexes must be top-level members of your entity.\nIndex: ${e}\nEntity: ${JSON.stringify(r,void 0,2)}`)}}})(r,i);return{entities:r,indexes:i,result:O(e,e,void 0,t,s,{})}},e.schema=g,Object.defineProperty(e,"__esModule",{value:!0})}));
define(["exports"],(function(e){"use strict";function t(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(Object.hasOwnProperty.call(e,"__ownerID")||e._map&&Object.hasOwnProperty.call(e._map,"__ownerID")))}function n(e,t,n){let r=!0;return[Object.keys(e).reduce((t,s)=>{const i=`${s}`,[o,c]=n(t.get(i),e[i]);return c||(r=!1),t.has(i)?t.set(i,o):t},t),r]}class r{constructor(e,t){t&&(this._schemaAttribute="string"==typeof t?e=>e[t]:t),this.define(e)}get isSingleSchema(){return!this._schemaAttribute}define(e){this.schema=e}getSchemaAttribute(e,t,n){return!this.isSingleSchema&&this._schemaAttribute(e,t,n)}inferSchema(e,t,n){if(this.isSingleSchema)return this.schema;const r=this.getSchemaAttribute(e,t,n);return this.schema[r]}normalizeValue(e,t,n,r,s,i){const o=this.inferSchema(e,t,n);if(!o)return e;const c=r(e,t,n,o,s,i);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,n)}}denormalizeValue(e,n){const r=t(e)?e.get("schema"):e.schema;return this.isSingleSchema||r?n((this.isSingleSchema?void 0:t(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[r]):[e,!0]}}const s=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]},i=e=>Array.isArray(e)?e:Object.keys(e).map(t=>e[t]),o=(e,t,n,r,o,c,a)=>(e=s(e),i(t).map((t,s)=>o(t,n,r,e,c,a))),c=(e,t,n)=>{e=s(e);let r=!0;return void 0===t&&e&&([,r]=n(void 0,e)),[t&&t.map?t.map(t=>n(t,e)).filter(([,e])=>e).map(([e])=>e):t,r]};const a=(e,t,n,r,s,i,o)=>{const c=Object.assign({},t);return Object.keys(e).forEach(n=>{const r=e[n],a=s(t[n],t,n,r,i,o);null==a?delete c[n]:c[n]=a}),c},u=(e,r,s)=>{if(t(r))return n(e,r,s);const i=Object.assign({},r);let o=!0;return Object.keys(e).forEach(t=>{const[n,r]=s(i[t],e[t]);void 0!==i[t]&&(i[t]=n),r||(o=!1)}),[i,o]};const l=Symbol("Defined Members"),h=Symbol("unq");class m{toString(){return this[h]}static fromJS(e={},t,n){const r=new this(e);return Object.assign(r,e),Object.defineProperty(r,l,{value:Object.keys(e),writable:!1}),Object.defineProperty(r,h,{value:`${Math.random()}`,writable:!1}),r}static merge(e,t){const n=Object.assign(this.toObjectDefined(e),this.toObjectDefined(t));return this.fromJS(n)}static hasDefined(e,t){return e[l].includes(t)}static toObjectDefined(e){const t={};for(const n of e[l])t[n]=e[n];return t}static keysDefined(e){return e[l]}}class f extends m{static get key(){if("production"!==process.env.NODE_ENV&&""===this.name)throw new Error("Entity classes without a name must define `static get key()`");return this.name}static pk(e,t,n){return this.prototype.pk.call(e,t,n)||n}static asSchema(){return this}static normalize(e,t,n,r,s,i){const o=this.fromJS(e,t,n);if("production"!==process.env.NODE_ENV){const e=new this,t=new Set(Object.keys(e));let[n,r]=[0,0],s=!1;for(const e of f.keysDefined(o))t.has(e)?n++:(r++,s=!0);if(r+=t.size-n,r>n&&t.size&&s){const t=new Error(`Attempted to initialize ${this.name} with substantially different than expected keys\n\n This is likely due to a malformed response.\n Try inspecting the network response or fetch() return value.\n\n Expected keys: ${Object.keys(e)}\n Value: ${JSON.stringify(f.toObjectDefined(o),null,2)}`);throw t.status=400,t}}const c=o.pk(t,n);if(void 0===c||""===c){if("production"!==process.env.NODE_ENV){const t=new Error(`Missing usable resource key when normalizing response.\n\n This is likely due to a malformed response.\n Try inspecting the network response or fetch() return value.\n\n Entity: ${this.name}\n Value: ${e&&JSON.stringify(e,null,2)}\n `);throw t.status=400,t}throw new Error("undefined pk")}const a=this.key;return a in i||(i[a]={}),c in i[a]||(i[a][c]=[]),i[a][c].some(t=>t===e)||(i[a][c].push(e),Object.keys(this.schema).forEach(e=>{if(Object.hasOwnProperty.call(o,e)&&"object"==typeof o[e]){const t=this.schema[e];o[e]=r(o[e],o,e,t,s,i)}}),s(this,o,o,t,n)),c}static denormalize(e,r){if(t(e)){const[t,s]=n(this.schema,e,r);return[this.fromJS(t.toObject()),s]}let s=!0;const i=e;return Object.keys(this.schema).forEach(t=>{const n=this.schema[t],[o,c]=r(e[t],n);c||(s=!1),this.hasDefined(e,t)&&i[t]!==o&&(i[t]=o)}),[i,s]}}function d(e){return null!==e&&void 0!==e.pk}f.schema={},"production"!==process.env.NODE_ENV&&(f.fromJS=function(e){if(void 0===this.prototype.pk)throw new Error("cannot construct on abstract types");return m.fromJS.call(this,e)});class y extends f{static denormalize(e,t){return[e,!0]}}const p=e=>{const n={},r=b(e);return[function e(s,i){if(!i)return[s,!0];if("object"==typeof i&&(!i.denormalize||"function"!=typeof i.denormalize)){return(Array.isArray(i)?c:u)(i,s,e)}return null===s?[s,!0]:d(i)?void 0===s?[s,!1]:((e,n,r,s,i)=>{const o=s(e,n);if("object"!=typeof o||null===o)return[o,!1];i[n.key]||(i[n.key]={});let c=!0;if(!i[n.key][e]){const s=t(o)||o instanceof y?o:n.fromJS(o);i[n.key][e]=s,[i[n.key][e],c]=n.denormalize(s,r)}return[i[n.key][e],c]})(s,i,e,r,n):"function"==typeof i.denormalize?i.denormalize(s,e):[s,!0]},n]},b=e=>{const n=t(e);return(t,r)=>{const s=r.key;return"object"==typeof t?t:n?e.getIn([s,t]):e[s]&&e[s][t]}},O=(e,t,n,r,s,i)=>{if("object"!=typeof e||!e||!r)return e;if("object"==typeof r&&(!r.normalize||"function"!=typeof r.normalize)){return(Array.isArray(r)?o:a)(r,e,t,n,O,s,i)}return r.normalize(e,t,n,O,s,i)};var j=Object.freeze({__proto__:null,Union:class extends r{constructor(e,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');super(e,t)}normalize(e,t,n,r,s,i){return this.normalizeValue(e,t,n,r,s,i)}denormalize(e,t){return this.denormalizeValue(e,t)}},Values:class extends r{normalize(e,t,n,r,s,i){return Object.keys(e).reduce((t,n,o)=>{const c=e[n];return null!=c?Object.assign({},t,{[n]:this.normalizeValue(c,e,n,r,s,i)}):t},{})}denormalize(e,t){let n=!0;return[Object.keys(e).reduce((r,s)=>{const i=e[s],[o,c]=this.denormalizeValue(i,t);return c||(n=!1),Object.assign({},r,{[s]:o})},{}),n]}},Array:class extends r{normalize(e,t,n,r,s,o){return i(e).map((e,i)=>this.normalizeValue(e,t,n,r,s,o)).filter(e=>null!=e)}denormalize(e,t){let n=!0;return void 0===e&&this.schema&&([,n]=t(void 0,this.schema)),[e&&e.map?e.map(e=>this.denormalizeValue(e,t)).filter(([,e])=>e).map(([e])=>e):e,n]}},Object:class{constructor(e){this.define(e)}define(e){this.schema=Object.keys(e).reduce((t,n)=>{const r=e[n];return Object.assign({},t,{[n]:r})},this.schema||{})}normalize(...e){return a(this.schema,...e)}denormalize(...e){return u(this.schema,...e)}}});e.Entity=f,e.FlatEntity=y,e.SimpleRecord=m,e.denormalize=(e,t,n)=>{if("production"!==process.env.NODE_ENV&&void 0===t)throw new Error("schema needed");if(void 0!==e){const[r,s]=p(n);return[...r(e,t),s]}return[void 0,!1,{}]},e.isEntity=d,e.normalize=(e,t)=>{const n=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(t);if(null===e||typeof e!==n)throw new Error(`Unexpected input given to normalize. Expected type to be "${n}", found "${null===e?"null":typeof e}".`);const r={},s={},i=((e,t)=>(n,r,s,i,o)=>{const c=n.key,a=n.pk(s,i,o);c in e||(e[c]={});const u=e[c][a];if(e[c][a]=u?n.merge(u,r):r,Array.isArray(n.indexes)){const r=e[c][a];c in t||(t[c]={});for(const e of n.indexes){e in t[c]||(t[c][e]={});const n=t[c][e];u&&delete n[u[e]],e in r?n[r[e]]=a:"production"!==process.env.NODE_ENV&&console.warn(`Index not found in entity. Indexes must be top-level members of your entity.\nIndex: ${e}\nEntity: ${JSON.stringify(r,void 0,2)}`)}}})(r,s);return{entities:r,indexes:s,result:O(e,e,void 0,t,i,{})}},e.schema=j,Object.defineProperty(e,"__esModule",{value:!0})}));

@@ -322,8 +322,40 @@ var rest_hooks_normalizr = (function (exports) {

const processedEntity = this.fromJS(input, parent, key);
/* istanbul ignore else */
if (process.env.NODE_ENV !== 'production') {
const instanceSample = new this();
const keysOfRecord = new Set(Object.keys(instanceSample));
let [sameCount, diffCount] = [0, 0];
let extraKey = false;
for (const keyOfProps of Entity.keysDefined(processedEntity)) {
if (keysOfRecord.has(keyOfProps)) {
sameCount++;
} else {
diffCount++;
extraKey = true;
}
}
diffCount += keysOfRecord.size - sameCount;
if (diffCount > sameCount && keysOfRecord.size && extraKey) {
const error = new Error(`Attempted to initialize ${this.name} with substantially different than expected keys
This is likely due to a malformed response.
Try inspecting the network response or fetch() return value.
Expected keys: ${Object.keys(instanceSample)}
Value: ${JSON.stringify(Entity.toObjectDefined(processedEntity), null, 2)}`);
error.status = 400;
throw error;
}
}
const id = processedEntity.pk(parent, key);
/* istanbul ignore next */
if (id === undefined) {
if (process.env.NODE_ENV !== 'production' && id === undefined) {
throw new Error(`Missing usable resource key when normalizing response.
if (id === undefined || id === '') {
/* istanbul ignore else */
if (process.env.NODE_ENV !== 'production') {
const error = new Error(`Missing usable resource key when normalizing response.

@@ -333,5 +365,7 @@ This is likely due to a malformed response.

Entity: ${this}
Entity: ${this.name}
Value: ${input && JSON.stringify(input, null, 2)}
`);
error.status = 400;
throw error;
} else {

@@ -363,3 +397,3 @@ throw new Error('undefined pk');

});
addEntity(this, processedEntity, input, parent, key);
addEntity(this, processedEntity, processedEntity, parent, key);
return id;

@@ -518,3 +552,3 @@ }

const schemaKey = schema.key;
const id = schema.pk(processedEntity, parent, key);
const id = schema.pk(value, parent, key);

@@ -521,0 +555,0 @@ if (!(schemaKey in entities)) {

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

var rest_hooks_normalizr=function(e){"use strict";function t(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(Object.hasOwnProperty.call(e,"__ownerID")||e._map&&Object.hasOwnProperty.call(e._map,"__ownerID")))}function n(e,t,n){let r=!0;return[Object.keys(e).reduce((t,i)=>{const s=`${i}`,[o,c]=n(t.get(s),e[s]);return c||(r=!1),t.has(s)?t.set(s,o):t},t),r]}class r{constructor(e,t){t&&(this._schemaAttribute="string"==typeof t?e=>e[t]:t),this.define(e)}get isSingleSchema(){return!this._schemaAttribute}define(e){this.schema=e}getSchemaAttribute(e,t,n){return!this.isSingleSchema&&this._schemaAttribute(e,t,n)}inferSchema(e,t,n){if(this.isSingleSchema)return this.schema;const r=this.getSchemaAttribute(e,t,n);return this.schema[r]}normalizeValue(e,t,n,r,i,s){const o=this.inferSchema(e,t,n);if(!o)return e;const c=r(e,t,n,o,i,s);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,n)}}denormalizeValue(e,n){const r=t(e)?e.get("schema"):e.schema;return this.isSingleSchema||r?n((this.isSingleSchema?void 0:t(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[r]):[e,!0]}}const i=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]},s=e=>Array.isArray(e)?e:Object.keys(e).map(t=>e[t]),o=(e,t,n,r,o,c,a)=>(e=i(e),s(t).map((t,i)=>o(t,n,r,e,c,a))),c=(e,t,n)=>{e=i(e);let r=!0;return void 0===t&&e&&([,r]=n(void 0,e)),[t&&t.map?t.map(t=>n(t,e)).filter(([,e])=>e).map(([e])=>e):t,r]};const a=(e,t,n,r,i,s,o)=>{const c=Object.assign({},t);return Object.keys(e).forEach(n=>{const r=e[n],a=i(t[n],t,n,r,s,o);null==a?delete c[n]:c[n]=a}),c},u=(e,r,i)=>{if(t(r))return n(e,r,i);const s=Object.assign({},r);let o=!0;return Object.keys(e).forEach(t=>{const[n,r]=i(s[t],e[t]);void 0!==s[t]&&(s[t]=n),r||(o=!1)}),[s,o]};const l=Symbol("Defined Members"),h=Symbol("unq");class m{toString(){return this[h]}static fromJS(e={},t,n){const r=new this(e);return Object.assign(r,e),Object.defineProperty(r,l,{value:Object.keys(e),writable:!1}),Object.defineProperty(r,h,{value:`${Math.random()}`,writable:!1}),r}static merge(e,t){const n=Object.assign(this.toObjectDefined(e),this.toObjectDefined(t));return this.fromJS(n)}static hasDefined(e,t){return e[l].includes(t)}static toObjectDefined(e){const t={};for(const n of e[l])t[n]=e[n];return t}static keysDefined(e){return e[l]}}class f extends m{static get key(){if("production"!==process.env.NODE_ENV&&""===this.name)throw new Error("Entity classes without a name must define `static get key()`");return this.name}static pk(e,t,n){return this.prototype.pk.call(e,t,n)||n}static asSchema(){return this}static normalize(e,t,n,r,i,s){const o=this.fromJS(e,t,n),c=o.pk(t,n);if(void 0===c)throw"production"!==process.env.NODE_ENV&&void 0===c?new Error(`Missing usable resource key when normalizing response.\n\n This is likely due to a malformed response.\n Try inspecting the network response or fetch() return value.\n\n Entity: ${this}\n Value: ${e&&JSON.stringify(e,null,2)}\n `):new Error("undefined pk");const a=this.key;return a in s||(s[a]={}),c in s[a]||(s[a][c]=[]),s[a][c].some(t=>t===e)||(s[a][c].push(e),Object.keys(this.schema).forEach(e=>{if(Object.hasOwnProperty.call(o,e)&&"object"==typeof o[e]){const t=this.schema[e];o[e]=r(o[e],o,e,t,i,s)}}),i(this,o,e,t,n)),c}static denormalize(e,r){if(t(e)){const[t,i]=n(this.schema,e,r);return[this.fromJS(t.toObject()),i]}let i=!0;const s=e;return Object.keys(this.schema).forEach(t=>{const n=this.schema[t],[o,c]=r(e[t],n);c||(i=!1),this.hasDefined(e,t)&&s[t]!==o&&(s[t]=o)}),[s,i]}}function d(e){return null!==e&&void 0!==e.pk}f.schema={},"production"!==process.env.NODE_ENV&&(f.fromJS=function(e){if(void 0===this.prototype.pk)throw new Error("cannot construct on abstract types");return m.fromJS.call(this,e)});class y extends f{static denormalize(e,t){return[e,!0]}}const p=e=>{const n={},r=b(e);return[function e(i,s){if(!s)return[i,!0];if("object"==typeof s&&(!s.denormalize||"function"!=typeof s.denormalize)){return(Array.isArray(s)?c:u)(s,i,e)}return null===i?[i,!0]:d(s)?void 0===i?[i,!1]:((e,n,r,i,s)=>{const o=i(e,n);if("object"!=typeof o||null===o)return[o,!1];s[n.key]||(s[n.key]={});let c=!0;if(!s[n.key][e]){const i=t(o)||o instanceof y?o:n.fromJS(o);s[n.key][e]=i,[s[n.key][e],c]=n.denormalize(i,r)}return[s[n.key][e],c]})(i,s,e,r,n):"function"==typeof s.denormalize?s.denormalize(i,e):[i,!0]},n]},b=e=>{const n=t(e);return(t,r)=>{const i=r.key;return"object"==typeof t?t:n?e.getIn([i,t]):e[i]&&e[i][t]}},O=(e,t,n,r,i,s)=>{if("object"!=typeof e||!e||!r)return e;if("object"==typeof r&&(!r.normalize||"function"!=typeof r.normalize)){return(Array.isArray(r)?o:a)(r,e,t,n,O,i,s)}return r.normalize(e,t,n,O,i,s)};var g=Object.freeze({__proto__:null,Union:class extends r{constructor(e,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');super(e,t)}normalize(e,t,n,r,i,s){return this.normalizeValue(e,t,n,r,i,s)}denormalize(e,t){return this.denormalizeValue(e,t)}},Values:class extends r{normalize(e,t,n,r,i,s){return Object.keys(e).reduce((t,n,o)=>{const c=e[n];return null!=c?Object.assign({},t,{[n]:this.normalizeValue(c,e,n,r,i,s)}):t},{})}denormalize(e,t){let n=!0;return[Object.keys(e).reduce((r,i)=>{const s=e[i],[o,c]=this.denormalizeValue(s,t);return c||(n=!1),Object.assign({},r,{[i]:o})},{}),n]}},Array:class extends r{normalize(e,t,n,r,i,o){return s(e).map((e,s)=>this.normalizeValue(e,t,n,r,i,o)).filter(e=>null!=e)}denormalize(e,t){let n=!0;return void 0===e&&this.schema&&([,n]=t(void 0,this.schema)),[e&&e.map?e.map(e=>this.denormalizeValue(e,t)).filter(([,e])=>e).map(([e])=>e):e,n]}},Object:class{constructor(e){this.define(e)}define(e){this.schema=Object.keys(e).reduce((t,n)=>{const r=e[n];return Object.assign({},t,{[n]:r})},this.schema||{})}normalize(...e){return a(this.schema,...e)}denormalize(...e){return u(this.schema,...e)}}});return e.Entity=f,e.FlatEntity=y,e.SimpleRecord=m,e.denormalize=(e,t,n)=>{if("production"!==process.env.NODE_ENV&&void 0===t)throw new Error("schema needed");if(void 0!==e){const[r,i]=p(n);return[...r(e,t),i]}return[void 0,!1,{}]},e.isEntity=d,e.normalize=(e,t)=>{const n=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(t);if(null===e||typeof e!==n)throw new Error(`Unexpected input given to normalize. Expected type to be "${n}", found "${null===e?"null":typeof e}".`);const r={},i={},s=((e,t)=>(n,r,i,s,o)=>{const c=n.key,a=n.pk(r,s,o);c in e||(e[c]={});const u=e[c][a];if(e[c][a]=u?n.merge(u,r):r,Array.isArray(n.indexes)){const r=e[c][a];c in t||(t[c]={});for(const e of n.indexes){e in t[c]||(t[c][e]={});const n=t[c][e];u&&delete n[u[e]],e in r?n[r[e]]=a:"production"!==process.env.NODE_ENV&&console.warn(`Index not found in entity. Indexes must be top-level members of your entity.\nIndex: ${e}\nEntity: ${JSON.stringify(r,void 0,2)}`)}}})(r,i);return{entities:r,indexes:i,result:O(e,e,void 0,t,s,{})}},e.schema=g,e}({});
var rest_hooks_normalizr=function(e){"use strict";function t(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(Object.hasOwnProperty.call(e,"__ownerID")||e._map&&Object.hasOwnProperty.call(e._map,"__ownerID")))}function n(e,t,n){let r=!0;return[Object.keys(e).reduce((t,s)=>{const i=`${s}`,[o,c]=n(t.get(i),e[i]);return c||(r=!1),t.has(i)?t.set(i,o):t},t),r]}class r{constructor(e,t){t&&(this._schemaAttribute="string"==typeof t?e=>e[t]:t),this.define(e)}get isSingleSchema(){return!this._schemaAttribute}define(e){this.schema=e}getSchemaAttribute(e,t,n){return!this.isSingleSchema&&this._schemaAttribute(e,t,n)}inferSchema(e,t,n){if(this.isSingleSchema)return this.schema;const r=this.getSchemaAttribute(e,t,n);return this.schema[r]}normalizeValue(e,t,n,r,s,i){const o=this.inferSchema(e,t,n);if(!o)return e;const c=r(e,t,n,o,s,i);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,n)}}denormalizeValue(e,n){const r=t(e)?e.get("schema"):e.schema;return this.isSingleSchema||r?n((this.isSingleSchema?void 0:t(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[r]):[e,!0]}}const s=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]},i=e=>Array.isArray(e)?e:Object.keys(e).map(t=>e[t]),o=(e,t,n,r,o,c,a)=>(e=s(e),i(t).map((t,s)=>o(t,n,r,e,c,a))),c=(e,t,n)=>{e=s(e);let r=!0;return void 0===t&&e&&([,r]=n(void 0,e)),[t&&t.map?t.map(t=>n(t,e)).filter(([,e])=>e).map(([e])=>e):t,r]};const a=(e,t,n,r,s,i,o)=>{const c=Object.assign({},t);return Object.keys(e).forEach(n=>{const r=e[n],a=s(t[n],t,n,r,i,o);null==a?delete c[n]:c[n]=a}),c},u=(e,r,s)=>{if(t(r))return n(e,r,s);const i=Object.assign({},r);let o=!0;return Object.keys(e).forEach(t=>{const[n,r]=s(i[t],e[t]);void 0!==i[t]&&(i[t]=n),r||(o=!1)}),[i,o]};const l=Symbol("Defined Members"),h=Symbol("unq");class m{toString(){return this[h]}static fromJS(e={},t,n){const r=new this(e);return Object.assign(r,e),Object.defineProperty(r,l,{value:Object.keys(e),writable:!1}),Object.defineProperty(r,h,{value:`${Math.random()}`,writable:!1}),r}static merge(e,t){const n=Object.assign(this.toObjectDefined(e),this.toObjectDefined(t));return this.fromJS(n)}static hasDefined(e,t){return e[l].includes(t)}static toObjectDefined(e){const t={};for(const n of e[l])t[n]=e[n];return t}static keysDefined(e){return e[l]}}class f extends m{static get key(){if("production"!==process.env.NODE_ENV&&""===this.name)throw new Error("Entity classes without a name must define `static get key()`");return this.name}static pk(e,t,n){return this.prototype.pk.call(e,t,n)||n}static asSchema(){return this}static normalize(e,t,n,r,s,i){const o=this.fromJS(e,t,n);if("production"!==process.env.NODE_ENV){const e=new this,t=new Set(Object.keys(e));let[n,r]=[0,0],s=!1;for(const e of f.keysDefined(o))t.has(e)?n++:(r++,s=!0);if(r+=t.size-n,r>n&&t.size&&s){const t=new Error(`Attempted to initialize ${this.name} with substantially different than expected keys\n\n This is likely due to a malformed response.\n Try inspecting the network response or fetch() return value.\n\n Expected keys: ${Object.keys(e)}\n Value: ${JSON.stringify(f.toObjectDefined(o),null,2)}`);throw t.status=400,t}}const c=o.pk(t,n);if(void 0===c||""===c){if("production"!==process.env.NODE_ENV){const t=new Error(`Missing usable resource key when normalizing response.\n\n This is likely due to a malformed response.\n Try inspecting the network response or fetch() return value.\n\n Entity: ${this.name}\n Value: ${e&&JSON.stringify(e,null,2)}\n `);throw t.status=400,t}throw new Error("undefined pk")}const a=this.key;return a in i||(i[a]={}),c in i[a]||(i[a][c]=[]),i[a][c].some(t=>t===e)||(i[a][c].push(e),Object.keys(this.schema).forEach(e=>{if(Object.hasOwnProperty.call(o,e)&&"object"==typeof o[e]){const t=this.schema[e];o[e]=r(o[e],o,e,t,s,i)}}),s(this,o,o,t,n)),c}static denormalize(e,r){if(t(e)){const[t,s]=n(this.schema,e,r);return[this.fromJS(t.toObject()),s]}let s=!0;const i=e;return Object.keys(this.schema).forEach(t=>{const n=this.schema[t],[o,c]=r(e[t],n);c||(s=!1),this.hasDefined(e,t)&&i[t]!==o&&(i[t]=o)}),[i,s]}}function d(e){return null!==e&&void 0!==e.pk}f.schema={},"production"!==process.env.NODE_ENV&&(f.fromJS=function(e){if(void 0===this.prototype.pk)throw new Error("cannot construct on abstract types");return m.fromJS.call(this,e)});class y extends f{static denormalize(e,t){return[e,!0]}}const p=e=>{const n={},r=b(e);return[function e(s,i){if(!i)return[s,!0];if("object"==typeof i&&(!i.denormalize||"function"!=typeof i.denormalize)){return(Array.isArray(i)?c:u)(i,s,e)}return null===s?[s,!0]:d(i)?void 0===s?[s,!1]:((e,n,r,s,i)=>{const o=s(e,n);if("object"!=typeof o||null===o)return[o,!1];i[n.key]||(i[n.key]={});let c=!0;if(!i[n.key][e]){const s=t(o)||o instanceof y?o:n.fromJS(o);i[n.key][e]=s,[i[n.key][e],c]=n.denormalize(s,r)}return[i[n.key][e],c]})(s,i,e,r,n):"function"==typeof i.denormalize?i.denormalize(s,e):[s,!0]},n]},b=e=>{const n=t(e);return(t,r)=>{const s=r.key;return"object"==typeof t?t:n?e.getIn([s,t]):e[s]&&e[s][t]}},O=(e,t,n,r,s,i)=>{if("object"!=typeof e||!e||!r)return e;if("object"==typeof r&&(!r.normalize||"function"!=typeof r.normalize)){return(Array.isArray(r)?o:a)(r,e,t,n,O,s,i)}return r.normalize(e,t,n,O,s,i)};var k=Object.freeze({__proto__:null,Union:class extends r{constructor(e,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');super(e,t)}normalize(e,t,n,r,s,i){return this.normalizeValue(e,t,n,r,s,i)}denormalize(e,t){return this.denormalizeValue(e,t)}},Values:class extends r{normalize(e,t,n,r,s,i){return Object.keys(e).reduce((t,n,o)=>{const c=e[n];return null!=c?Object.assign({},t,{[n]:this.normalizeValue(c,e,n,r,s,i)}):t},{})}denormalize(e,t){let n=!0;return[Object.keys(e).reduce((r,s)=>{const i=e[s],[o,c]=this.denormalizeValue(i,t);return c||(n=!1),Object.assign({},r,{[s]:o})},{}),n]}},Array:class extends r{normalize(e,t,n,r,s,o){return i(e).map((e,i)=>this.normalizeValue(e,t,n,r,s,o)).filter(e=>null!=e)}denormalize(e,t){let n=!0;return void 0===e&&this.schema&&([,n]=t(void 0,this.schema)),[e&&e.map?e.map(e=>this.denormalizeValue(e,t)).filter(([,e])=>e).map(([e])=>e):e,n]}},Object:class{constructor(e){this.define(e)}define(e){this.schema=Object.keys(e).reduce((t,n)=>{const r=e[n];return Object.assign({},t,{[n]:r})},this.schema||{})}normalize(...e){return a(this.schema,...e)}denormalize(...e){return u(this.schema,...e)}}});return e.Entity=f,e.FlatEntity=y,e.SimpleRecord=m,e.denormalize=(e,t,n)=>{if("production"!==process.env.NODE_ENV&&void 0===t)throw new Error("schema needed");if(void 0!==e){const[r,s]=p(n);return[...r(e,t),s]}return[void 0,!1,{}]},e.isEntity=d,e.normalize=(e,t)=>{const n=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(t);if(null===e||typeof e!==n)throw new Error(`Unexpected input given to normalize. Expected type to be "${n}", found "${null===e?"null":typeof e}".`);const r={},s={},i=((e,t)=>(n,r,s,i,o)=>{const c=n.key,a=n.pk(s,i,o);c in e||(e[c]={});const u=e[c][a];if(e[c][a]=u?n.merge(u,r):r,Array.isArray(n.indexes)){const r=e[c][a];c in t||(t[c]={});for(const e of n.indexes){e in t[c]||(t[c][e]={});const n=t[c][e];u&&delete n[u[e]],e in r?n[r[e]]=a:"production"!==process.env.NODE_ENV&&console.warn(`Index not found in entity. Indexes must be top-level members of your entity.\nIndex: ${e}\nEntity: ${JSON.stringify(r,void 0,2)}`)}}})(r,s);return{entities:r,indexes:s,result:O(e,e,void 0,t,i,{})}},e.schema=k,e}({});

@@ -317,8 +317,40 @@ /**

const processedEntity = this.fromJS(input, parent, key);
/* istanbul ignore else */
if (process.env.NODE_ENV !== 'production') {
const instanceSample = new this();
const keysOfRecord = new Set(Object.keys(instanceSample));
let [sameCount, diffCount] = [0, 0];
let extraKey = false;
for (const keyOfProps of Entity.keysDefined(processedEntity)) {
if (keysOfRecord.has(keyOfProps)) {
sameCount++;
} else {
diffCount++;
extraKey = true;
}
}
diffCount += keysOfRecord.size - sameCount;
if (diffCount > sameCount && keysOfRecord.size && extraKey) {
const error = new Error(`Attempted to initialize ${this.name} with substantially different than expected keys
This is likely due to a malformed response.
Try inspecting the network response or fetch() return value.
Expected keys: ${Object.keys(instanceSample)}
Value: ${JSON.stringify(Entity.toObjectDefined(processedEntity), null, 2)}`);
error.status = 400;
throw error;
}
}
const id = processedEntity.pk(parent, key);
/* istanbul ignore next */
if (id === undefined) {
if (process.env.NODE_ENV !== 'production' && id === undefined) {
throw new Error(`Missing usable resource key when normalizing response.
if (id === undefined || id === '') {
/* istanbul ignore else */
if (process.env.NODE_ENV !== 'production') {
const error = new Error(`Missing usable resource key when normalizing response.

@@ -328,5 +360,7 @@ This is likely due to a malformed response.

Entity: ${this}
Entity: ${this.name}
Value: ${input && JSON.stringify(input, null, 2)}
`);
error.status = 400;
throw error;
} else {

@@ -358,3 +392,3 @@ throw new Error('undefined pk');

});
addEntity(this, processedEntity, input, parent, key);
addEntity(this, processedEntity, processedEntity, parent, key);
return id;

@@ -513,3 +547,3 @@ }

const schemaKey = schema.key;
const id = schema.pk(processedEntity, parent, key);
const id = schema.pk(value, parent, key);

@@ -516,0 +550,0 @@ if (!(schemaKey in entities)) {

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

function e(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(Object.hasOwnProperty.call(e,"__ownerID")||e._map&&Object.hasOwnProperty.call(e._map,"__ownerID")))}function t(e,t,n){let r=!0;return[Object.keys(e).reduce((t,s)=>{const i=`${s}`,[o,c]=n(t.get(i),e[i]);return c||(r=!1),t.has(i)?t.set(i,o):t},t),r]}class n{constructor(e,t){t&&(this._schemaAttribute="string"==typeof t?e=>e[t]:t),this.define(e)}get isSingleSchema(){return!this._schemaAttribute}define(e){this.schema=e}getSchemaAttribute(e,t,n){return!this.isSingleSchema&&this._schemaAttribute(e,t,n)}inferSchema(e,t,n){if(this.isSingleSchema)return this.schema;const r=this.getSchemaAttribute(e,t,n);return this.schema[r]}normalizeValue(e,t,n,r,s,i){const o=this.inferSchema(e,t,n);if(!o)return e;const c=r(e,t,n,o,s,i);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,n)}}denormalizeValue(t,n){const r=e(t)?t.get("schema"):t.schema;return this.isSingleSchema||r?n((this.isSingleSchema?void 0:e(t)?t.get("id"):t.id)||t,this.isSingleSchema?this.schema:this.schema[r]):[t,!0]}}const r=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]},s=e=>Array.isArray(e)?e:Object.keys(e).map(t=>e[t]),i=(e,t,n,i,o,c,a)=>(e=r(e),s(t).map((t,r)=>o(t,n,i,e,c,a))),o=(e,t,n)=>{e=r(e);let s=!0;return void 0===t&&e&&([,s]=n(void 0,e)),[t&&t.map?t.map(t=>n(t,e)).filter(([,e])=>e).map(([e])=>e):t,s]};const c=(e,t,n,r,s,i,o)=>{const c=Object.assign({},t);return Object.keys(e).forEach(n=>{const r=e[n],a=s(t[n],t,n,r,i,o);null==a?delete c[n]:c[n]=a}),c},a=(n,r,s)=>{if(e(r))return t(n,r,s);const i=Object.assign({},r);let o=!0;return Object.keys(n).forEach(e=>{const[t,r]=s(i[e],n[e]);void 0!==i[e]&&(i[e]=t),r||(o=!1)}),[i,o]};const u=Symbol("Defined Members"),l=Symbol("unq");class h{toString(){return this[l]}static fromJS(e={},t,n){const r=new this(e);return Object.assign(r,e),Object.defineProperty(r,u,{value:Object.keys(e),writable:!1}),Object.defineProperty(r,l,{value:`${Math.random()}`,writable:!1}),r}static merge(e,t){const n=Object.assign(this.toObjectDefined(e),this.toObjectDefined(t));return this.fromJS(n)}static hasDefined(e,t){return e[u].includes(t)}static toObjectDefined(e){const t={};for(const n of e[u])t[n]=e[n];return t}static keysDefined(e){return e[u]}}class m extends h{static get key(){if("production"!==process.env.NODE_ENV&&""===this.name)throw new Error("Entity classes without a name must define `static get key()`");return this.name}static pk(e,t,n){return this.prototype.pk.call(e,t,n)||n}static asSchema(){return this}static normalize(e,t,n,r,s,i){const o=this.fromJS(e,t,n),c=o.pk(t,n);if(void 0===c)throw"production"!==process.env.NODE_ENV&&void 0===c?new Error(`Missing usable resource key when normalizing response.\n\n This is likely due to a malformed response.\n Try inspecting the network response or fetch() return value.\n\n Entity: ${this}\n Value: ${e&&JSON.stringify(e,null,2)}\n `):new Error("undefined pk");const a=this.key;return a in i||(i[a]={}),c in i[a]||(i[a][c]=[]),i[a][c].some(t=>t===e)||(i[a][c].push(e),Object.keys(this.schema).forEach(e=>{if(Object.hasOwnProperty.call(o,e)&&"object"==typeof o[e]){const t=this.schema[e];o[e]=r(o[e],o,e,t,s,i)}}),s(this,o,e,t,n)),c}static denormalize(n,r){if(e(n)){const[e,s]=t(this.schema,n,r);return[this.fromJS(e.toObject()),s]}let s=!0;const i=n;return Object.keys(this.schema).forEach(e=>{const t=this.schema[e],[o,c]=r(n[e],t);c||(s=!1),this.hasDefined(n,e)&&i[e]!==o&&(i[e]=o)}),[i,s]}}function f(e){return null!==e&&void 0!==e.pk}m.schema={},"production"!==process.env.NODE_ENV&&(m.fromJS=function(e){if(void 0===this.prototype.pk)throw new Error("cannot construct on abstract types");return h.fromJS.call(this,e)});class d extends m{static denormalize(e,t){return[e,!0]}}const y=t=>{const n={},r=p(t);return[function t(s,i){if(!i)return[s,!0];if("object"==typeof i&&(!i.denormalize||"function"!=typeof i.denormalize)){return(Array.isArray(i)?o:a)(i,s,t)}return null===s?[s,!0]:f(i)?void 0===s?[s,!1]:((t,n,r,s,i)=>{const o=s(t,n);if("object"!=typeof o||null===o)return[o,!1];i[n.key]||(i[n.key]={});let c=!0;if(!i[n.key][t]){const s=e(o)||o instanceof d?o:n.fromJS(o);i[n.key][t]=s,[i[n.key][t],c]=n.denormalize(s,r)}return[i[n.key][t],c]})(s,i,t,r,n):"function"==typeof i.denormalize?i.denormalize(s,t):[s,!0]},n]},p=t=>{const n=e(t);return(e,r)=>{const s=r.key;return"object"==typeof e?e:n?t.getIn([s,e]):t[s]&&t[s][e]}},b=(e,t,n)=>{if("production"!==process.env.NODE_ENV&&void 0===t)throw new Error("schema needed");if(void 0!==e){const[r,s]=y(n);return[...r(e,t),s]}return[void 0,!1,{}]},O=(e,t,n,r,s,o)=>{if("object"!=typeof e||!e||!r)return e;if("object"==typeof r&&(!r.normalize||"function"!=typeof r.normalize)){return(Array.isArray(r)?i:c)(r,e,t,n,O,s,o)}return r.normalize(e,t,n,O,s,o)};const g=(e,t)=>{const n=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(t);if(null===e||typeof e!==n)throw new Error(`Unexpected input given to normalize. Expected type to be "${n}", found "${null===e?"null":typeof e}".`);const r={},s={},i=((e,t)=>(n,r,s,i,o)=>{const c=n.key,a=n.pk(r,i,o);c in e||(e[c]={});const u=e[c][a];if(e[c][a]=u?n.merge(u,r):r,Array.isArray(n.indexes)){const r=e[c][a];c in t||(t[c]={});for(const e of n.indexes){e in t[c]||(t[c][e]={});const n=t[c][e];u&&delete n[u[e]],e in r?n[r[e]]=a:"production"!==process.env.NODE_ENV&&console.warn(`Index not found in entity. Indexes must be top-level members of your entity.\nIndex: ${e}\nEntity: ${JSON.stringify(r,void 0,2)}`)}}})(r,s);return{entities:r,indexes:s,result:O(e,e,void 0,t,i,{})}};var j=Object.freeze({__proto__:null,Union:class extends n{constructor(e,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');super(e,t)}normalize(e,t,n,r,s,i){return this.normalizeValue(e,t,n,r,s,i)}denormalize(e,t){return this.denormalizeValue(e,t)}},Values:class extends n{normalize(e,t,n,r,s,i){return Object.keys(e).reduce((t,n,o)=>{const c=e[n];return null!=c?Object.assign({},t,{[n]:this.normalizeValue(c,e,n,r,s,i)}):t},{})}denormalize(e,t){let n=!0;return[Object.keys(e).reduce((r,s)=>{const i=e[s],[o,c]=this.denormalizeValue(i,t);return c||(n=!1),Object.assign({},r,{[s]:o})},{}),n]}},Array:class extends n{normalize(e,t,n,r,i,o){return s(e).map((e,s)=>this.normalizeValue(e,t,n,r,i,o)).filter(e=>null!=e)}denormalize(e,t){let n=!0;return void 0===e&&this.schema&&([,n]=t(void 0,this.schema)),[e&&e.map?e.map(e=>this.denormalizeValue(e,t)).filter(([,e])=>e).map(([e])=>e):e,n]}},Object:class{constructor(e){this.define(e)}define(e){this.schema=Object.keys(e).reduce((t,n)=>{const r=e[n];return Object.assign({},t,{[n]:r})},this.schema||{})}normalize(...e){return c(this.schema,...e)}denormalize(...e){return a(this.schema,...e)}}});export{m as Entity,d as FlatEntity,h as SimpleRecord,b as denormalize,f as isEntity,g as normalize,j as schema};
function e(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(Object.hasOwnProperty.call(e,"__ownerID")||e._map&&Object.hasOwnProperty.call(e._map,"__ownerID")))}function t(e,t,n){let r=!0;return[Object.keys(e).reduce((t,s)=>{const i=`${s}`,[o,c]=n(t.get(i),e[i]);return c||(r=!1),t.has(i)?t.set(i,o):t},t),r]}class n{constructor(e,t){t&&(this._schemaAttribute="string"==typeof t?e=>e[t]:t),this.define(e)}get isSingleSchema(){return!this._schemaAttribute}define(e){this.schema=e}getSchemaAttribute(e,t,n){return!this.isSingleSchema&&this._schemaAttribute(e,t,n)}inferSchema(e,t,n){if(this.isSingleSchema)return this.schema;const r=this.getSchemaAttribute(e,t,n);return this.schema[r]}normalizeValue(e,t,n,r,s,i){const o=this.inferSchema(e,t,n);if(!o)return e;const c=r(e,t,n,o,s,i);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,n)}}denormalizeValue(t,n){const r=e(t)?t.get("schema"):t.schema;return this.isSingleSchema||r?n((this.isSingleSchema?void 0:e(t)?t.get("id"):t.id)||t,this.isSingleSchema?this.schema:this.schema[r]):[t,!0]}}const r=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]},s=e=>Array.isArray(e)?e:Object.keys(e).map(t=>e[t]),i=(e,t,n,i,o,c,a)=>(e=r(e),s(t).map((t,r)=>o(t,n,i,e,c,a))),o=(e,t,n)=>{e=r(e);let s=!0;return void 0===t&&e&&([,s]=n(void 0,e)),[t&&t.map?t.map(t=>n(t,e)).filter(([,e])=>e).map(([e])=>e):t,s]};const c=(e,t,n,r,s,i,o)=>{const c=Object.assign({},t);return Object.keys(e).forEach(n=>{const r=e[n],a=s(t[n],t,n,r,i,o);null==a?delete c[n]:c[n]=a}),c},a=(n,r,s)=>{if(e(r))return t(n,r,s);const i=Object.assign({},r);let o=!0;return Object.keys(n).forEach(e=>{const[t,r]=s(i[e],n[e]);void 0!==i[e]&&(i[e]=t),r||(o=!1)}),[i,o]};const u=Symbol("Defined Members"),l=Symbol("unq");class h{toString(){return this[l]}static fromJS(e={},t,n){const r=new this(e);return Object.assign(r,e),Object.defineProperty(r,u,{value:Object.keys(e),writable:!1}),Object.defineProperty(r,l,{value:`${Math.random()}`,writable:!1}),r}static merge(e,t){const n=Object.assign(this.toObjectDefined(e),this.toObjectDefined(t));return this.fromJS(n)}static hasDefined(e,t){return e[u].includes(t)}static toObjectDefined(e){const t={};for(const n of e[u])t[n]=e[n];return t}static keysDefined(e){return e[u]}}class m extends h{static get key(){if("production"!==process.env.NODE_ENV&&""===this.name)throw new Error("Entity classes without a name must define `static get key()`");return this.name}static pk(e,t,n){return this.prototype.pk.call(e,t,n)||n}static asSchema(){return this}static normalize(e,t,n,r,s,i){const o=this.fromJS(e,t,n);if("production"!==process.env.NODE_ENV){const e=new this,t=new Set(Object.keys(e));let[n,r]=[0,0],s=!1;for(const e of m.keysDefined(o))t.has(e)?n++:(r++,s=!0);if(r+=t.size-n,r>n&&t.size&&s){const t=new Error(`Attempted to initialize ${this.name} with substantially different than expected keys\n\n This is likely due to a malformed response.\n Try inspecting the network response or fetch() return value.\n\n Expected keys: ${Object.keys(e)}\n Value: ${JSON.stringify(m.toObjectDefined(o),null,2)}`);throw t.status=400,t}}const c=o.pk(t,n);if(void 0===c||""===c){if("production"!==process.env.NODE_ENV){const t=new Error(`Missing usable resource key when normalizing response.\n\n This is likely due to a malformed response.\n Try inspecting the network response or fetch() return value.\n\n Entity: ${this.name}\n Value: ${e&&JSON.stringify(e,null,2)}\n `);throw t.status=400,t}throw new Error("undefined pk")}const a=this.key;return a in i||(i[a]={}),c in i[a]||(i[a][c]=[]),i[a][c].some(t=>t===e)||(i[a][c].push(e),Object.keys(this.schema).forEach(e=>{if(Object.hasOwnProperty.call(o,e)&&"object"==typeof o[e]){const t=this.schema[e];o[e]=r(o[e],o,e,t,s,i)}}),s(this,o,o,t,n)),c}static denormalize(n,r){if(e(n)){const[e,s]=t(this.schema,n,r);return[this.fromJS(e.toObject()),s]}let s=!0;const i=n;return Object.keys(this.schema).forEach(e=>{const t=this.schema[e],[o,c]=r(n[e],t);c||(s=!1),this.hasDefined(n,e)&&i[e]!==o&&(i[e]=o)}),[i,s]}}function f(e){return null!==e&&void 0!==e.pk}m.schema={},"production"!==process.env.NODE_ENV&&(m.fromJS=function(e){if(void 0===this.prototype.pk)throw new Error("cannot construct on abstract types");return h.fromJS.call(this,e)});class d extends m{static denormalize(e,t){return[e,!0]}}const y=t=>{const n={},r=p(t);return[function t(s,i){if(!i)return[s,!0];if("object"==typeof i&&(!i.denormalize||"function"!=typeof i.denormalize)){return(Array.isArray(i)?o:a)(i,s,t)}return null===s?[s,!0]:f(i)?void 0===s?[s,!1]:((t,n,r,s,i)=>{const o=s(t,n);if("object"!=typeof o||null===o)return[o,!1];i[n.key]||(i[n.key]={});let c=!0;if(!i[n.key][t]){const s=e(o)||o instanceof d?o:n.fromJS(o);i[n.key][t]=s,[i[n.key][t],c]=n.denormalize(s,r)}return[i[n.key][t],c]})(s,i,t,r,n):"function"==typeof i.denormalize?i.denormalize(s,t):[s,!0]},n]},p=t=>{const n=e(t);return(e,r)=>{const s=r.key;return"object"==typeof e?e:n?t.getIn([s,e]):t[s]&&t[s][e]}},b=(e,t,n)=>{if("production"!==process.env.NODE_ENV&&void 0===t)throw new Error("schema needed");if(void 0!==e){const[r,s]=y(n);return[...r(e,t),s]}return[void 0,!1,{}]},O=(e,t,n,r,s,o)=>{if("object"!=typeof e||!e||!r)return e;if("object"==typeof r&&(!r.normalize||"function"!=typeof r.normalize)){return(Array.isArray(r)?i:c)(r,e,t,n,O,s,o)}return r.normalize(e,t,n,O,s,o)};const g=(e,t)=>{const n=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(t);if(null===e||typeof e!==n)throw new Error(`Unexpected input given to normalize. Expected type to be "${n}", found "${null===e?"null":typeof e}".`);const r={},s={},i=((e,t)=>(n,r,s,i,o)=>{const c=n.key,a=n.pk(s,i,o);c in e||(e[c]={});const u=e[c][a];if(e[c][a]=u?n.merge(u,r):r,Array.isArray(n.indexes)){const r=e[c][a];c in t||(t[c]={});for(const e of n.indexes){e in t[c]||(t[c][e]={});const n=t[c][e];u&&delete n[u[e]],e in r?n[r[e]]=a:"production"!==process.env.NODE_ENV&&console.warn(`Index not found in entity. Indexes must be top-level members of your entity.\nIndex: ${e}\nEntity: ${JSON.stringify(r,void 0,2)}`)}}})(r,s);return{entities:r,indexes:s,result:O(e,e,void 0,t,i,{})}};var j=Object.freeze({__proto__:null,Union:class extends n{constructor(e,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');super(e,t)}normalize(e,t,n,r,s,i){return this.normalizeValue(e,t,n,r,s,i)}denormalize(e,t){return this.denormalizeValue(e,t)}},Values:class extends n{normalize(e,t,n,r,s,i){return Object.keys(e).reduce((t,n,o)=>{const c=e[n];return null!=c?Object.assign({},t,{[n]:this.normalizeValue(c,e,n,r,s,i)}):t},{})}denormalize(e,t){let n=!0;return[Object.keys(e).reduce((r,s)=>{const i=e[s],[o,c]=this.denormalizeValue(i,t);return c||(n=!1),Object.assign({},r,{[s]:o})},{}),n]}},Array:class extends n{normalize(e,t,n,r,i,o){return s(e).map((e,s)=>this.normalizeValue(e,t,n,r,i,o)).filter(e=>null!=e)}denormalize(e,t){let n=!0;return void 0===e&&this.schema&&([,n]=t(void 0,this.schema)),[e&&e.map?e.map(e=>this.denormalizeValue(e,t)).filter(([,e])=>e).map(([e])=>e):e,n]}},Object:class{constructor(e){this.define(e)}define(e){this.schema=Object.keys(e).reduce((t,n)=>{const r=e[n];return Object.assign({},t,{[n]:r})},this.schema||{})}normalize(...e){return c(this.schema,...e)}denormalize(...e){return a(this.schema,...e)}}});export{m as Entity,d as FlatEntity,h as SimpleRecord,b as denormalize,f as isEntity,g as normalize,j as schema};

@@ -323,8 +323,40 @@ 'use strict';

const processedEntity = this.fromJS(input, parent, key);
/* istanbul ignore else */
if (process.env.NODE_ENV !== 'production') {
const instanceSample = new this();
const keysOfRecord = new Set(Object.keys(instanceSample));
let [sameCount, diffCount] = [0, 0];
let extraKey = false;
for (const keyOfProps of Entity.keysDefined(processedEntity)) {
if (keysOfRecord.has(keyOfProps)) {
sameCount++;
} else {
diffCount++;
extraKey = true;
}
}
diffCount += keysOfRecord.size - sameCount;
if (diffCount > sameCount && keysOfRecord.size && extraKey) {
const error = new Error(`Attempted to initialize ${this.name} with substantially different than expected keys
This is likely due to a malformed response.
Try inspecting the network response or fetch() return value.
Expected keys: ${Object.keys(instanceSample)}
Value: ${JSON.stringify(Entity.toObjectDefined(processedEntity), null, 2)}`);
error.status = 400;
throw error;
}
}
const id = processedEntity.pk(parent, key);
/* istanbul ignore next */
if (id === undefined) {
if (process.env.NODE_ENV !== 'production' && id === undefined) {
throw new Error(`Missing usable resource key when normalizing response.
if (id === undefined || id === '') {
/* istanbul ignore else */
if (process.env.NODE_ENV !== 'production') {
const error = new Error(`Missing usable resource key when normalizing response.

@@ -334,5 +366,7 @@ This is likely due to a malformed response.

Entity: ${this}
Entity: ${this.name}
Value: ${input && JSON.stringify(input, null, 2)}
`);
error.status = 400;
throw error;
} else {

@@ -364,3 +398,3 @@ throw new Error('undefined pk');

});
addEntity(this, processedEntity, input, parent, key);
addEntity(this, processedEntity, processedEntity, parent, key);
return id;

@@ -519,3 +553,3 @@ }

const schemaKey = schema.key;
const id = schema.pk(processedEntity, parent, key);
const id = schema.pk(value, parent, key);

@@ -522,0 +556,0 @@ if (!(schemaKey in entities)) {

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

"use strict";function e(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(Object.hasOwnProperty.call(e,"__ownerID")||e._map&&Object.hasOwnProperty.call(e._map,"__ownerID")))}function t(e,t,n){let r=!0;return[Object.keys(e).reduce((t,s)=>{const i=`${s}`,[o,c]=n(t.get(i),e[i]);return c||(r=!1),t.has(i)?t.set(i,o):t},t),r]}Object.defineProperty(exports,"__esModule",{value:!0});class n{constructor(e,t){t&&(this._schemaAttribute="string"==typeof t?e=>e[t]:t),this.define(e)}get isSingleSchema(){return!this._schemaAttribute}define(e){this.schema=e}getSchemaAttribute(e,t,n){return!this.isSingleSchema&&this._schemaAttribute(e,t,n)}inferSchema(e,t,n){if(this.isSingleSchema)return this.schema;const r=this.getSchemaAttribute(e,t,n);return this.schema[r]}normalizeValue(e,t,n,r,s,i){const o=this.inferSchema(e,t,n);if(!o)return e;const c=r(e,t,n,o,s,i);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,n)}}denormalizeValue(t,n){const r=e(t)?t.get("schema"):t.schema;return this.isSingleSchema||r?n((this.isSingleSchema?void 0:e(t)?t.get("id"):t.id)||t,this.isSingleSchema?this.schema:this.schema[r]):[t,!0]}}const r=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]},s=e=>Array.isArray(e)?e:Object.keys(e).map(t=>e[t]),i=(e,t,n,i,o,c,a)=>(e=r(e),s(t).map((t,r)=>o(t,n,i,e,c,a))),o=(e,t,n)=>{e=r(e);let s=!0;return void 0===t&&e&&([,s]=n(void 0,e)),[t&&t.map?t.map(t=>n(t,e)).filter(([,e])=>e).map(([e])=>e):t,s]};const c=(e,t,n,r,s,i,o)=>{const c=Object.assign({},t);return Object.keys(e).forEach(n=>{const r=e[n],a=s(t[n],t,n,r,i,o);null==a?delete c[n]:c[n]=a}),c},a=(n,r,s)=>{if(e(r))return t(n,r,s);const i=Object.assign({},r);let o=!0;return Object.keys(n).forEach(e=>{const[t,r]=s(i[e],n[e]);void 0!==i[e]&&(i[e]=t),r||(o=!1)}),[i,o]};const u=Symbol("Defined Members"),l=Symbol("unq");class h{toString(){return this[l]}static fromJS(e={},t,n){const r=new this(e);return Object.assign(r,e),Object.defineProperty(r,u,{value:Object.keys(e),writable:!1}),Object.defineProperty(r,l,{value:`${Math.random()}`,writable:!1}),r}static merge(e,t){const n=Object.assign(this.toObjectDefined(e),this.toObjectDefined(t));return this.fromJS(n)}static hasDefined(e,t){return e[u].includes(t)}static toObjectDefined(e){const t={};for(const n of e[u])t[n]=e[n];return t}static keysDefined(e){return e[u]}}class m extends h{static get key(){if("production"!==process.env.NODE_ENV&&""===this.name)throw new Error("Entity classes without a name must define `static get key()`");return this.name}static pk(e,t,n){return this.prototype.pk.call(e,t,n)||n}static asSchema(){return this}static normalize(e,t,n,r,s,i){const o=this.fromJS(e,t,n),c=o.pk(t,n);if(void 0===c)throw"production"!==process.env.NODE_ENV&&void 0===c?new Error(`Missing usable resource key when normalizing response.\n\n This is likely due to a malformed response.\n Try inspecting the network response or fetch() return value.\n\n Entity: ${this}\n Value: ${e&&JSON.stringify(e,null,2)}\n `):new Error("undefined pk");const a=this.key;return a in i||(i[a]={}),c in i[a]||(i[a][c]=[]),i[a][c].some(t=>t===e)||(i[a][c].push(e),Object.keys(this.schema).forEach(e=>{if(Object.hasOwnProperty.call(o,e)&&"object"==typeof o[e]){const t=this.schema[e];o[e]=r(o[e],o,e,t,s,i)}}),s(this,o,e,t,n)),c}static denormalize(n,r){if(e(n)){const[e,s]=t(this.schema,n,r);return[this.fromJS(e.toObject()),s]}let s=!0;const i=n;return Object.keys(this.schema).forEach(e=>{const t=this.schema[e],[o,c]=r(n[e],t);c||(s=!1),this.hasDefined(n,e)&&i[e]!==o&&(i[e]=o)}),[i,s]}}function f(e){return null!==e&&void 0!==e.pk}m.schema={},"production"!==process.env.NODE_ENV&&(m.fromJS=function(e){if(void 0===this.prototype.pk)throw new Error("cannot construct on abstract types");return h.fromJS.call(this,e)});class d extends m{static denormalize(e,t){return[e,!0]}}const p=t=>{const n={},r=y(t);return[function t(s,i){if(!i)return[s,!0];if("object"==typeof i&&(!i.denormalize||"function"!=typeof i.denormalize)){return(Array.isArray(i)?o:a)(i,s,t)}return null===s?[s,!0]:f(i)?void 0===s?[s,!1]:((t,n,r,s,i)=>{const o=s(t,n);if("object"!=typeof o||null===o)return[o,!1];i[n.key]||(i[n.key]={});let c=!0;if(!i[n.key][t]){const s=e(o)||o instanceof d?o:n.fromJS(o);i[n.key][t]=s,[i[n.key][t],c]=n.denormalize(s,r)}return[i[n.key][t],c]})(s,i,t,r,n):"function"==typeof i.denormalize?i.denormalize(s,t):[s,!0]},n]},y=t=>{const n=e(t);return(e,r)=>{const s=r.key;return"object"==typeof e?e:n?t.getIn([s,e]):t[s]&&t[s][e]}},b=(e,t,n,r,s,o)=>{if("object"!=typeof e||!e||!r)return e;if("object"==typeof r&&(!r.normalize||"function"!=typeof r.normalize)){return(Array.isArray(r)?i:c)(r,e,t,n,b,s,o)}return r.normalize(e,t,n,b,s,o)};var O=Object.freeze({__proto__:null,Union:class extends n{constructor(e,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');super(e,t)}normalize(e,t,n,r,s,i){return this.normalizeValue(e,t,n,r,s,i)}denormalize(e,t){return this.denormalizeValue(e,t)}},Values:class extends n{normalize(e,t,n,r,s,i){return Object.keys(e).reduce((t,n,o)=>{const c=e[n];return null!=c?Object.assign({},t,{[n]:this.normalizeValue(c,e,n,r,s,i)}):t},{})}denormalize(e,t){let n=!0;return[Object.keys(e).reduce((r,s)=>{const i=e[s],[o,c]=this.denormalizeValue(i,t);return c||(n=!1),Object.assign({},r,{[s]:o})},{}),n]}},Array:class extends n{normalize(e,t,n,r,i,o){return s(e).map((e,s)=>this.normalizeValue(e,t,n,r,i,o)).filter(e=>null!=e)}denormalize(e,t){let n=!0;return void 0===e&&this.schema&&([,n]=t(void 0,this.schema)),[e&&e.map?e.map(e=>this.denormalizeValue(e,t)).filter(([,e])=>e).map(([e])=>e):e,n]}},Object:class{constructor(e){this.define(e)}define(e){this.schema=Object.keys(e).reduce((t,n)=>{const r=e[n];return Object.assign({},t,{[n]:r})},this.schema||{})}normalize(...e){return c(this.schema,...e)}denormalize(...e){return a(this.schema,...e)}}});exports.Entity=m,exports.FlatEntity=d,exports.SimpleRecord=h,exports.denormalize=(e,t,n)=>{if("production"!==process.env.NODE_ENV&&void 0===t)throw new Error("schema needed");if(void 0!==e){const[r,s]=p(n);return[...r(e,t),s]}return[void 0,!1,{}]},exports.isEntity=f,exports.normalize=(e,t)=>{const n=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(t);if(null===e||typeof e!==n)throw new Error(`Unexpected input given to normalize. Expected type to be "${n}", found "${null===e?"null":typeof e}".`);const r={},s={},i=((e,t)=>(n,r,s,i,o)=>{const c=n.key,a=n.pk(r,i,o);c in e||(e[c]={});const u=e[c][a];if(e[c][a]=u?n.merge(u,r):r,Array.isArray(n.indexes)){const r=e[c][a];c in t||(t[c]={});for(const e of n.indexes){e in t[c]||(t[c][e]={});const n=t[c][e];u&&delete n[u[e]],e in r?n[r[e]]=a:"production"!==process.env.NODE_ENV&&console.warn(`Index not found in entity. Indexes must be top-level members of your entity.\nIndex: ${e}\nEntity: ${JSON.stringify(r,void 0,2)}`)}}})(r,s);return{entities:r,indexes:s,result:b(e,e,void 0,t,i,{})}},exports.schema=O;
"use strict";function e(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(Object.hasOwnProperty.call(e,"__ownerID")||e._map&&Object.hasOwnProperty.call(e._map,"__ownerID")))}function t(e,t,n){let r=!0;return[Object.keys(e).reduce((t,s)=>{const i=`${s}`,[o,c]=n(t.get(i),e[i]);return c||(r=!1),t.has(i)?t.set(i,o):t},t),r]}Object.defineProperty(exports,"__esModule",{value:!0});class n{constructor(e,t){t&&(this._schemaAttribute="string"==typeof t?e=>e[t]:t),this.define(e)}get isSingleSchema(){return!this._schemaAttribute}define(e){this.schema=e}getSchemaAttribute(e,t,n){return!this.isSingleSchema&&this._schemaAttribute(e,t,n)}inferSchema(e,t,n){if(this.isSingleSchema)return this.schema;const r=this.getSchemaAttribute(e,t,n);return this.schema[r]}normalizeValue(e,t,n,r,s,i){const o=this.inferSchema(e,t,n);if(!o)return e;const c=r(e,t,n,o,s,i);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,n)}}denormalizeValue(t,n){const r=e(t)?t.get("schema"):t.schema;return this.isSingleSchema||r?n((this.isSingleSchema?void 0:e(t)?t.get("id"):t.id)||t,this.isSingleSchema?this.schema:this.schema[r]):[t,!0]}}const r=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]},s=e=>Array.isArray(e)?e:Object.keys(e).map(t=>e[t]),i=(e,t,n,i,o,c,a)=>(e=r(e),s(t).map((t,r)=>o(t,n,i,e,c,a))),o=(e,t,n)=>{e=r(e);let s=!0;return void 0===t&&e&&([,s]=n(void 0,e)),[t&&t.map?t.map(t=>n(t,e)).filter(([,e])=>e).map(([e])=>e):t,s]};const c=(e,t,n,r,s,i,o)=>{const c=Object.assign({},t);return Object.keys(e).forEach(n=>{const r=e[n],a=s(t[n],t,n,r,i,o);null==a?delete c[n]:c[n]=a}),c},a=(n,r,s)=>{if(e(r))return t(n,r,s);const i=Object.assign({},r);let o=!0;return Object.keys(n).forEach(e=>{const[t,r]=s(i[e],n[e]);void 0!==i[e]&&(i[e]=t),r||(o=!1)}),[i,o]};const u=Symbol("Defined Members"),l=Symbol("unq");class h{toString(){return this[l]}static fromJS(e={},t,n){const r=new this(e);return Object.assign(r,e),Object.defineProperty(r,u,{value:Object.keys(e),writable:!1}),Object.defineProperty(r,l,{value:`${Math.random()}`,writable:!1}),r}static merge(e,t){const n=Object.assign(this.toObjectDefined(e),this.toObjectDefined(t));return this.fromJS(n)}static hasDefined(e,t){return e[u].includes(t)}static toObjectDefined(e){const t={};for(const n of e[u])t[n]=e[n];return t}static keysDefined(e){return e[u]}}class m extends h{static get key(){if("production"!==process.env.NODE_ENV&&""===this.name)throw new Error("Entity classes without a name must define `static get key()`");return this.name}static pk(e,t,n){return this.prototype.pk.call(e,t,n)||n}static asSchema(){return this}static normalize(e,t,n,r,s,i){const o=this.fromJS(e,t,n);if("production"!==process.env.NODE_ENV){const e=new this,t=new Set(Object.keys(e));let[n,r]=[0,0],s=!1;for(const e of m.keysDefined(o))t.has(e)?n++:(r++,s=!0);if(r+=t.size-n,r>n&&t.size&&s){const t=new Error(`Attempted to initialize ${this.name} with substantially different than expected keys\n\n This is likely due to a malformed response.\n Try inspecting the network response or fetch() return value.\n\n Expected keys: ${Object.keys(e)}\n Value: ${JSON.stringify(m.toObjectDefined(o),null,2)}`);throw t.status=400,t}}const c=o.pk(t,n);if(void 0===c||""===c){if("production"!==process.env.NODE_ENV){const t=new Error(`Missing usable resource key when normalizing response.\n\n This is likely due to a malformed response.\n Try inspecting the network response or fetch() return value.\n\n Entity: ${this.name}\n Value: ${e&&JSON.stringify(e,null,2)}\n `);throw t.status=400,t}throw new Error("undefined pk")}const a=this.key;return a in i||(i[a]={}),c in i[a]||(i[a][c]=[]),i[a][c].some(t=>t===e)||(i[a][c].push(e),Object.keys(this.schema).forEach(e=>{if(Object.hasOwnProperty.call(o,e)&&"object"==typeof o[e]){const t=this.schema[e];o[e]=r(o[e],o,e,t,s,i)}}),s(this,o,o,t,n)),c}static denormalize(n,r){if(e(n)){const[e,s]=t(this.schema,n,r);return[this.fromJS(e.toObject()),s]}let s=!0;const i=n;return Object.keys(this.schema).forEach(e=>{const t=this.schema[e],[o,c]=r(n[e],t);c||(s=!1),this.hasDefined(n,e)&&i[e]!==o&&(i[e]=o)}),[i,s]}}function f(e){return null!==e&&void 0!==e.pk}m.schema={},"production"!==process.env.NODE_ENV&&(m.fromJS=function(e){if(void 0===this.prototype.pk)throw new Error("cannot construct on abstract types");return h.fromJS.call(this,e)});class d extends m{static denormalize(e,t){return[e,!0]}}const p=t=>{const n={},r=y(t);return[function t(s,i){if(!i)return[s,!0];if("object"==typeof i&&(!i.denormalize||"function"!=typeof i.denormalize)){return(Array.isArray(i)?o:a)(i,s,t)}return null===s?[s,!0]:f(i)?void 0===s?[s,!1]:((t,n,r,s,i)=>{const o=s(t,n);if("object"!=typeof o||null===o)return[o,!1];i[n.key]||(i[n.key]={});let c=!0;if(!i[n.key][t]){const s=e(o)||o instanceof d?o:n.fromJS(o);i[n.key][t]=s,[i[n.key][t],c]=n.denormalize(s,r)}return[i[n.key][t],c]})(s,i,t,r,n):"function"==typeof i.denormalize?i.denormalize(s,t):[s,!0]},n]},y=t=>{const n=e(t);return(e,r)=>{const s=r.key;return"object"==typeof e?e:n?t.getIn([s,e]):t[s]&&t[s][e]}},b=(e,t,n,r,s,o)=>{if("object"!=typeof e||!e||!r)return e;if("object"==typeof r&&(!r.normalize||"function"!=typeof r.normalize)){return(Array.isArray(r)?i:c)(r,e,t,n,b,s,o)}return r.normalize(e,t,n,b,s,o)};var O=Object.freeze({__proto__:null,Union:class extends n{constructor(e,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');super(e,t)}normalize(e,t,n,r,s,i){return this.normalizeValue(e,t,n,r,s,i)}denormalize(e,t){return this.denormalizeValue(e,t)}},Values:class extends n{normalize(e,t,n,r,s,i){return Object.keys(e).reduce((t,n,o)=>{const c=e[n];return null!=c?Object.assign({},t,{[n]:this.normalizeValue(c,e,n,r,s,i)}):t},{})}denormalize(e,t){let n=!0;return[Object.keys(e).reduce((r,s)=>{const i=e[s],[o,c]=this.denormalizeValue(i,t);return c||(n=!1),Object.assign({},r,{[s]:o})},{}),n]}},Array:class extends n{normalize(e,t,n,r,i,o){return s(e).map((e,s)=>this.normalizeValue(e,t,n,r,i,o)).filter(e=>null!=e)}denormalize(e,t){let n=!0;return void 0===e&&this.schema&&([,n]=t(void 0,this.schema)),[e&&e.map?e.map(e=>this.denormalizeValue(e,t)).filter(([,e])=>e).map(([e])=>e):e,n]}},Object:class{constructor(e){this.define(e)}define(e){this.schema=Object.keys(e).reduce((t,n)=>{const r=e[n];return Object.assign({},t,{[n]:r})},this.schema||{})}normalize(...e){return c(this.schema,...e)}denormalize(...e){return a(this.schema,...e)}}});exports.Entity=m,exports.FlatEntity=d,exports.SimpleRecord=h,exports.denormalize=(e,t,n)=>{if("production"!==process.env.NODE_ENV&&void 0===t)throw new Error("schema needed");if(void 0!==e){const[r,s]=p(n);return[...r(e,t),s]}return[void 0,!1,{}]},exports.isEntity=f,exports.normalize=(e,t)=>{const n=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(t);if(null===e||typeof e!==n)throw new Error(`Unexpected input given to normalize. Expected type to be "${n}", found "${null===e?"null":typeof e}".`);const r={},s={},i=((e,t)=>(n,r,s,i,o)=>{const c=n.key,a=n.pk(s,i,o);c in e||(e[c]={});const u=e[c][a];if(e[c][a]=u?n.merge(u,r):r,Array.isArray(n.indexes)){const r=e[c][a];c in t||(t[c]={});for(const e of n.indexes){e in t[c]||(t[c][e]={});const n=t[c][e];u&&delete n[u[e]],e in r?n[r[e]]=a:"production"!==process.env.NODE_ENV&&console.warn(`Index not found in entity. Indexes must be top-level members of your entity.\nIndex: ${e}\nEntity: ${JSON.stringify(r,void 0,2)}`)}}})(r,s);return{entities:r,indexes:s,result:b(e,e,void 0,t,i,{})}},exports.schema=O;

@@ -325,8 +325,40 @@ (function (global, factory) {

const processedEntity = this.fromJS(input, parent, key);
/* istanbul ignore else */
if (process.env.NODE_ENV !== 'production') {
const instanceSample = new this();
const keysOfRecord = new Set(Object.keys(instanceSample));
let [sameCount, diffCount] = [0, 0];
let extraKey = false;
for (const keyOfProps of Entity.keysDefined(processedEntity)) {
if (keysOfRecord.has(keyOfProps)) {
sameCount++;
} else {
diffCount++;
extraKey = true;
}
}
diffCount += keysOfRecord.size - sameCount;
if (diffCount > sameCount && keysOfRecord.size && extraKey) {
const error = new Error(`Attempted to initialize ${this.name} with substantially different than expected keys
This is likely due to a malformed response.
Try inspecting the network response or fetch() return value.
Expected keys: ${Object.keys(instanceSample)}
Value: ${JSON.stringify(Entity.toObjectDefined(processedEntity), null, 2)}`);
error.status = 400;
throw error;
}
}
const id = processedEntity.pk(parent, key);
/* istanbul ignore next */
if (id === undefined) {
if (process.env.NODE_ENV !== 'production' && id === undefined) {
throw new Error(`Missing usable resource key when normalizing response.
if (id === undefined || id === '') {
/* istanbul ignore else */
if (process.env.NODE_ENV !== 'production') {
const error = new Error(`Missing usable resource key when normalizing response.

@@ -336,5 +368,7 @@ This is likely due to a malformed response.

Entity: ${this}
Entity: ${this.name}
Value: ${input && JSON.stringify(input, null, 2)}
`);
error.status = 400;
throw error;
} else {

@@ -366,3 +400,3 @@ throw new Error('undefined pk');

});
addEntity(this, processedEntity, input, parent, key);
addEntity(this, processedEntity, processedEntity, parent, key);
return id;

@@ -521,3 +555,3 @@ }

const schemaKey = schema.key;
const id = schema.pk(processedEntity, parent, key);
const id = schema.pk(value, parent, key);

@@ -524,0 +558,0 @@ if (!(schemaKey in entities)) {

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).rest_hooks_normalizr={})}(this,(function(e){"use strict";function t(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(Object.hasOwnProperty.call(e,"__ownerID")||e._map&&Object.hasOwnProperty.call(e._map,"__ownerID")))}function n(e,t,n){let r=!0;return[Object.keys(e).reduce((t,i)=>{const s=`${i}`,[o,c]=n(t.get(s),e[s]);return c||(r=!1),t.has(s)?t.set(s,o):t},t),r]}class r{constructor(e,t){t&&(this._schemaAttribute="string"==typeof t?e=>e[t]:t),this.define(e)}get isSingleSchema(){return!this._schemaAttribute}define(e){this.schema=e}getSchemaAttribute(e,t,n){return!this.isSingleSchema&&this._schemaAttribute(e,t,n)}inferSchema(e,t,n){if(this.isSingleSchema)return this.schema;const r=this.getSchemaAttribute(e,t,n);return this.schema[r]}normalizeValue(e,t,n,r,i,s){const o=this.inferSchema(e,t,n);if(!o)return e;const c=r(e,t,n,o,i,s);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,n)}}denormalizeValue(e,n){const r=t(e)?e.get("schema"):e.schema;return this.isSingleSchema||r?n((this.isSingleSchema?void 0:t(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[r]):[e,!0]}}const i=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]},s=e=>Array.isArray(e)?e:Object.keys(e).map(t=>e[t]),o=(e,t,n,r,o,c,a)=>(e=i(e),s(t).map((t,i)=>o(t,n,r,e,c,a))),c=(e,t,n)=>{e=i(e);let r=!0;return void 0===t&&e&&([,r]=n(void 0,e)),[t&&t.map?t.map(t=>n(t,e)).filter(([,e])=>e).map(([e])=>e):t,r]};const a=(e,t,n,r,i,s,o)=>{const c=Object.assign({},t);return Object.keys(e).forEach(n=>{const r=e[n],a=i(t[n],t,n,r,s,o);null==a?delete c[n]:c[n]=a}),c},u=(e,r,i)=>{if(t(r))return n(e,r,i);const s=Object.assign({},r);let o=!0;return Object.keys(e).forEach(t=>{const[n,r]=i(s[t],e[t]);void 0!==s[t]&&(s[t]=n),r||(o=!1)}),[s,o]};const l=Symbol("Defined Members"),h=Symbol("unq");class m{toString(){return this[h]}static fromJS(e={},t,n){const r=new this(e);return Object.assign(r,e),Object.defineProperty(r,l,{value:Object.keys(e),writable:!1}),Object.defineProperty(r,h,{value:`${Math.random()}`,writable:!1}),r}static merge(e,t){const n=Object.assign(this.toObjectDefined(e),this.toObjectDefined(t));return this.fromJS(n)}static hasDefined(e,t){return e[l].includes(t)}static toObjectDefined(e){const t={};for(const n of e[l])t[n]=e[n];return t}static keysDefined(e){return e[l]}}class f extends m{static get key(){if("production"!==process.env.NODE_ENV&&""===this.name)throw new Error("Entity classes without a name must define `static get key()`");return this.name}static pk(e,t,n){return this.prototype.pk.call(e,t,n)||n}static asSchema(){return this}static normalize(e,t,n,r,i,s){const o=this.fromJS(e,t,n),c=o.pk(t,n);if(void 0===c)throw"production"!==process.env.NODE_ENV&&void 0===c?new Error(`Missing usable resource key when normalizing response.\n\n This is likely due to a malformed response.\n Try inspecting the network response or fetch() return value.\n\n Entity: ${this}\n Value: ${e&&JSON.stringify(e,null,2)}\n `):new Error("undefined pk");const a=this.key;return a in s||(s[a]={}),c in s[a]||(s[a][c]=[]),s[a][c].some(t=>t===e)||(s[a][c].push(e),Object.keys(this.schema).forEach(e=>{if(Object.hasOwnProperty.call(o,e)&&"object"==typeof o[e]){const t=this.schema[e];o[e]=r(o[e],o,e,t,i,s)}}),i(this,o,e,t,n)),c}static denormalize(e,r){if(t(e)){const[t,i]=n(this.schema,e,r);return[this.fromJS(t.toObject()),i]}let i=!0;const s=e;return Object.keys(this.schema).forEach(t=>{const n=this.schema[t],[o,c]=r(e[t],n);c||(i=!1),this.hasDefined(e,t)&&s[t]!==o&&(s[t]=o)}),[s,i]}}function d(e){return null!==e&&void 0!==e.pk}f.schema={},"production"!==process.env.NODE_ENV&&(f.fromJS=function(e){if(void 0===this.prototype.pk)throw new Error("cannot construct on abstract types");return m.fromJS.call(this,e)});class y extends f{static denormalize(e,t){return[e,!0]}}const p=e=>{const n={},r=b(e);return[function e(i,s){if(!s)return[i,!0];if("object"==typeof s&&(!s.denormalize||"function"!=typeof s.denormalize)){return(Array.isArray(s)?c:u)(s,i,e)}return null===i?[i,!0]:d(s)?void 0===i?[i,!1]:((e,n,r,i,s)=>{const o=i(e,n);if("object"!=typeof o||null===o)return[o,!1];s[n.key]||(s[n.key]={});let c=!0;if(!s[n.key][e]){const i=t(o)||o instanceof y?o:n.fromJS(o);s[n.key][e]=i,[s[n.key][e],c]=n.denormalize(i,r)}return[s[n.key][e],c]})(i,s,e,r,n):"function"==typeof s.denormalize?s.denormalize(i,e):[i,!0]},n]},b=e=>{const n=t(e);return(t,r)=>{const i=r.key;return"object"==typeof t?t:n?e.getIn([i,t]):e[i]&&e[i][t]}},O=(e,t,n,r,i,s)=>{if("object"!=typeof e||!e||!r)return e;if("object"==typeof r&&(!r.normalize||"function"!=typeof r.normalize)){return(Array.isArray(r)?o:a)(r,e,t,n,O,i,s)}return r.normalize(e,t,n,O,i,s)};var j=Object.freeze({__proto__:null,Union:class extends r{constructor(e,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');super(e,t)}normalize(e,t,n,r,i,s){return this.normalizeValue(e,t,n,r,i,s)}denormalize(e,t){return this.denormalizeValue(e,t)}},Values:class extends r{normalize(e,t,n,r,i,s){return Object.keys(e).reduce((t,n,o)=>{const c=e[n];return null!=c?Object.assign({},t,{[n]:this.normalizeValue(c,e,n,r,i,s)}):t},{})}denormalize(e,t){let n=!0;return[Object.keys(e).reduce((r,i)=>{const s=e[i],[o,c]=this.denormalizeValue(s,t);return c||(n=!1),Object.assign({},r,{[i]:o})},{}),n]}},Array:class extends r{normalize(e,t,n,r,i,o){return s(e).map((e,s)=>this.normalizeValue(e,t,n,r,i,o)).filter(e=>null!=e)}denormalize(e,t){let n=!0;return void 0===e&&this.schema&&([,n]=t(void 0,this.schema)),[e&&e.map?e.map(e=>this.denormalizeValue(e,t)).filter(([,e])=>e).map(([e])=>e):e,n]}},Object:class{constructor(e){this.define(e)}define(e){this.schema=Object.keys(e).reduce((t,n)=>{const r=e[n];return Object.assign({},t,{[n]:r})},this.schema||{})}normalize(...e){return a(this.schema,...e)}denormalize(...e){return u(this.schema,...e)}}});e.Entity=f,e.FlatEntity=y,e.SimpleRecord=m,e.denormalize=(e,t,n)=>{if("production"!==process.env.NODE_ENV&&void 0===t)throw new Error("schema needed");if(void 0!==e){const[r,i]=p(n);return[...r(e,t),i]}return[void 0,!1,{}]},e.isEntity=d,e.normalize=(e,t)=>{const n=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(t);if(null===e||typeof e!==n)throw new Error(`Unexpected input given to normalize. Expected type to be "${n}", found "${null===e?"null":typeof e}".`);const r={},i={},s=((e,t)=>(n,r,i,s,o)=>{const c=n.key,a=n.pk(r,s,o);c in e||(e[c]={});const u=e[c][a];if(e[c][a]=u?n.merge(u,r):r,Array.isArray(n.indexes)){const r=e[c][a];c in t||(t[c]={});for(const e of n.indexes){e in t[c]||(t[c][e]={});const n=t[c][e];u&&delete n[u[e]],e in r?n[r[e]]=a:"production"!==process.env.NODE_ENV&&console.warn(`Index not found in entity. Indexes must be top-level members of your entity.\nIndex: ${e}\nEntity: ${JSON.stringify(r,void 0,2)}`)}}})(r,i);return{entities:r,indexes:i,result:O(e,e,void 0,t,s,{})}},e.schema=j,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).rest_hooks_normalizr={})}(this,(function(e){"use strict";function t(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(Object.hasOwnProperty.call(e,"__ownerID")||e._map&&Object.hasOwnProperty.call(e._map,"__ownerID")))}function n(e,t,n){let r=!0;return[Object.keys(e).reduce((t,s)=>{const i=`${s}`,[o,c]=n(t.get(i),e[i]);return c||(r=!1),t.has(i)?t.set(i,o):t},t),r]}class r{constructor(e,t){t&&(this._schemaAttribute="string"==typeof t?e=>e[t]:t),this.define(e)}get isSingleSchema(){return!this._schemaAttribute}define(e){this.schema=e}getSchemaAttribute(e,t,n){return!this.isSingleSchema&&this._schemaAttribute(e,t,n)}inferSchema(e,t,n){if(this.isSingleSchema)return this.schema;const r=this.getSchemaAttribute(e,t,n);return this.schema[r]}normalizeValue(e,t,n,r,s,i){const o=this.inferSchema(e,t,n);if(!o)return e;const c=r(e,t,n,o,s,i);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,n)}}denormalizeValue(e,n){const r=t(e)?e.get("schema"):e.schema;return this.isSingleSchema||r?n((this.isSingleSchema?void 0:t(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[r]):[e,!0]}}const s=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]},i=e=>Array.isArray(e)?e:Object.keys(e).map(t=>e[t]),o=(e,t,n,r,o,c,a)=>(e=s(e),i(t).map((t,s)=>o(t,n,r,e,c,a))),c=(e,t,n)=>{e=s(e);let r=!0;return void 0===t&&e&&([,r]=n(void 0,e)),[t&&t.map?t.map(t=>n(t,e)).filter(([,e])=>e).map(([e])=>e):t,r]};const a=(e,t,n,r,s,i,o)=>{const c=Object.assign({},t);return Object.keys(e).forEach(n=>{const r=e[n],a=s(t[n],t,n,r,i,o);null==a?delete c[n]:c[n]=a}),c},u=(e,r,s)=>{if(t(r))return n(e,r,s);const i=Object.assign({},r);let o=!0;return Object.keys(e).forEach(t=>{const[n,r]=s(i[t],e[t]);void 0!==i[t]&&(i[t]=n),r||(o=!1)}),[i,o]};const l=Symbol("Defined Members"),h=Symbol("unq");class f{toString(){return this[h]}static fromJS(e={},t,n){const r=new this(e);return Object.assign(r,e),Object.defineProperty(r,l,{value:Object.keys(e),writable:!1}),Object.defineProperty(r,h,{value:`${Math.random()}`,writable:!1}),r}static merge(e,t){const n=Object.assign(this.toObjectDefined(e),this.toObjectDefined(t));return this.fromJS(n)}static hasDefined(e,t){return e[l].includes(t)}static toObjectDefined(e){const t={};for(const n of e[l])t[n]=e[n];return t}static keysDefined(e){return e[l]}}class m extends f{static get key(){if("production"!==process.env.NODE_ENV&&""===this.name)throw new Error("Entity classes without a name must define `static get key()`");return this.name}static pk(e,t,n){return this.prototype.pk.call(e,t,n)||n}static asSchema(){return this}static normalize(e,t,n,r,s,i){const o=this.fromJS(e,t,n);if("production"!==process.env.NODE_ENV){const e=new this,t=new Set(Object.keys(e));let[n,r]=[0,0],s=!1;for(const e of m.keysDefined(o))t.has(e)?n++:(r++,s=!0);if(r+=t.size-n,r>n&&t.size&&s){const t=new Error(`Attempted to initialize ${this.name} with substantially different than expected keys\n\n This is likely due to a malformed response.\n Try inspecting the network response or fetch() return value.\n\n Expected keys: ${Object.keys(e)}\n Value: ${JSON.stringify(m.toObjectDefined(o),null,2)}`);throw t.status=400,t}}const c=o.pk(t,n);if(void 0===c||""===c){if("production"!==process.env.NODE_ENV){const t=new Error(`Missing usable resource key when normalizing response.\n\n This is likely due to a malformed response.\n Try inspecting the network response or fetch() return value.\n\n Entity: ${this.name}\n Value: ${e&&JSON.stringify(e,null,2)}\n `);throw t.status=400,t}throw new Error("undefined pk")}const a=this.key;return a in i||(i[a]={}),c in i[a]||(i[a][c]=[]),i[a][c].some(t=>t===e)||(i[a][c].push(e),Object.keys(this.schema).forEach(e=>{if(Object.hasOwnProperty.call(o,e)&&"object"==typeof o[e]){const t=this.schema[e];o[e]=r(o[e],o,e,t,s,i)}}),s(this,o,o,t,n)),c}static denormalize(e,r){if(t(e)){const[t,s]=n(this.schema,e,r);return[this.fromJS(t.toObject()),s]}let s=!0;const i=e;return Object.keys(this.schema).forEach(t=>{const n=this.schema[t],[o,c]=r(e[t],n);c||(s=!1),this.hasDefined(e,t)&&i[t]!==o&&(i[t]=o)}),[i,s]}}function d(e){return null!==e&&void 0!==e.pk}m.schema={},"production"!==process.env.NODE_ENV&&(m.fromJS=function(e){if(void 0===this.prototype.pk)throw new Error("cannot construct on abstract types");return f.fromJS.call(this,e)});class y extends m{static denormalize(e,t){return[e,!0]}}const p=e=>{const n={},r=b(e);return[function e(s,i){if(!i)return[s,!0];if("object"==typeof i&&(!i.denormalize||"function"!=typeof i.denormalize)){return(Array.isArray(i)?c:u)(i,s,e)}return null===s?[s,!0]:d(i)?void 0===s?[s,!1]:((e,n,r,s,i)=>{const o=s(e,n);if("object"!=typeof o||null===o)return[o,!1];i[n.key]||(i[n.key]={});let c=!0;if(!i[n.key][e]){const s=t(o)||o instanceof y?o:n.fromJS(o);i[n.key][e]=s,[i[n.key][e],c]=n.denormalize(s,r)}return[i[n.key][e],c]})(s,i,e,r,n):"function"==typeof i.denormalize?i.denormalize(s,e):[s,!0]},n]},b=e=>{const n=t(e);return(t,r)=>{const s=r.key;return"object"==typeof t?t:n?e.getIn([s,t]):e[s]&&e[s][t]}},O=(e,t,n,r,s,i)=>{if("object"!=typeof e||!e||!r)return e;if("object"==typeof r&&(!r.normalize||"function"!=typeof r.normalize)){return(Array.isArray(r)?o:a)(r,e,t,n,O,s,i)}return r.normalize(e,t,n,O,s,i)};var j=Object.freeze({__proto__:null,Union:class extends r{constructor(e,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');super(e,t)}normalize(e,t,n,r,s,i){return this.normalizeValue(e,t,n,r,s,i)}denormalize(e,t){return this.denormalizeValue(e,t)}},Values:class extends r{normalize(e,t,n,r,s,i){return Object.keys(e).reduce((t,n,o)=>{const c=e[n];return null!=c?Object.assign({},t,{[n]:this.normalizeValue(c,e,n,r,s,i)}):t},{})}denormalize(e,t){let n=!0;return[Object.keys(e).reduce((r,s)=>{const i=e[s],[o,c]=this.denormalizeValue(i,t);return c||(n=!1),Object.assign({},r,{[s]:o})},{}),n]}},Array:class extends r{normalize(e,t,n,r,s,o){return i(e).map((e,i)=>this.normalizeValue(e,t,n,r,s,o)).filter(e=>null!=e)}denormalize(e,t){let n=!0;return void 0===e&&this.schema&&([,n]=t(void 0,this.schema)),[e&&e.map?e.map(e=>this.denormalizeValue(e,t)).filter(([,e])=>e).map(([e])=>e):e,n]}},Object:class{constructor(e){this.define(e)}define(e){this.schema=Object.keys(e).reduce((t,n)=>{const r=e[n];return Object.assign({},t,{[n]:r})},this.schema||{})}normalize(...e){return a(this.schema,...e)}denormalize(...e){return u(this.schema,...e)}}});e.Entity=m,e.FlatEntity=y,e.SimpleRecord=f,e.denormalize=(e,t,n)=>{if("production"!==process.env.NODE_ENV&&void 0===t)throw new Error("schema needed");if(void 0!==e){const[r,s]=p(n);return[...r(e,t),s]}return[void 0,!1,{}]},e.isEntity=d,e.normalize=(e,t)=>{const n=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(t);if(null===e||typeof e!==n)throw new Error(`Unexpected input given to normalize. Expected type to be "${n}", found "${null===e?"null":typeof e}".`);const r={},s={},i=((e,t)=>(n,r,s,i,o)=>{const c=n.key,a=n.pk(s,i,o);c in e||(e[c]={});const u=e[c][a];if(e[c][a]=u?n.merge(u,r):r,Array.isArray(n.indexes)){const r=e[c][a];c in t||(t[c]={});for(const e of n.indexes){e in t[c]||(t[c][e]={});const n=t[c][e];u&&delete n[u[e]],e in r?n[r[e]]=a:"production"!==process.env.NODE_ENV&&console.warn(`Index not found in entity. Indexes must be top-level members of your entity.\nIndex: ${e}\nEntity: ${JSON.stringify(r,void 0,2)}`)}}})(r,s);return{entities:r,indexes:s,result:O(e,e,void 0,t,i,{})}},e.schema=j,Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "@rest-hooks/normalizr",
"version": "6.0.0-beta.1",
"version": "6.0.0-beta.2",
"description": "Normalizes and denormalizes JSON according to schema for Redux and Flux applications",

@@ -61,4 +61,3 @@ "homepage": "https://github.com/coinbase/rest-hooks/tree/master/packages/normalizr#readme",

"@babel/runtime": "^7.7.0"
},
"gitHead": "b4281279a22304f794ecc4c579d99bb7642b49e9"
}
}

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