@rest-hooks/normalizr
Advanced tools
Comparing version 4.1.0 to 4.1.1
@@ -6,2 +6,21 @@ # Change Log | ||
### [4.1.1](https://github.com/coinbase/rest-hooks/compare/@rest-hooks/normalizr@4.1.0...@rest-hooks/normalizr@4.1.1) (2020-01-05) | ||
### 💅 Enhancement | ||
* Remove extraneous logic - schema is not allowed to be null ([775cc8a](https://github.com/coinbase/rest-hooks/commit/775cc8a47a7d016f3f33766aee83a0154b7385ac)) | ||
### 📦 Package | ||
* Build things ([9d386aa](https://github.com/coinbase/rest-hooks/commit/9d386aa1ab944159f5ed4576b81d8d5e5f67847b)) | ||
### 🏠 Internal | ||
* Run normalizr typescript tests ([#223](https://github.com/coinbase/rest-hooks/issues/223)) ([17a3f84](https://github.com/coinbase/rest-hooks/commit/17a3f84a390762173843736ad0b2d6a3ef8e031f)) | ||
## 4.1.0 (2019-12-31) | ||
@@ -8,0 +27,0 @@ |
@@ -558,3 +558,3 @@ define(['exports'], function (exports) { 'use strict'; | ||
if (input === null || typeof input !== typeof schema) { | ||
throw new Error("Unexpected input given to normalize. Expected type to be \"" + (schema === null ? 'null' : typeof schema) + "\", found \"" + (input === null ? 'null' : typeof input) + "\"."); | ||
throw new Error("Unexpected input given to normalize. Expected type to be \"" + typeof schema + "\", found \"" + (input === null ? 'null' : typeof input) + "\"."); | ||
} | ||
@@ -561,0 +561,0 @@ |
@@ -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 r(e,t,r){let n=!0;return[Object.keys(e).reduce((t,s)=>{const i=""+s,[o,c]=r(t.get(i),e[i]);return c||(n=!1),t.has(i)?t.set(i,o):t},t),n]}const n=e=>r=>t(r)?r.get(e):r[e];class s{constructor(e,t={},r={}){if(!e||"string"!=typeof e)throw new Error("Expected a string key for Entity, but found "+e+".");const{idAttribute:s="id",mergeStrategy:i=((e,t)=>Object.assign({},e,{},t)),processStrategy:o=(e=>Object.assign({},e))}=r;this._key=e,this._getId="function"==typeof s?s:n(s),this._idAttribute=s,this._mergeStrategy=i,this._processStrategy=o,this.define(t)}get key(){return this._key}get idAttribute(){return this._idAttribute}define(e){this.schema=Object.keys(e).reduce((t,r)=>{const n=e[r];return Object.assign({},t,{[r]:n})},this.schema||{})}getId(e,t,r){return this._getId(e,t,r)}merge(e,t){return this._mergeStrategy(e,t)}normalize(e,t,r,n,s,i){const o=this.getId(e,t,r),c=this.key;if(c in i||(i[c]={}),o in i[c]||(i[c][o]=[]),i[c][o].some(t=>t===e))return o;i[c][o].push(e);const a=this._processStrategy(e,t,r);return Object.keys(this.schema).forEach(e=>{if(Object.hasOwnProperty.call(a,e)&&"object"==typeof a[e]){const t=this.schema[e];a[e]=n(a[e],a,e,t,s,i)}}),s(this,a,e,t,r),o}denormalize(e,n){if(t(e))return r(this.schema,e,n);let s=!0;return Object.keys(this.schema).forEach(t=>{const r=this.schema[t],[i,o]=n(e[t],r);o||(s=!1),Object.hasOwnProperty.call(e,t)&&(e[t]=i)}),[e,s]}}class i{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,r){return!this.isSingleSchema&&this._schemaAttribute(e,t,r)}inferSchema(e,t,r){if(this.isSingleSchema)return this.schema;const n=this.getSchemaAttribute(e,t,r);return this.schema[n]}normalizeValue(e,t,r,n,s,i){const o=this.inferSchema(e,t,r);if(!o)return e;const c=n(e,t,r,o,s,i);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,r)}}denormalizeValue(e,r){const n=t(e)?e.get("schema"):e.schema;return this.isSingleSchema||n?r((t(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[n]):[e,!0]}}const o=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]},c=e=>Array.isArray(e)?e:Object.keys(e).map(t=>e[t]),a=(e,t,r,n,s,i,a)=>{return e=o(e),c(t).map((t,o)=>s(t,r,n,e,i,a))},u=(e,t,r)=>{e=o(e);let n=!0;return void 0===t&&e&&([,n]=r(void 0,e)),[t&&t.map?t.map(t=>r(t,e)).filter(([,e])=>e).map(([e])=>e):t,n]};const h=(e,t,r,n,s,i,o)=>{const c=Object.assign({},t);return Object.keys(e).forEach(r=>{const n=e[r],a=s(t[r],t,r,n,i,o);null==a?delete c[r]:c[r]=a}),c},l=(e,n,s)=>{if(t(n))return r(e,n,s);const i=Object.assign({},n);let o=!0;return Object.keys(e).forEach(t=>{const[r,n]=s(i[t],e[t]);null!=i[t]&&(i[t]=r),n||(o=!1)}),[i,o]};const m=(e,t,r,n,s,i)=>{if("object"!=typeof e||!e)return e;if("object"==typeof n&&(!n.normalize||"function"!=typeof n.normalize)){return(Array.isArray(n)?a:h)(n,e,t,r,m,s,i)}return n.normalize(e,t,r,m,s,i)},f={Array:class extends i{normalize(e,t,r,n,s,i){return c(e).map((e,o)=>this.normalizeValue(e,t,r,n,s,i)).filter(e=>null!=e)}denormalize(e,t){let r=!0;return void 0===e&&this.schema&&([,r]=t(void 0,this.schema)),[e&&e.map?e.map(e=>this.denormalizeValue(e,t)).filter(([,e])=>e).map(([e])=>e):e,r]}},Entity:s,Object:class{constructor(e){this.define(e)}define(e){this.schema=Object.keys(e).reduce((t,r)=>{const n=e[r];return Object.assign({},t,{[r]:n})},this.schema||{})}normalize(...e){return h(this.schema,...e)}denormalize(...e){return l(this.schema,...e)}},Union:class extends i{constructor(e,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');super(e,t)}normalize(e,t,r,n,s,i){return this.normalizeValue(e,t,r,n,s,i)}denormalize(e,t){return this.denormalizeValue(e,t)}},Values:class extends i{normalize(e,t,r,n,s,i){return Object.keys(e).reduce((t,r,o)=>{const c=e[r];return null!=c?Object.assign({},t,{[r]:this.normalizeValue(c,e,r,n,s,i)}):t},{})}denormalize(e,t){let r=!0;return[Object.keys(e).reduce((n,s)=>{const i=e[s],[o,c]=this.denormalizeValue(i,t);return c||(r=!1),Object.assign({},n,{[s]:o})},{}),r]}}},y=e=>{const r={},n=d(e);return function e(i,o){if("object"==typeof o&&(!o.denormalize||"function"!=typeof o.denormalize)){return(Array.isArray(o)?u:l)(o,i,e)}return null===i?[i,!0]:o instanceof s?void 0===i?[i,!1]:((e,r,n,s,i)=>{const o=s(e,r);if("object"!=typeof o||null===o)return[o,!1];i[r.key]||(i[r.key]={});let c=!0;if(!i[r.key][e]){const s=t(o)?o:Object.assign({},o);i[r.key][e]=s,[i[r.key][e],c]=r.denormalize(s,n)}return[i[r.key][e],c]})(i,o,e,n,r):"function"==typeof o.denormalize?o.denormalize(i,e):[i,!0]}},d=e=>{const r=t(e);return(t,n)=>{const s=n.key;return"object"==typeof t?t:r?e.getIn([s,t.toString()]):e[s]&&e[s][t]}};e.denormalize=(e,t,r)=>void 0!==e?y(r)(e,t):[void 0,!1],e.normalize=(e,t)=>{if(null===e||typeof e!=typeof t)throw new Error('Unexpected input given to normalize. Expected type to be "'+(null===t?"null":typeof t)+'", found "'+(null===e?"null":typeof e)+'".');const r={},n=(e=>(t,r,n,s,i)=>{const o=t.key,c=t.getId(n,s,i);o in e||(e[o]={});const a=e[o][c];e[o][c]=a?t.merge(a,r):r})(r);return{entities:r,result:m(e,e,null,t,n,{})}},e.schema=f,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 r(e,t,r){let n=!0;return[Object.keys(e).reduce((t,s)=>{const i=""+s,[o,c]=r(t.get(i),e[i]);return c||(n=!1),t.has(i)?t.set(i,o):t},t),n]}const n=e=>r=>t(r)?r.get(e):r[e];class s{constructor(e,t={},r={}){if(!e||"string"!=typeof e)throw new Error("Expected a string key for Entity, but found "+e+".");const{idAttribute:s="id",mergeStrategy:i=((e,t)=>Object.assign({},e,{},t)),processStrategy:o=(e=>Object.assign({},e))}=r;this._key=e,this._getId="function"==typeof s?s:n(s),this._idAttribute=s,this._mergeStrategy=i,this._processStrategy=o,this.define(t)}get key(){return this._key}get idAttribute(){return this._idAttribute}define(e){this.schema=Object.keys(e).reduce((t,r)=>{const n=e[r];return Object.assign({},t,{[r]:n})},this.schema||{})}getId(e,t,r){return this._getId(e,t,r)}merge(e,t){return this._mergeStrategy(e,t)}normalize(e,t,r,n,s,i){const o=this.getId(e,t,r),c=this.key;if(c in i||(i[c]={}),o in i[c]||(i[c][o]=[]),i[c][o].some(t=>t===e))return o;i[c][o].push(e);const a=this._processStrategy(e,t,r);return Object.keys(this.schema).forEach(e=>{if(Object.hasOwnProperty.call(a,e)&&"object"==typeof a[e]){const t=this.schema[e];a[e]=n(a[e],a,e,t,s,i)}}),s(this,a,e,t,r),o}denormalize(e,n){if(t(e))return r(this.schema,e,n);let s=!0;return Object.keys(this.schema).forEach(t=>{const r=this.schema[t],[i,o]=n(e[t],r);o||(s=!1),Object.hasOwnProperty.call(e,t)&&(e[t]=i)}),[e,s]}}class i{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,r){return!this.isSingleSchema&&this._schemaAttribute(e,t,r)}inferSchema(e,t,r){if(this.isSingleSchema)return this.schema;const n=this.getSchemaAttribute(e,t,r);return this.schema[n]}normalizeValue(e,t,r,n,s,i){const o=this.inferSchema(e,t,r);if(!o)return e;const c=n(e,t,r,o,s,i);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,r)}}denormalizeValue(e,r){const n=t(e)?e.get("schema"):e.schema;return this.isSingleSchema||n?r((t(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[n]):[e,!0]}}const o=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]},c=e=>Array.isArray(e)?e:Object.keys(e).map(t=>e[t]),a=(e,t,r,n,s,i,a)=>{return e=o(e),c(t).map((t,o)=>s(t,r,n,e,i,a))},u=(e,t,r)=>{e=o(e);let n=!0;return void 0===t&&e&&([,n]=r(void 0,e)),[t&&t.map?t.map(t=>r(t,e)).filter(([,e])=>e).map(([e])=>e):t,n]};const h=(e,t,r,n,s,i,o)=>{const c=Object.assign({},t);return Object.keys(e).forEach(r=>{const n=e[r],a=s(t[r],t,r,n,i,o);null==a?delete c[r]:c[r]=a}),c},l=(e,n,s)=>{if(t(n))return r(e,n,s);const i=Object.assign({},n);let o=!0;return Object.keys(e).forEach(t=>{const[r,n]=s(i[t],e[t]);null!=i[t]&&(i[t]=r),n||(o=!1)}),[i,o]};const m=(e,t,r,n,s,i)=>{if("object"!=typeof e||!e)return e;if("object"==typeof n&&(!n.normalize||"function"!=typeof n.normalize)){return(Array.isArray(n)?a:h)(n,e,t,r,m,s,i)}return n.normalize(e,t,r,m,s,i)},f={Array:class extends i{normalize(e,t,r,n,s,i){return c(e).map((e,o)=>this.normalizeValue(e,t,r,n,s,i)).filter(e=>null!=e)}denormalize(e,t){let r=!0;return void 0===e&&this.schema&&([,r]=t(void 0,this.schema)),[e&&e.map?e.map(e=>this.denormalizeValue(e,t)).filter(([,e])=>e).map(([e])=>e):e,r]}},Entity:s,Object:class{constructor(e){this.define(e)}define(e){this.schema=Object.keys(e).reduce((t,r)=>{const n=e[r];return Object.assign({},t,{[r]:n})},this.schema||{})}normalize(...e){return h(this.schema,...e)}denormalize(...e){return l(this.schema,...e)}},Union:class extends i{constructor(e,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');super(e,t)}normalize(e,t,r,n,s,i){return this.normalizeValue(e,t,r,n,s,i)}denormalize(e,t){return this.denormalizeValue(e,t)}},Values:class extends i{normalize(e,t,r,n,s,i){return Object.keys(e).reduce((t,r,o)=>{const c=e[r];return null!=c?Object.assign({},t,{[r]:this.normalizeValue(c,e,r,n,s,i)}):t},{})}denormalize(e,t){let r=!0;return[Object.keys(e).reduce((n,s)=>{const i=e[s],[o,c]=this.denormalizeValue(i,t);return c||(r=!1),Object.assign({},n,{[s]:o})},{}),r]}}},y=e=>{const r={},n=d(e);return function e(i,o){if("object"==typeof o&&(!o.denormalize||"function"!=typeof o.denormalize)){return(Array.isArray(o)?u:l)(o,i,e)}return null===i?[i,!0]:o instanceof s?void 0===i?[i,!1]:((e,r,n,s,i)=>{const o=s(e,r);if("object"!=typeof o||null===o)return[o,!1];i[r.key]||(i[r.key]={});let c=!0;if(!i[r.key][e]){const s=t(o)?o:Object.assign({},o);i[r.key][e]=s,[i[r.key][e],c]=r.denormalize(s,n)}return[i[r.key][e],c]})(i,o,e,n,r):"function"==typeof o.denormalize?o.denormalize(i,e):[i,!0]}},d=e=>{const r=t(e);return(t,n)=>{const s=n.key;return"object"==typeof t?t:r?e.getIn([s,t.toString()]):e[s]&&e[s][t]}};e.denormalize=(e,t,r)=>void 0!==e?y(r)(e,t):[void 0,!1],e.normalize=(e,t)=>{if(null===e||typeof e!=typeof t)throw new Error('Unexpected input given to normalize. Expected type to be "'+typeof t+'", found "'+(null===e?"null":typeof e)+'".');const r={},n=(e=>(t,r,n,s,i)=>{const o=t.key,c=t.getId(n,s,i);o in e||(e[o]={});const a=e[o][c];e[o][c]=a?t.merge(a,r):r})(r);return{entities:r,result:m(e,e,null,t,n,{})}},e.schema=f,Object.defineProperty(e,"__esModule",{value:!0})})); |
@@ -559,3 +559,3 @@ var rest_hooks_normalizr = (function (exports) { | ||
if (input === null || typeof input !== typeof schema) { | ||
throw new Error("Unexpected input given to normalize. Expected type to be \"" + (schema === null ? 'null' : typeof schema) + "\", found \"" + (input === null ? 'null' : typeof input) + "\"."); | ||
throw new Error("Unexpected input given to normalize. Expected type to be \"" + typeof schema + "\", found \"" + (input === null ? 'null' : typeof input) + "\"."); | ||
} | ||
@@ -562,0 +562,0 @@ |
@@ -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 r(e,t,r){let n=!0;return[Object.keys(e).reduce((t,s)=>{const i=""+s,[o,c]=r(t.get(i),e[i]);return c||(n=!1),t.has(i)?t.set(i,o):t},t),n]}const n=e=>r=>t(r)?r.get(e):r[e];class s{constructor(e,t={},r={}){if(!e||"string"!=typeof e)throw new Error("Expected a string key for Entity, but found "+e+".");const{idAttribute:s="id",mergeStrategy:i=((e,t)=>Object.assign({},e,{},t)),processStrategy:o=(e=>Object.assign({},e))}=r;this._key=e,this._getId="function"==typeof s?s:n(s),this._idAttribute=s,this._mergeStrategy=i,this._processStrategy=o,this.define(t)}get key(){return this._key}get idAttribute(){return this._idAttribute}define(e){this.schema=Object.keys(e).reduce((t,r)=>{const n=e[r];return Object.assign({},t,{[r]:n})},this.schema||{})}getId(e,t,r){return this._getId(e,t,r)}merge(e,t){return this._mergeStrategy(e,t)}normalize(e,t,r,n,s,i){const o=this.getId(e,t,r),c=this.key;if(c in i||(i[c]={}),o in i[c]||(i[c][o]=[]),i[c][o].some(t=>t===e))return o;i[c][o].push(e);const a=this._processStrategy(e,t,r);return Object.keys(this.schema).forEach(e=>{if(Object.hasOwnProperty.call(a,e)&&"object"==typeof a[e]){const t=this.schema[e];a[e]=n(a[e],a,e,t,s,i)}}),s(this,a,e,t,r),o}denormalize(e,n){if(t(e))return r(this.schema,e,n);let s=!0;return Object.keys(this.schema).forEach(t=>{const r=this.schema[t],[i,o]=n(e[t],r);o||(s=!1),Object.hasOwnProperty.call(e,t)&&(e[t]=i)}),[e,s]}}class i{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,r){return!this.isSingleSchema&&this._schemaAttribute(e,t,r)}inferSchema(e,t,r){if(this.isSingleSchema)return this.schema;const n=this.getSchemaAttribute(e,t,r);return this.schema[n]}normalizeValue(e,t,r,n,s,i){const o=this.inferSchema(e,t,r);if(!o)return e;const c=n(e,t,r,o,s,i);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,r)}}denormalizeValue(e,r){const n=t(e)?e.get("schema"):e.schema;return this.isSingleSchema||n?r((t(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[n]):[e,!0]}}const o=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]},c=e=>Array.isArray(e)?e:Object.keys(e).map(t=>e[t]),a=(e,t,r,n,s,i,a)=>{return e=o(e),c(t).map((t,o)=>s(t,r,n,e,i,a))},u=(e,t,r)=>{e=o(e);let n=!0;return void 0===t&&e&&([,n]=r(void 0,e)),[t&&t.map?t.map(t=>r(t,e)).filter(([,e])=>e).map(([e])=>e):t,n]};const h=(e,t,r,n,s,i,o)=>{const c=Object.assign({},t);return Object.keys(e).forEach(r=>{const n=e[r],a=s(t[r],t,r,n,i,o);null==a?delete c[r]:c[r]=a}),c},l=(e,n,s)=>{if(t(n))return r(e,n,s);const i=Object.assign({},n);let o=!0;return Object.keys(e).forEach(t=>{const[r,n]=s(i[t],e[t]);null!=i[t]&&(i[t]=r),n||(o=!1)}),[i,o]};const m=(e,t,r,n,s,i)=>{if("object"!=typeof e||!e)return e;if("object"==typeof n&&(!n.normalize||"function"!=typeof n.normalize)){return(Array.isArray(n)?a:h)(n,e,t,r,m,s,i)}return n.normalize(e,t,r,m,s,i)},f={Array:class extends i{normalize(e,t,r,n,s,i){return c(e).map((e,o)=>this.normalizeValue(e,t,r,n,s,i)).filter(e=>null!=e)}denormalize(e,t){let r=!0;return void 0===e&&this.schema&&([,r]=t(void 0,this.schema)),[e&&e.map?e.map(e=>this.denormalizeValue(e,t)).filter(([,e])=>e).map(([e])=>e):e,r]}},Entity:s,Object:class{constructor(e){this.define(e)}define(e){this.schema=Object.keys(e).reduce((t,r)=>{const n=e[r];return Object.assign({},t,{[r]:n})},this.schema||{})}normalize(...e){return h(this.schema,...e)}denormalize(...e){return l(this.schema,...e)}},Union:class extends i{constructor(e,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');super(e,t)}normalize(e,t,r,n,s,i){return this.normalizeValue(e,t,r,n,s,i)}denormalize(e,t){return this.denormalizeValue(e,t)}},Values:class extends i{normalize(e,t,r,n,s,i){return Object.keys(e).reduce((t,r,o)=>{const c=e[r];return null!=c?Object.assign({},t,{[r]:this.normalizeValue(c,e,r,n,s,i)}):t},{})}denormalize(e,t){let r=!0;return[Object.keys(e).reduce((n,s)=>{const i=e[s],[o,c]=this.denormalizeValue(i,t);return c||(r=!1),Object.assign({},n,{[s]:o})},{}),r]}}},y=e=>{const r={},n=d(e);return function e(i,o){if("object"==typeof o&&(!o.denormalize||"function"!=typeof o.denormalize)){return(Array.isArray(o)?u:l)(o,i,e)}return null===i?[i,!0]:o instanceof s?void 0===i?[i,!1]:((e,r,n,s,i)=>{const o=s(e,r);if("object"!=typeof o||null===o)return[o,!1];i[r.key]||(i[r.key]={});let c=!0;if(!i[r.key][e]){const s=t(o)?o:Object.assign({},o);i[r.key][e]=s,[i[r.key][e],c]=r.denormalize(s,n)}return[i[r.key][e],c]})(i,o,e,n,r):"function"==typeof o.denormalize?o.denormalize(i,e):[i,!0]}},d=e=>{const r=t(e);return(t,n)=>{const s=n.key;return"object"==typeof t?t:r?e.getIn([s,t.toString()]):e[s]&&e[s][t]}};return e.denormalize=(e,t,r)=>void 0!==e?y(r)(e,t):[void 0,!1],e.normalize=(e,t)=>{if(null===e||typeof e!=typeof t)throw new Error('Unexpected input given to normalize. Expected type to be "'+(null===t?"null":typeof t)+'", found "'+(null===e?"null":typeof e)+'".');const r={},n=(e=>(t,r,n,s,i)=>{const o=t.key,c=t.getId(n,s,i);o in e||(e[o]={});const a=e[o][c];e[o][c]=a?t.merge(a,r):r})(r);return{entities:r,result:m(e,e,null,t,n,{})}},e.schema=f,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 r(e,t,r){let n=!0;return[Object.keys(e).reduce((t,s)=>{const i=""+s,[o,c]=r(t.get(i),e[i]);return c||(n=!1),t.has(i)?t.set(i,o):t},t),n]}const n=e=>r=>t(r)?r.get(e):r[e];class s{constructor(e,t={},r={}){if(!e||"string"!=typeof e)throw new Error("Expected a string key for Entity, but found "+e+".");const{idAttribute:s="id",mergeStrategy:i=((e,t)=>Object.assign({},e,{},t)),processStrategy:o=(e=>Object.assign({},e))}=r;this._key=e,this._getId="function"==typeof s?s:n(s),this._idAttribute=s,this._mergeStrategy=i,this._processStrategy=o,this.define(t)}get key(){return this._key}get idAttribute(){return this._idAttribute}define(e){this.schema=Object.keys(e).reduce((t,r)=>{const n=e[r];return Object.assign({},t,{[r]:n})},this.schema||{})}getId(e,t,r){return this._getId(e,t,r)}merge(e,t){return this._mergeStrategy(e,t)}normalize(e,t,r,n,s,i){const o=this.getId(e,t,r),c=this.key;if(c in i||(i[c]={}),o in i[c]||(i[c][o]=[]),i[c][o].some(t=>t===e))return o;i[c][o].push(e);const a=this._processStrategy(e,t,r);return Object.keys(this.schema).forEach(e=>{if(Object.hasOwnProperty.call(a,e)&&"object"==typeof a[e]){const t=this.schema[e];a[e]=n(a[e],a,e,t,s,i)}}),s(this,a,e,t,r),o}denormalize(e,n){if(t(e))return r(this.schema,e,n);let s=!0;return Object.keys(this.schema).forEach(t=>{const r=this.schema[t],[i,o]=n(e[t],r);o||(s=!1),Object.hasOwnProperty.call(e,t)&&(e[t]=i)}),[e,s]}}class i{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,r){return!this.isSingleSchema&&this._schemaAttribute(e,t,r)}inferSchema(e,t,r){if(this.isSingleSchema)return this.schema;const n=this.getSchemaAttribute(e,t,r);return this.schema[n]}normalizeValue(e,t,r,n,s,i){const o=this.inferSchema(e,t,r);if(!o)return e;const c=n(e,t,r,o,s,i);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,r)}}denormalizeValue(e,r){const n=t(e)?e.get("schema"):e.schema;return this.isSingleSchema||n?r((t(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[n]):[e,!0]}}const o=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]},c=e=>Array.isArray(e)?e:Object.keys(e).map(t=>e[t]),a=(e,t,r,n,s,i,a)=>{return e=o(e),c(t).map((t,o)=>s(t,r,n,e,i,a))},h=(e,t,r)=>{e=o(e);let n=!0;return void 0===t&&e&&([,n]=r(void 0,e)),[t&&t.map?t.map(t=>r(t,e)).filter(([,e])=>e).map(([e])=>e):t,n]};const u=(e,t,r,n,s,i,o)=>{const c=Object.assign({},t);return Object.keys(e).forEach(r=>{const n=e[r],a=s(t[r],t,r,n,i,o);null==a?delete c[r]:c[r]=a}),c},l=(e,n,s)=>{if(t(n))return r(e,n,s);const i=Object.assign({},n);let o=!0;return Object.keys(e).forEach(t=>{const[r,n]=s(i[t],e[t]);null!=i[t]&&(i[t]=r),n||(o=!1)}),[i,o]};const m=(e,t,r,n,s,i)=>{if("object"!=typeof e||!e)return e;if("object"==typeof n&&(!n.normalize||"function"!=typeof n.normalize)){return(Array.isArray(n)?a:u)(n,e,t,r,m,s,i)}return n.normalize(e,t,r,m,s,i)},f={Array:class extends i{normalize(e,t,r,n,s,i){return c(e).map((e,o)=>this.normalizeValue(e,t,r,n,s,i)).filter(e=>null!=e)}denormalize(e,t){let r=!0;return void 0===e&&this.schema&&([,r]=t(void 0,this.schema)),[e&&e.map?e.map(e=>this.denormalizeValue(e,t)).filter(([,e])=>e).map(([e])=>e):e,r]}},Entity:s,Object:class{constructor(e){this.define(e)}define(e){this.schema=Object.keys(e).reduce((t,r)=>{const n=e[r];return Object.assign({},t,{[r]:n})},this.schema||{})}normalize(...e){return u(this.schema,...e)}denormalize(...e){return l(this.schema,...e)}},Union:class extends i{constructor(e,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');super(e,t)}normalize(e,t,r,n,s,i){return this.normalizeValue(e,t,r,n,s,i)}denormalize(e,t){return this.denormalizeValue(e,t)}},Values:class extends i{normalize(e,t,r,n,s,i){return Object.keys(e).reduce((t,r,o)=>{const c=e[r];return null!=c?Object.assign({},t,{[r]:this.normalizeValue(c,e,r,n,s,i)}):t},{})}denormalize(e,t){let r=!0;return[Object.keys(e).reduce((n,s)=>{const i=e[s],[o,c]=this.denormalizeValue(i,t);return c||(r=!1),Object.assign({},n,{[s]:o})},{}),r]}}},y=e=>{const r={},n=d(e);return function e(i,o){if("object"==typeof o&&(!o.denormalize||"function"!=typeof o.denormalize)){return(Array.isArray(o)?h:l)(o,i,e)}return null===i?[i,!0]:o instanceof s?void 0===i?[i,!1]:((e,r,n,s,i)=>{const o=s(e,r);if("object"!=typeof o||null===o)return[o,!1];i[r.key]||(i[r.key]={});let c=!0;if(!i[r.key][e]){const s=t(o)?o:Object.assign({},o);i[r.key][e]=s,[i[r.key][e],c]=r.denormalize(s,n)}return[i[r.key][e],c]})(i,o,e,n,r):"function"==typeof o.denormalize?o.denormalize(i,e):[i,!0]}},d=e=>{const r=t(e);return(t,n)=>{const s=n.key;return"object"==typeof t?t:r?e.getIn([s,t.toString()]):e[s]&&e[s][t]}};return e.denormalize=(e,t,r)=>void 0!==e?y(r)(e,t):[void 0,!1],e.normalize=(e,t)=>{if(null===e||typeof e!=typeof t)throw new Error('Unexpected input given to normalize. Expected type to be "'+typeof t+'", found "'+(null===e?"null":typeof e)+'".');const r={},n=(e=>(t,r,n,s,i)=>{const o=t.key,c=t.getId(n,s,i);o in e||(e[o]={});const a=e[o][c];e[o][c]=a?t.merge(a,r):r})(r);return{entities:r,result:m(e,e,null,t,n,{})}},e.schema=f,e}({}); |
@@ -537,3 +537,3 @@ import _createClass from '@babel/runtime/helpers/esm/createClass'; | ||
if (input === null || typeof input !== typeof schema) { | ||
throw new Error("Unexpected input given to normalize. Expected type to be \"" + (schema === null ? 'null' : typeof schema) + "\", found \"" + (input === null ? 'null' : typeof input) + "\"."); | ||
throw new Error("Unexpected input given to normalize. Expected type to be \"" + typeof schema + "\", found \"" + (input === null ? 'null' : typeof input) + "\"."); | ||
} | ||
@@ -540,0 +540,0 @@ |
@@ -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,r){let n=!0;return[Object.keys(e).reduce((t,s)=>{const i=""+s,[o,c]=r(t.get(i),e[i]);return c||(n=!1),t.has(i)?t.set(i,o):t},t),n]}const r=t=>r=>e(r)?r.get(t):r[t];class n{constructor(e,t={},n={}){if(!e||"string"!=typeof e)throw new Error("Expected a string key for Entity, but found "+e+".");const{idAttribute:s="id",mergeStrategy:i=((e,t)=>Object.assign({},e,{},t)),processStrategy:o=(e=>Object.assign({},e))}=n;this._key=e,this._getId="function"==typeof s?s:r(s),this._idAttribute=s,this._mergeStrategy=i,this._processStrategy=o,this.define(t)}get key(){return this._key}get idAttribute(){return this._idAttribute}define(e){this.schema=Object.keys(e).reduce((t,r)=>{const n=e[r];return Object.assign({},t,{[r]:n})},this.schema||{})}getId(e,t,r){return this._getId(e,t,r)}merge(e,t){return this._mergeStrategy(e,t)}normalize(e,t,r,n,s,i){const o=this.getId(e,t,r),c=this.key;if(c in i||(i[c]={}),o in i[c]||(i[c][o]=[]),i[c][o].some(t=>t===e))return o;i[c][o].push(e);const a=this._processStrategy(e,t,r);return Object.keys(this.schema).forEach(e=>{if(Object.hasOwnProperty.call(a,e)&&"object"==typeof a[e]){const t=this.schema[e];a[e]=n(a[e],a,e,t,s,i)}}),s(this,a,e,t,r),o}denormalize(r,n){if(e(r))return t(this.schema,r,n);let s=!0;return Object.keys(this.schema).forEach(e=>{const t=this.schema[e],[i,o]=n(r[e],t);o||(s=!1),Object.hasOwnProperty.call(r,e)&&(r[e]=i)}),[r,s]}}class s{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,r){return!this.isSingleSchema&&this._schemaAttribute(e,t,r)}inferSchema(e,t,r){if(this.isSingleSchema)return this.schema;const n=this.getSchemaAttribute(e,t,r);return this.schema[n]}normalizeValue(e,t,r,n,s,i){const o=this.inferSchema(e,t,r);if(!o)return e;const c=n(e,t,r,o,s,i);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,r)}}denormalizeValue(t,r){const n=e(t)?t.get("schema"):t.schema;return this.isSingleSchema||n?r((e(t)?t.get("id"):t.id)||t,this.isSingleSchema?this.schema:this.schema[n]):[t,!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]},o=e=>Array.isArray(e)?e:Object.keys(e).map(t=>e[t]),c=(e,t,r,n,s,c,a)=>{return e=i(e),o(t).map((t,i)=>s(t,r,n,e,c,a))},a=(e,t,r)=>{e=i(e);let n=!0;return void 0===t&&e&&([,n]=r(void 0,e)),[t&&t.map?t.map(t=>r(t,e)).filter(([,e])=>e).map(([e])=>e):t,n]};const h=(e,t,r,n,s,i,o)=>{const c=Object.assign({},t);return Object.keys(e).forEach(r=>{const n=e[r],a=s(t[r],t,r,n,i,o);null==a?delete c[r]:c[r]=a}),c},u=(r,n,s)=>{if(e(n))return t(r,n,s);const i=Object.assign({},n);let o=!0;return Object.keys(r).forEach(e=>{const[t,n]=s(i[e],r[e]);null!=i[e]&&(i[e]=t),n||(o=!1)}),[i,o]};const l=(e,t,r,n,s,i)=>{if("object"!=typeof e||!e)return e;if("object"==typeof n&&(!n.normalize||"function"!=typeof n.normalize)){return(Array.isArray(n)?c:h)(n,e,t,r,l,s,i)}return n.normalize(e,t,r,l,s,i)},m={Array:class extends s{normalize(e,t,r,n,s,i){return o(e).map((e,o)=>this.normalizeValue(e,t,r,n,s,i)).filter(e=>null!=e)}denormalize(e,t){let r=!0;return void 0===e&&this.schema&&([,r]=t(void 0,this.schema)),[e&&e.map?e.map(e=>this.denormalizeValue(e,t)).filter(([,e])=>e).map(([e])=>e):e,r]}},Entity:n,Object:class{constructor(e){this.define(e)}define(e){this.schema=Object.keys(e).reduce((t,r)=>{const n=e[r];return Object.assign({},t,{[r]:n})},this.schema||{})}normalize(...e){return h(this.schema,...e)}denormalize(...e){return u(this.schema,...e)}},Union:class extends s{constructor(e,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');super(e,t)}normalize(e,t,r,n,s,i){return this.normalizeValue(e,t,r,n,s,i)}denormalize(e,t){return this.denormalizeValue(e,t)}},Values:class extends s{normalize(e,t,r,n,s,i){return Object.keys(e).reduce((t,r,o)=>{const c=e[r];return null!=c?Object.assign({},t,{[r]:this.normalizeValue(c,e,r,n,s,i)}):t},{})}denormalize(e,t){let r=!0;return[Object.keys(e).reduce((n,s)=>{const i=e[s],[o,c]=this.denormalizeValue(i,t);return c||(r=!1),Object.assign({},n,{[s]:o})},{}),r]}}},y=(e,t)=>{if(null===e||typeof e!=typeof t)throw new Error('Unexpected input given to normalize. Expected type to be "'+(null===t?"null":typeof t)+'", found "'+(null===e?"null":typeof e)+'".');const r={},n=(e=>(t,r,n,s,i)=>{const o=t.key,c=t.getId(n,s,i);o in e||(e[o]={});const a=e[o][c];e[o][c]=a?t.merge(a,r):r})(r);return{entities:r,result:l(e,e,null,t,n,{})}},f=t=>{const r={},s=d(t);return function t(i,o){if("object"==typeof o&&(!o.denormalize||"function"!=typeof o.denormalize)){return(Array.isArray(o)?a:u)(o,i,t)}return null===i?[i,!0]:o instanceof n?void 0===i?[i,!1]:((t,r,n,s,i)=>{const o=s(t,r);if("object"!=typeof o||null===o)return[o,!1];i[r.key]||(i[r.key]={});let c=!0;if(!i[r.key][t]){const s=e(o)?o:Object.assign({},o);i[r.key][t]=s,[i[r.key][t],c]=r.denormalize(s,n)}return[i[r.key][t],c]})(i,o,t,s,r):"function"==typeof o.denormalize?o.denormalize(i,t):[i,!0]}},d=t=>{const r=e(t);return(e,n)=>{const s=n.key;return"object"==typeof e?e:r?t.getIn([s,e.toString()]):t[s]&&t[s][e]}},g=(e,t,r)=>void 0!==e?f(r)(e,t):[void 0,!1];export{g as denormalize,y as normalize,m 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,r){let n=!0;return[Object.keys(e).reduce((t,s)=>{const i=""+s,[o,c]=r(t.get(i),e[i]);return c||(n=!1),t.has(i)?t.set(i,o):t},t),n]}const r=t=>r=>e(r)?r.get(t):r[t];class n{constructor(e,t={},n={}){if(!e||"string"!=typeof e)throw new Error("Expected a string key for Entity, but found "+e+".");const{idAttribute:s="id",mergeStrategy:i=((e,t)=>Object.assign({},e,{},t)),processStrategy:o=(e=>Object.assign({},e))}=n;this._key=e,this._getId="function"==typeof s?s:r(s),this._idAttribute=s,this._mergeStrategy=i,this._processStrategy=o,this.define(t)}get key(){return this._key}get idAttribute(){return this._idAttribute}define(e){this.schema=Object.keys(e).reduce((t,r)=>{const n=e[r];return Object.assign({},t,{[r]:n})},this.schema||{})}getId(e,t,r){return this._getId(e,t,r)}merge(e,t){return this._mergeStrategy(e,t)}normalize(e,t,r,n,s,i){const o=this.getId(e,t,r),c=this.key;if(c in i||(i[c]={}),o in i[c]||(i[c][o]=[]),i[c][o].some(t=>t===e))return o;i[c][o].push(e);const a=this._processStrategy(e,t,r);return Object.keys(this.schema).forEach(e=>{if(Object.hasOwnProperty.call(a,e)&&"object"==typeof a[e]){const t=this.schema[e];a[e]=n(a[e],a,e,t,s,i)}}),s(this,a,e,t,r),o}denormalize(r,n){if(e(r))return t(this.schema,r,n);let s=!0;return Object.keys(this.schema).forEach(e=>{const t=this.schema[e],[i,o]=n(r[e],t);o||(s=!1),Object.hasOwnProperty.call(r,e)&&(r[e]=i)}),[r,s]}}class s{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,r){return!this.isSingleSchema&&this._schemaAttribute(e,t,r)}inferSchema(e,t,r){if(this.isSingleSchema)return this.schema;const n=this.getSchemaAttribute(e,t,r);return this.schema[n]}normalizeValue(e,t,r,n,s,i){const o=this.inferSchema(e,t,r);if(!o)return e;const c=n(e,t,r,o,s,i);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,r)}}denormalizeValue(t,r){const n=e(t)?t.get("schema"):t.schema;return this.isSingleSchema||n?r((e(t)?t.get("id"):t.id)||t,this.isSingleSchema?this.schema:this.schema[n]):[t,!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]},o=e=>Array.isArray(e)?e:Object.keys(e).map(t=>e[t]),c=(e,t,r,n,s,c,a)=>{return e=i(e),o(t).map((t,i)=>s(t,r,n,e,c,a))},a=(e,t,r)=>{e=i(e);let n=!0;return void 0===t&&e&&([,n]=r(void 0,e)),[t&&t.map?t.map(t=>r(t,e)).filter(([,e])=>e).map(([e])=>e):t,n]};const h=(e,t,r,n,s,i,o)=>{const c=Object.assign({},t);return Object.keys(e).forEach(r=>{const n=e[r],a=s(t[r],t,r,n,i,o);null==a?delete c[r]:c[r]=a}),c},u=(r,n,s)=>{if(e(n))return t(r,n,s);const i=Object.assign({},n);let o=!0;return Object.keys(r).forEach(e=>{const[t,n]=s(i[e],r[e]);null!=i[e]&&(i[e]=t),n||(o=!1)}),[i,o]};const l=(e,t,r,n,s,i)=>{if("object"!=typeof e||!e)return e;if("object"==typeof n&&(!n.normalize||"function"!=typeof n.normalize)){return(Array.isArray(n)?c:h)(n,e,t,r,l,s,i)}return n.normalize(e,t,r,l,s,i)},m={Array:class extends s{normalize(e,t,r,n,s,i){return o(e).map((e,o)=>this.normalizeValue(e,t,r,n,s,i)).filter(e=>null!=e)}denormalize(e,t){let r=!0;return void 0===e&&this.schema&&([,r]=t(void 0,this.schema)),[e&&e.map?e.map(e=>this.denormalizeValue(e,t)).filter(([,e])=>e).map(([e])=>e):e,r]}},Entity:n,Object:class{constructor(e){this.define(e)}define(e){this.schema=Object.keys(e).reduce((t,r)=>{const n=e[r];return Object.assign({},t,{[r]:n})},this.schema||{})}normalize(...e){return h(this.schema,...e)}denormalize(...e){return u(this.schema,...e)}},Union:class extends s{constructor(e,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');super(e,t)}normalize(e,t,r,n,s,i){return this.normalizeValue(e,t,r,n,s,i)}denormalize(e,t){return this.denormalizeValue(e,t)}},Values:class extends s{normalize(e,t,r,n,s,i){return Object.keys(e).reduce((t,r,o)=>{const c=e[r];return null!=c?Object.assign({},t,{[r]:this.normalizeValue(c,e,r,n,s,i)}):t},{})}denormalize(e,t){let r=!0;return[Object.keys(e).reduce((n,s)=>{const i=e[s],[o,c]=this.denormalizeValue(i,t);return c||(r=!1),Object.assign({},n,{[s]:o})},{}),r]}}},y=(e,t)=>{if(null===e||typeof e!=typeof t)throw new Error('Unexpected input given to normalize. Expected type to be "'+typeof t+'", found "'+(null===e?"null":typeof e)+'".');const r={},n=(e=>(t,r,n,s,i)=>{const o=t.key,c=t.getId(n,s,i);o in e||(e[o]={});const a=e[o][c];e[o][c]=a?t.merge(a,r):r})(r);return{entities:r,result:l(e,e,null,t,n,{})}},f=t=>{const r={},s=d(t);return function t(i,o){if("object"==typeof o&&(!o.denormalize||"function"!=typeof o.denormalize)){return(Array.isArray(o)?a:u)(o,i,t)}return null===i?[i,!0]:o instanceof n?void 0===i?[i,!1]:((t,r,n,s,i)=>{const o=s(t,r);if("object"!=typeof o||null===o)return[o,!1];i[r.key]||(i[r.key]={});let c=!0;if(!i[r.key][t]){const s=e(o)?o:Object.assign({},o);i[r.key][t]=s,[i[r.key][t],c]=r.denormalize(s,n)}return[i[r.key][t],c]})(i,o,t,s,r):"function"==typeof o.denormalize?o.denormalize(i,t):[i,!0]}},d=t=>{const r=e(t);return(e,n)=>{const s=n.key;return"object"==typeof e?e:r?t.getIn([s,e.toString()]):t[s]&&t[s][e]}},g=(e,t,r)=>void 0!==e?f(r)(e,t):[void 0,!1];export{g as denormalize,y as normalize,m as schema}; |
@@ -560,3 +560,3 @@ 'use strict'; | ||
if (input === null || typeof input !== typeof schema) { | ||
throw new Error("Unexpected input given to normalize. Expected type to be \"" + (schema === null ? 'null' : typeof schema) + "\", found \"" + (input === null ? 'null' : typeof input) + "\"."); | ||
throw new Error("Unexpected input given to normalize. Expected type to be \"" + typeof schema + "\", found \"" + (input === null ? 'null' : typeof input) + "\"."); | ||
} | ||
@@ -563,0 +563,0 @@ |
@@ -1,1 +0,1 @@ | ||
"use strict";function isImmutable(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(Object.hasOwnProperty.call(e,"__ownerID")||e._map&&Object.hasOwnProperty.call(e._map,"__ownerID")))}function denormalizeImmutable(e,t,r){let i=!0;return[Object.keys(e).reduce((t,n)=>{const s=""+n,[a,o]=r(t.get(s),e[s]);return o||(i=!1),t.has(s)?t.set(s,a):t},t),i]}Object.defineProperty(exports,"__esModule",{value:!0});const getDefaultGetId=e=>t=>isImmutable(t)?t.get(e):t[e];class EntitySchema{constructor(e,t={},r={}){if(!e||"string"!=typeof e)throw new Error("Expected a string key for Entity, but found "+e+".");const{idAttribute:i="id",mergeStrategy:n=((e,t)=>Object.assign({},e,{},t)),processStrategy:s=(e=>Object.assign({},e))}=r;this._key=e,this._getId="function"==typeof i?i:getDefaultGetId(i),this._idAttribute=i,this._mergeStrategy=n,this._processStrategy=s,this.define(t)}get key(){return this._key}get idAttribute(){return this._idAttribute}define(e){this.schema=Object.keys(e).reduce((t,r)=>{const i=e[r];return Object.assign({},t,{[r]:i})},this.schema||{})}getId(e,t,r){return this._getId(e,t,r)}merge(e,t){return this._mergeStrategy(e,t)}normalize(e,t,r,i,n,s){const a=this.getId(e,t,r),o=this.key;if(o in s||(s[o]={}),a in s[o]||(s[o][a]=[]),s[o][a].some(t=>t===e))return a;s[o][a].push(e);const c=this._processStrategy(e,t,r);return Object.keys(this.schema).forEach(e=>{if(Object.hasOwnProperty.call(c,e)&&"object"==typeof c[e]){const t=this.schema[e];c[e]=i(c[e],c,e,t,n,s)}}),n(this,c,e,t,r),a}denormalize(e,t){if(isImmutable(e))return denormalizeImmutable(this.schema,e,t);let r=!0;return Object.keys(this.schema).forEach(i=>{const n=this.schema[i],[s,a]=t(e[i],n);a||(r=!1),Object.hasOwnProperty.call(e,i)&&(e[i]=s)}),[e,r]}}class PolymorphicSchema{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,r){return!this.isSingleSchema&&this._schemaAttribute(e,t,r)}inferSchema(e,t,r){if(this.isSingleSchema)return this.schema;const i=this.getSchemaAttribute(e,t,r);return this.schema[i]}normalizeValue(e,t,r,i,n,s){const a=this.inferSchema(e,t,r);if(!a)return e;const o=i(e,t,r,a,n,s);return this.isSingleSchema||null==o?o:{id:o,schema:this.getSchemaAttribute(e,t,r)}}denormalizeValue(e,t){const r=isImmutable(e)?e.get("schema"):e.schema;return this.isSingleSchema||r?t((isImmutable(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[r]):[e,!0]}}class UnionSchema extends PolymorphicSchema{constructor(e,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');super(e,t)}normalize(e,t,r,i,n,s){return this.normalizeValue(e,t,r,i,n,s)}denormalize(e,t){return this.denormalizeValue(e,t)}}class ValuesSchema extends PolymorphicSchema{normalize(e,t,r,i,n,s){return Object.keys(e).reduce((t,r,a)=>{const o=e[r];return null!=o?Object.assign({},t,{[r]:this.normalizeValue(o,e,r,i,n,s)}):t},{})}denormalize(e,t){let r=!0;return[Object.keys(e).reduce((i,n)=>{const s=e[n],[a,o]=this.denormalizeValue(s,t);return o||(r=!1),Object.assign({},i,{[n]:a})},{}),r]}}const validateSchema=e=>{if(Array.isArray(e)&&e.length>1)throw new Error("Expected schema definition to be a single schema, but found "+e.length+".");return e[0]},getValues=e=>Array.isArray(e)?e:Object.keys(e).map(t=>e[t]),normalize=(e,t,r,i,n,s,a)=>{return e=validateSchema(e),getValues(t).map((t,o)=>n(t,r,i,e,s,a))},denormalize=(e,t,r)=>{e=validateSchema(e);let i=!0;return void 0===t&&e&&([,i]=r(void 0,e)),[t&&t.map?t.map(t=>r(t,e)).filter(([,e])=>e).map(([e])=>e):t,i]};class ArraySchema extends PolymorphicSchema{normalize(e,t,r,i,n,s){return getValues(e).map((e,a)=>this.normalizeValue(e,t,r,i,n,s)).filter(e=>null!=e)}denormalize(e,t){let r=!0;return void 0===e&&this.schema&&([,r]=t(void 0,this.schema)),[e&&e.map?e.map(e=>this.denormalizeValue(e,t)).filter(([,e])=>e).map(([e])=>e):e,r]}}const normalize$1=(e,t,r,i,n,s,a)=>{const o=Object.assign({},t);return Object.keys(e).forEach(r=>{const i=e[r],c=n(t[r],t,r,i,s,a);null==c?delete o[r]:o[r]=c}),o},denormalize$1=(e,t,r)=>{if(isImmutable(t))return denormalizeImmutable(e,t,r);const i=Object.assign({},t);let n=!0;return Object.keys(e).forEach(t=>{const[s,a]=r(i[t],e[t]);null!=i[t]&&(i[t]=s),a||(n=!1)}),[i,n]};class ObjectSchema{constructor(e){this.define(e)}define(e){this.schema=Object.keys(e).reduce((t,r)=>{const i=e[r];return Object.assign({},t,{[r]:i})},this.schema||{})}normalize(...e){return normalize$1(this.schema,...e)}denormalize(...e){return denormalize$1(this.schema,...e)}}const visit=(e,t,r,i,n,s)=>{if("object"!=typeof e||!e)return e;if("object"==typeof i&&(!i.normalize||"function"!=typeof i.normalize)){return(Array.isArray(i)?normalize:normalize$1)(i,e,t,r,visit,n,s)}return i.normalize(e,t,r,visit,n,s)},addEntities=e=>(t,r,i,n,s)=>{const a=t.key,o=t.getId(i,n,s);a in e||(e[a]={});const c=e[a][o];e[a][o]=c?t.merge(c,r):r},schema={Array:ArraySchema,Entity:EntitySchema,Object:ObjectSchema,Union:UnionSchema,Values:ValuesSchema},normalize$2=(e,t)=>{if(null===e||typeof e!=typeof t)throw new Error('Unexpected input given to normalize. Expected type to be "'+(null===t?"null":typeof t)+'", found "'+(null===e?"null":typeof e)+'".');const r={},i=addEntities(r);return{entities:r,result:visit(e,e,null,t,i,{})}},unvisitEntity=(e,t,r,i,n)=>{const s=i(e,t);if("object"!=typeof s||null===s)return[s,!1];n[t.key]||(n[t.key]={});let a=!0;if(!n[t.key][e]){const i=isImmutable(s)?s:Object.assign({},s);n[t.key][e]=i,[n[t.key][e],a]=t.denormalize(i,r)}return[n[t.key][e],a]},getUnvisit=e=>{const t={},r=getEntities(e);return function e(i,n){if("object"==typeof n&&(!n.denormalize||"function"!=typeof n.denormalize)){return(Array.isArray(n)?denormalize:denormalize$1)(n,i,e)}return null===i?[i,!0]:n instanceof EntitySchema?void 0===i?[i,!1]:unvisitEntity(i,n,e,r,t):"function"==typeof n.denormalize?n.denormalize(i,e):[i,!0]}},getEntities=e=>{const t=isImmutable(e);return(r,i)=>{const n=i.key;return"object"==typeof r?r:t?e.getIn([n,r.toString()]):e[n]&&e[n][r]}},denormalize$2=(e,t,r)=>void 0!==e?getUnvisit(r)(e,t):[void 0,!1];exports.denormalize=denormalize$2,exports.normalize=normalize$2,exports.schema=schema; | ||
"use strict";function isImmutable(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(Object.hasOwnProperty.call(e,"__ownerID")||e._map&&Object.hasOwnProperty.call(e._map,"__ownerID")))}function denormalizeImmutable(e,t,r){let i=!0;return[Object.keys(e).reduce((t,n)=>{const s=""+n,[a,o]=r(t.get(s),e[s]);return o||(i=!1),t.has(s)?t.set(s,a):t},t),i]}Object.defineProperty(exports,"__esModule",{value:!0});const getDefaultGetId=e=>t=>isImmutable(t)?t.get(e):t[e];class EntitySchema{constructor(e,t={},r={}){if(!e||"string"!=typeof e)throw new Error("Expected a string key for Entity, but found "+e+".");const{idAttribute:i="id",mergeStrategy:n=((e,t)=>Object.assign({},e,{},t)),processStrategy:s=(e=>Object.assign({},e))}=r;this._key=e,this._getId="function"==typeof i?i:getDefaultGetId(i),this._idAttribute=i,this._mergeStrategy=n,this._processStrategy=s,this.define(t)}get key(){return this._key}get idAttribute(){return this._idAttribute}define(e){this.schema=Object.keys(e).reduce((t,r)=>{const i=e[r];return Object.assign({},t,{[r]:i})},this.schema||{})}getId(e,t,r){return this._getId(e,t,r)}merge(e,t){return this._mergeStrategy(e,t)}normalize(e,t,r,i,n,s){const a=this.getId(e,t,r),o=this.key;if(o in s||(s[o]={}),a in s[o]||(s[o][a]=[]),s[o][a].some(t=>t===e))return a;s[o][a].push(e);const c=this._processStrategy(e,t,r);return Object.keys(this.schema).forEach(e=>{if(Object.hasOwnProperty.call(c,e)&&"object"==typeof c[e]){const t=this.schema[e];c[e]=i(c[e],c,e,t,n,s)}}),n(this,c,e,t,r),a}denormalize(e,t){if(isImmutable(e))return denormalizeImmutable(this.schema,e,t);let r=!0;return Object.keys(this.schema).forEach(i=>{const n=this.schema[i],[s,a]=t(e[i],n);a||(r=!1),Object.hasOwnProperty.call(e,i)&&(e[i]=s)}),[e,r]}}class PolymorphicSchema{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,r){return!this.isSingleSchema&&this._schemaAttribute(e,t,r)}inferSchema(e,t,r){if(this.isSingleSchema)return this.schema;const i=this.getSchemaAttribute(e,t,r);return this.schema[i]}normalizeValue(e,t,r,i,n,s){const a=this.inferSchema(e,t,r);if(!a)return e;const o=i(e,t,r,a,n,s);return this.isSingleSchema||null==o?o:{id:o,schema:this.getSchemaAttribute(e,t,r)}}denormalizeValue(e,t){const r=isImmutable(e)?e.get("schema"):e.schema;return this.isSingleSchema||r?t((isImmutable(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[r]):[e,!0]}}class UnionSchema extends PolymorphicSchema{constructor(e,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');super(e,t)}normalize(e,t,r,i,n,s){return this.normalizeValue(e,t,r,i,n,s)}denormalize(e,t){return this.denormalizeValue(e,t)}}class ValuesSchema extends PolymorphicSchema{normalize(e,t,r,i,n,s){return Object.keys(e).reduce((t,r,a)=>{const o=e[r];return null!=o?Object.assign({},t,{[r]:this.normalizeValue(o,e,r,i,n,s)}):t},{})}denormalize(e,t){let r=!0;return[Object.keys(e).reduce((i,n)=>{const s=e[n],[a,o]=this.denormalizeValue(s,t);return o||(r=!1),Object.assign({},i,{[n]:a})},{}),r]}}const validateSchema=e=>{if(Array.isArray(e)&&e.length>1)throw new Error("Expected schema definition to be a single schema, but found "+e.length+".");return e[0]},getValues=e=>Array.isArray(e)?e:Object.keys(e).map(t=>e[t]),normalize=(e,t,r,i,n,s,a)=>{return e=validateSchema(e),getValues(t).map((t,o)=>n(t,r,i,e,s,a))},denormalize=(e,t,r)=>{e=validateSchema(e);let i=!0;return void 0===t&&e&&([,i]=r(void 0,e)),[t&&t.map?t.map(t=>r(t,e)).filter(([,e])=>e).map(([e])=>e):t,i]};class ArraySchema extends PolymorphicSchema{normalize(e,t,r,i,n,s){return getValues(e).map((e,a)=>this.normalizeValue(e,t,r,i,n,s)).filter(e=>null!=e)}denormalize(e,t){let r=!0;return void 0===e&&this.schema&&([,r]=t(void 0,this.schema)),[e&&e.map?e.map(e=>this.denormalizeValue(e,t)).filter(([,e])=>e).map(([e])=>e):e,r]}}const normalize$1=(e,t,r,i,n,s,a)=>{const o=Object.assign({},t);return Object.keys(e).forEach(r=>{const i=e[r],c=n(t[r],t,r,i,s,a);null==c?delete o[r]:o[r]=c}),o},denormalize$1=(e,t,r)=>{if(isImmutable(t))return denormalizeImmutable(e,t,r);const i=Object.assign({},t);let n=!0;return Object.keys(e).forEach(t=>{const[s,a]=r(i[t],e[t]);null!=i[t]&&(i[t]=s),a||(n=!1)}),[i,n]};class ObjectSchema{constructor(e){this.define(e)}define(e){this.schema=Object.keys(e).reduce((t,r)=>{const i=e[r];return Object.assign({},t,{[r]:i})},this.schema||{})}normalize(...e){return normalize$1(this.schema,...e)}denormalize(...e){return denormalize$1(this.schema,...e)}}const visit=(e,t,r,i,n,s)=>{if("object"!=typeof e||!e)return e;if("object"==typeof i&&(!i.normalize||"function"!=typeof i.normalize)){return(Array.isArray(i)?normalize:normalize$1)(i,e,t,r,visit,n,s)}return i.normalize(e,t,r,visit,n,s)},addEntities=e=>(t,r,i,n,s)=>{const a=t.key,o=t.getId(i,n,s);a in e||(e[a]={});const c=e[a][o];e[a][o]=c?t.merge(c,r):r},schema={Array:ArraySchema,Entity:EntitySchema,Object:ObjectSchema,Union:UnionSchema,Values:ValuesSchema},normalize$2=(e,t)=>{if(null===e||typeof e!=typeof t)throw new Error('Unexpected input given to normalize. Expected type to be "'+typeof t+'", found "'+(null===e?"null":typeof e)+'".');const r={},i=addEntities(r);return{entities:r,result:visit(e,e,null,t,i,{})}},unvisitEntity=(e,t,r,i,n)=>{const s=i(e,t);if("object"!=typeof s||null===s)return[s,!1];n[t.key]||(n[t.key]={});let a=!0;if(!n[t.key][e]){const i=isImmutable(s)?s:Object.assign({},s);n[t.key][e]=i,[n[t.key][e],a]=t.denormalize(i,r)}return[n[t.key][e],a]},getUnvisit=e=>{const t={},r=getEntities(e);return function e(i,n){if("object"==typeof n&&(!n.denormalize||"function"!=typeof n.denormalize)){return(Array.isArray(n)?denormalize:denormalize$1)(n,i,e)}return null===i?[i,!0]:n instanceof EntitySchema?void 0===i?[i,!1]:unvisitEntity(i,n,e,r,t):"function"==typeof n.denormalize?n.denormalize(i,e):[i,!0]}},getEntities=e=>{const t=isImmutable(e);return(r,i)=>{const n=i.key;return"object"==typeof r?r:t?e.getIn([n,r.toString()]):e[n]&&e[n][r]}},denormalize$2=(e,t,r)=>void 0!==e?getUnvisit(r)(e,t):[void 0,!1];exports.denormalize=denormalize$2,exports.normalize=normalize$2,exports.schema=schema; |
@@ -562,3 +562,3 @@ (function (global, factory) { | ||
if (input === null || typeof input !== typeof schema) { | ||
throw new Error("Unexpected input given to normalize. Expected type to be \"" + (schema === null ? 'null' : typeof schema) + "\", found \"" + (input === null ? 'null' : typeof input) + "\"."); | ||
throw new Error("Unexpected input given to normalize. Expected type to be \"" + typeof schema + "\", found \"" + (input === null ? 'null' : typeof input) + "\"."); | ||
} | ||
@@ -565,0 +565,0 @@ |
@@ -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 r(e,t,r){let n=!0;return[Object.keys(e).reduce((t,s)=>{const i=""+s,[o,c]=r(t.get(i),e[i]);return c||(n=!1),t.has(i)?t.set(i,o):t},t),n]}const n=e=>r=>t(r)?r.get(e):r[e];class s{constructor(e,t={},r={}){if(!e||"string"!=typeof e)throw new Error("Expected a string key for Entity, but found "+e+".");const{idAttribute:s="id",mergeStrategy:i=((e,t)=>Object.assign({},e,{},t)),processStrategy:o=(e=>Object.assign({},e))}=r;this._key=e,this._getId="function"==typeof s?s:n(s),this._idAttribute=s,this._mergeStrategy=i,this._processStrategy=o,this.define(t)}get key(){return this._key}get idAttribute(){return this._idAttribute}define(e){this.schema=Object.keys(e).reduce((t,r)=>{const n=e[r];return Object.assign({},t,{[r]:n})},this.schema||{})}getId(e,t,r){return this._getId(e,t,r)}merge(e,t){return this._mergeStrategy(e,t)}normalize(e,t,r,n,s,i){const o=this.getId(e,t,r),c=this.key;if(c in i||(i[c]={}),o in i[c]||(i[c][o]=[]),i[c][o].some(t=>t===e))return o;i[c][o].push(e);const a=this._processStrategy(e,t,r);return Object.keys(this.schema).forEach(e=>{if(Object.hasOwnProperty.call(a,e)&&"object"==typeof a[e]){const t=this.schema[e];a[e]=n(a[e],a,e,t,s,i)}}),s(this,a,e,t,r),o}denormalize(e,n){if(t(e))return r(this.schema,e,n);let s=!0;return Object.keys(this.schema).forEach(t=>{const r=this.schema[t],[i,o]=n(e[t],r);o||(s=!1),Object.hasOwnProperty.call(e,t)&&(e[t]=i)}),[e,s]}}class i{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,r){return!this.isSingleSchema&&this._schemaAttribute(e,t,r)}inferSchema(e,t,r){if(this.isSingleSchema)return this.schema;const n=this.getSchemaAttribute(e,t,r);return this.schema[n]}normalizeValue(e,t,r,n,s,i){const o=this.inferSchema(e,t,r);if(!o)return e;const c=n(e,t,r,o,s,i);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,r)}}denormalizeValue(e,r){const n=t(e)?e.get("schema"):e.schema;return this.isSingleSchema||n?r((t(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[n]):[e,!0]}}const o=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]},c=e=>Array.isArray(e)?e:Object.keys(e).map(t=>e[t]),a=(e,t,r,n,s,i,a)=>{return e=o(e),c(t).map((t,o)=>s(t,r,n,e,i,a))},u=(e,t,r)=>{e=o(e);let n=!0;return void 0===t&&e&&([,n]=r(void 0,e)),[t&&t.map?t.map(t=>r(t,e)).filter(([,e])=>e).map(([e])=>e):t,n]};const h=(e,t,r,n,s,i,o)=>{const c=Object.assign({},t);return Object.keys(e).forEach(r=>{const n=e[r],a=s(t[r],t,r,n,i,o);null==a?delete c[r]:c[r]=a}),c},l=(e,n,s)=>{if(t(n))return r(e,n,s);const i=Object.assign({},n);let o=!0;return Object.keys(e).forEach(t=>{const[r,n]=s(i[t],e[t]);null!=i[t]&&(i[t]=r),n||(o=!1)}),[i,o]};const m=(e,t,r,n,s,i)=>{if("object"!=typeof e||!e)return e;if("object"==typeof n&&(!n.normalize||"function"!=typeof n.normalize)){return(Array.isArray(n)?a:h)(n,e,t,r,m,s,i)}return n.normalize(e,t,r,m,s,i)},f={Array:class extends i{normalize(e,t,r,n,s,i){return c(e).map((e,o)=>this.normalizeValue(e,t,r,n,s,i)).filter(e=>null!=e)}denormalize(e,t){let r=!0;return void 0===e&&this.schema&&([,r]=t(void 0,this.schema)),[e&&e.map?e.map(e=>this.denormalizeValue(e,t)).filter(([,e])=>e).map(([e])=>e):e,r]}},Entity:s,Object:class{constructor(e){this.define(e)}define(e){this.schema=Object.keys(e).reduce((t,r)=>{const n=e[r];return Object.assign({},t,{[r]:n})},this.schema||{})}normalize(...e){return h(this.schema,...e)}denormalize(...e){return l(this.schema,...e)}},Union:class extends i{constructor(e,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');super(e,t)}normalize(e,t,r,n,s,i){return this.normalizeValue(e,t,r,n,s,i)}denormalize(e,t){return this.denormalizeValue(e,t)}},Values:class extends i{normalize(e,t,r,n,s,i){return Object.keys(e).reduce((t,r,o)=>{const c=e[r];return null!=c?Object.assign({},t,{[r]:this.normalizeValue(c,e,r,n,s,i)}):t},{})}denormalize(e,t){let r=!0;return[Object.keys(e).reduce((n,s)=>{const i=e[s],[o,c]=this.denormalizeValue(i,t);return c||(r=!1),Object.assign({},n,{[s]:o})},{}),r]}}},d=e=>{const r={},n=y(e);return function e(i,o){if("object"==typeof o&&(!o.denormalize||"function"!=typeof o.denormalize)){return(Array.isArray(o)?u:l)(o,i,e)}return null===i?[i,!0]:o instanceof s?void 0===i?[i,!1]:((e,r,n,s,i)=>{const o=s(e,r);if("object"!=typeof o||null===o)return[o,!1];i[r.key]||(i[r.key]={});let c=!0;if(!i[r.key][e]){const s=t(o)?o:Object.assign({},o);i[r.key][e]=s,[i[r.key][e],c]=r.denormalize(s,n)}return[i[r.key][e],c]})(i,o,e,n,r):"function"==typeof o.denormalize?o.denormalize(i,e):[i,!0]}},y=e=>{const r=t(e);return(t,n)=>{const s=n.key;return"object"==typeof t?t:r?e.getIn([s,t.toString()]):e[s]&&e[s][t]}};e.denormalize=(e,t,r)=>void 0!==e?d(r)(e,t):[void 0,!1],e.normalize=(e,t)=>{if(null===e||typeof e!=typeof t)throw new Error('Unexpected input given to normalize. Expected type to be "'+(null===t?"null":typeof t)+'", found "'+(null===e?"null":typeof e)+'".');const r={},n=(e=>(t,r,n,s,i)=>{const o=t.key,c=t.getId(n,s,i);o in e||(e[o]={});const a=e[o][c];e[o][c]=a?t.merge(a,r):r})(r);return{entities:r,result:m(e,e,null,t,n,{})}},e.schema=f,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 r(e,t,r){let n=!0;return[Object.keys(e).reduce((t,s)=>{const i=""+s,[o,c]=r(t.get(i),e[i]);return c||(n=!1),t.has(i)?t.set(i,o):t},t),n]}const n=e=>r=>t(r)?r.get(e):r[e];class s{constructor(e,t={},r={}){if(!e||"string"!=typeof e)throw new Error("Expected a string key for Entity, but found "+e+".");const{idAttribute:s="id",mergeStrategy:i=((e,t)=>Object.assign({},e,{},t)),processStrategy:o=(e=>Object.assign({},e))}=r;this._key=e,this._getId="function"==typeof s?s:n(s),this._idAttribute=s,this._mergeStrategy=i,this._processStrategy=o,this.define(t)}get key(){return this._key}get idAttribute(){return this._idAttribute}define(e){this.schema=Object.keys(e).reduce((t,r)=>{const n=e[r];return Object.assign({},t,{[r]:n})},this.schema||{})}getId(e,t,r){return this._getId(e,t,r)}merge(e,t){return this._mergeStrategy(e,t)}normalize(e,t,r,n,s,i){const o=this.getId(e,t,r),c=this.key;if(c in i||(i[c]={}),o in i[c]||(i[c][o]=[]),i[c][o].some(t=>t===e))return o;i[c][o].push(e);const a=this._processStrategy(e,t,r);return Object.keys(this.schema).forEach(e=>{if(Object.hasOwnProperty.call(a,e)&&"object"==typeof a[e]){const t=this.schema[e];a[e]=n(a[e],a,e,t,s,i)}}),s(this,a,e,t,r),o}denormalize(e,n){if(t(e))return r(this.schema,e,n);let s=!0;return Object.keys(this.schema).forEach(t=>{const r=this.schema[t],[i,o]=n(e[t],r);o||(s=!1),Object.hasOwnProperty.call(e,t)&&(e[t]=i)}),[e,s]}}class i{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,r){return!this.isSingleSchema&&this._schemaAttribute(e,t,r)}inferSchema(e,t,r){if(this.isSingleSchema)return this.schema;const n=this.getSchemaAttribute(e,t,r);return this.schema[n]}normalizeValue(e,t,r,n,s,i){const o=this.inferSchema(e,t,r);if(!o)return e;const c=n(e,t,r,o,s,i);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,r)}}denormalizeValue(e,r){const n=t(e)?e.get("schema"):e.schema;return this.isSingleSchema||n?r((t(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[n]):[e,!0]}}const o=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]},c=e=>Array.isArray(e)?e:Object.keys(e).map(t=>e[t]),a=(e,t,r,n,s,i,a)=>{return e=o(e),c(t).map((t,o)=>s(t,r,n,e,i,a))},u=(e,t,r)=>{e=o(e);let n=!0;return void 0===t&&e&&([,n]=r(void 0,e)),[t&&t.map?t.map(t=>r(t,e)).filter(([,e])=>e).map(([e])=>e):t,n]};const h=(e,t,r,n,s,i,o)=>{const c=Object.assign({},t);return Object.keys(e).forEach(r=>{const n=e[r],a=s(t[r],t,r,n,i,o);null==a?delete c[r]:c[r]=a}),c},l=(e,n,s)=>{if(t(n))return r(e,n,s);const i=Object.assign({},n);let o=!0;return Object.keys(e).forEach(t=>{const[r,n]=s(i[t],e[t]);null!=i[t]&&(i[t]=r),n||(o=!1)}),[i,o]};const m=(e,t,r,n,s,i)=>{if("object"!=typeof e||!e)return e;if("object"==typeof n&&(!n.normalize||"function"!=typeof n.normalize)){return(Array.isArray(n)?a:h)(n,e,t,r,m,s,i)}return n.normalize(e,t,r,m,s,i)},f={Array:class extends i{normalize(e,t,r,n,s,i){return c(e).map((e,o)=>this.normalizeValue(e,t,r,n,s,i)).filter(e=>null!=e)}denormalize(e,t){let r=!0;return void 0===e&&this.schema&&([,r]=t(void 0,this.schema)),[e&&e.map?e.map(e=>this.denormalizeValue(e,t)).filter(([,e])=>e).map(([e])=>e):e,r]}},Entity:s,Object:class{constructor(e){this.define(e)}define(e){this.schema=Object.keys(e).reduce((t,r)=>{const n=e[r];return Object.assign({},t,{[r]:n})},this.schema||{})}normalize(...e){return h(this.schema,...e)}denormalize(...e){return l(this.schema,...e)}},Union:class extends i{constructor(e,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');super(e,t)}normalize(e,t,r,n,s,i){return this.normalizeValue(e,t,r,n,s,i)}denormalize(e,t){return this.denormalizeValue(e,t)}},Values:class extends i{normalize(e,t,r,n,s,i){return Object.keys(e).reduce((t,r,o)=>{const c=e[r];return null!=c?Object.assign({},t,{[r]:this.normalizeValue(c,e,r,n,s,i)}):t},{})}denormalize(e,t){let r=!0;return[Object.keys(e).reduce((n,s)=>{const i=e[s],[o,c]=this.denormalizeValue(i,t);return c||(r=!1),Object.assign({},n,{[s]:o})},{}),r]}}},d=e=>{const r={},n=y(e);return function e(i,o){if("object"==typeof o&&(!o.denormalize||"function"!=typeof o.denormalize)){return(Array.isArray(o)?u:l)(o,i,e)}return null===i?[i,!0]:o instanceof s?void 0===i?[i,!1]:((e,r,n,s,i)=>{const o=s(e,r);if("object"!=typeof o||null===o)return[o,!1];i[r.key]||(i[r.key]={});let c=!0;if(!i[r.key][e]){const s=t(o)?o:Object.assign({},o);i[r.key][e]=s,[i[r.key][e],c]=r.denormalize(s,n)}return[i[r.key][e],c]})(i,o,e,n,r):"function"==typeof o.denormalize?o.denormalize(i,e):[i,!0]}},y=e=>{const r=t(e);return(t,n)=>{const s=n.key;return"object"==typeof t?t:r?e.getIn([s,t.toString()]):e[s]&&e[s][t]}};e.denormalize=(e,t,r)=>void 0!==e?d(r)(e,t):[void 0,!1],e.normalize=(e,t)=>{if(null===e||typeof e!=typeof t)throw new Error('Unexpected input given to normalize. Expected type to be "'+typeof t+'", found "'+(null===e?"null":typeof e)+'".');const r={},n=(e=>(t,r,n,s,i)=>{const o=t.key,c=t.getId(n,s,i);o in e||(e[o]={});const a=e[o][c];e[o][c]=a?t.merge(a,r):r})(r);return{entities:r,result:m(e,e,null,t,n,{})}},e.schema=f,Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "@rest-hooks/normalizr", | ||
"version": "4.1.0", | ||
"version": "4.1.1", | ||
"description": "Normalizes and denormalizes JSON according to schema for Redux and Flux applications", | ||
@@ -63,3 +63,3 @@ "homepage": "https://github.com/coinbase/rest-hooks/tree/master/packages/normalizr#readme", | ||
}, | ||
"gitHead": "7b86389ec9b44d8e2b8248c80616cd95fe6e90d8" | ||
"gitHead": "a2f1cfb07b755bb4bc1528a79e70363fca9bb237" | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
145596
0
3033