New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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-j.0 to 6.0.0-j.1

lib/denormalize.d.ts

8

CHANGELOG.md

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

## 6.0.0-j.1 (2020-07-31)
* enhance: Normalizr ES build should be split into modules for code splitting (#381) ([c543a31](https://github.com/coinbase/rest-hooks/commit/c543a31)), closes [#381](https://github.com/coinbase/rest-hooks/issues/381)
## 6.0.0-j.0 (2020-07-27)

@@ -8,0 +16,0 @@

2

dist/normalizr.umd.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory(global.rest_hooks_normalizr = {}));
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.rest_hooks_normalizr = {}));
}(this, (function (exports) { 'use strict';

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

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

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).rest_hooks_normalizr={})}(this,(function(e){"use strict";function n(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(Object.hasOwnProperty.call(e,"__ownerID")||e._map&&Object.hasOwnProperty.call(e._map,"__ownerID")))}function t(e,n,t){var r=!0,i=!1;return[Object.keys(e).reduce((function(n,o){var a=""+o,u=t(n.get(a),e[a]),s=u[0],c=u[1],f=u[2];return c||(r=!1),f&&(i=!0),n.has(a)?n.set(a,s):n}),n),r,i]}function r(e,n){e.prototype=Object.create(n.prototype),e.prototype.constructor=e,e.__proto__=n}function i(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function o(e,n,t){return n&&i(e.prototype,n),t&&i(e,t),e}var a=function(){function e(e,n){n&&(this._schemaAttribute="string"==typeof n?function(e){return e[n]}:n),this.define(e)}var t=e.prototype;return t.define=function(e){this.schema=e},t.getSchemaAttribute=function(e,n,t){return!this.isSingleSchema&&this._schemaAttribute(e,n,t)},t.inferSchema=function(e,n,t){if(this.isSingleSchema)return this.schema;var r=this.getSchemaAttribute(e,n,t);return this.schema[r]},t.normalizeValue=function(e,n,t,r,i,o){var a=this.inferSchema(e,n,t);if(!a)return e;var u=r(e,n,t,a,i,o);return this.isSingleSchema||null==u?u:{id:u,schema:this.getSchemaAttribute(e,n,t)}},t.denormalizeValue=function(e,t){var r=n(e)?e.get("schema"):e.schema;return this.isSingleSchema||r?t((this.isSingleSchema?void 0:n(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[r]):[e,!0,!0]},o(e,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),e}(),u=Symbol("ENTITY WAS DELETED"),s=function(e){if(Array.isArray(e)&&e.length>1)throw new Error("Expected schema definition to be a single schema, but found "+e.length+".");return e[0]},c=function(e){return Array.isArray(e)?e:Object.keys(e).map((function(n){return e[n]}))},f=function(e){var n=e[1],t=e[2];return n&&!t},h=function(e,n,t,r,i,o,a){return e=s(e),c(n).map((function(n,u){return i(n,t,r,e,o,a)}))},l=function(e,n,t){e=s(e);var r=!1,i=!0;if(void 0===n&&e){var o=t(void 0,e);i=o[1],r=o[2]}return[n&&n.map?n.map((function(n){return t(n,e)})).filter(f).map((function(e){return e[0]})):n,i,r]},m=function(e){function n(){return e.apply(this,arguments)||this}r(n,e);var t=n.prototype;return t.normalize=function(e,n,t,r,i,o){var a=this;return c(e).map((function(e,u){return a.normalizeValue(e,n,t,r,i,o)})).filter((function(e){return null!=e}))},t.denormalize=function(e,n){var t=this,r=!1,i=!0;if(void 0===e&&this.schema){var o=n(void 0,this.schema);i=o[1],r=o[2]}return[e&&e.map?e.map((function(e){return t.denormalizeValue(e,n)})).filter(f).map((function(e){return e[0]})):e,i,r]},n}(a),p=function(e,n,t,r,i,o,a){var u=Object.assign({},n);return Object.keys(e).forEach((function(t){var r=e[t],s=i(n[t],n,t,r,o,a);null==s?delete u[t]:u[t]=s})),u},d=function(e,r,i){if(n(r))return t(e,r,i);var o=Object.assign({},r),a=!0,u=!1;return Object.keys(e).forEach((function(n){var t=i(o[n],e[n]),r=t[0],s=t[1],c=t[2];void 0!==o[n]&&(o[n]=r),c&&(u=!0),s||(a=!1)})),[o,a,u]},y=function(){function e(e){this.define(e)}var n=e.prototype;return n.define=function(e){this.schema=Object.keys(e).reduce((function(n,t){var r,i=e[t];return Object.assign({},n,((r={})[t]=i,r))}),this.schema||{})},n.normalize=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return p.apply(void 0,[this.schema].concat(n))},n.denormalize=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return d.apply(void 0,[this.schema].concat(n))},e}();function v(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function b(e,n){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=function(e,n){if(e){if("string"==typeof e)return v(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?v(e,n):void 0}}(e))||n&&e&&"number"==typeof e.length){t&&(e=t);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=e[Symbol.iterator]()).next.bind(t)}var g=Symbol("Defined Members"),O=Symbol("unq"),S=function(){function e(){}return e.prototype.toString=function(){return this[O]},e.toJSON=function(){return{name:this.name,schema:this.schema}},e.fromJS=function(n,t,r){void 0===n&&(n={});var i=new this(n);return n instanceof e&&(n=n.constructor.toObjectDefined(n)),Object.assign(i,n),Object.defineProperty(i,g,{value:Object.keys(n),writable:!1}),Object.defineProperty(i,O,{value:""+Math.random(),writable:!1}),i},e.merge=function(e,n){var t=Object.assign(this.toObjectDefined(e),this.toObjectDefined(n));return this.fromJS(t)},e.hasDefined=function(e,n){return e[g].includes(n)},e.toObjectDefined=function(e){for(var n,t={},r=b(e[g]);!(n=r()).done;){var i=n.value;t[i]=e[i]}return t},e.keysDefined=function(e){return e[g]},e.normalize=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return p.apply(void 0,[this.schema].concat(n))},e.denormalize=function(e,n){var t=this,r=new this,i=Object.assign({},e),o=!1,a=!0;return Object.keys(this.schema).forEach((function(e){var u=n(i[e],t.schema[e]),s=u[0],c=u[1],f=u[2];void 0!==i[e]&&(i[e]=s),c||e in r&&!r[e]||(a=!1),!f||e in r&&!r[e]||(o=!0)})),[this.fromJS(i),a,o]},e.asSchema=function(){return"development"===process.env.NODE_ENV&&console.error("asSchema() is deprecated - use Entity directly instead."),this},e}();S.schema={};var E=function(e){function i(){return e.apply(this,arguments)||this}return r(i,e),i.toJSON=function(){return Object.assign({},e.toJSON.call(this),{key:this.key})},i.pk=function(e,n,t){return this.prototype.pk.call(e,n,t)||t},i.normalize=function(e,n,t,r,i,o){var a=this;if("string"==typeof e)return e;var u=this.fromJS(e,n,t);if("production"!==process.env.NODE_ENV){for(var s,c=new this,f=new Set(Object.keys(c)),h=this.keysDefined(u),l=[[],[],[]],m=l[0],p=l[1],d=l[2],y=b(h);!(s=y()).done;){var v=s.value;f.has(v)?m.push(v):d.push(v)}for(var g,O=b(f);!(g=O()).done;){var S=g.value;m.includes(S)||p.push(S)}if((Math.max(h.length/2,1)<=d.length&&f.size>Math.max(d.length,2)||m.length<Math.min(1,f.size/2))&&f.size){var E=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:\n Found: "+m+"\n Missing: "+p+"\n Unexpected keys: "+d+"\n Value: "+JSON.stringify(this.toObjectDefined(u),null,2));throw E.status=400,E}}var w=u.pk(n,t);if(void 0!==w&&""!==w){var k=this.key;return k in o||(o[k]={}),w in o[k]||(o[k][w]=[]),o[k][w].some((function(n){return n===e}))?w:(o[k][w].push(e),Object.keys(this.schema).forEach((function(e){if(Object.hasOwnProperty.call(u,e)){var n=a.schema[e];u[e]=r(u[e],u,e,n,i,o)}})),i(this,u,u,n,t),w)}if("production"!==process.env.NODE_ENV){var j=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 j.status=400,j}},i.denormalize=function(e,r){var i=this;if(n(e)){var o=t(this.schema,e,r),a=o[0],u=o[1],s=o[2];return[this.fromJS(a.toObject()),u,s]}var c=new this,f=!1,h=!0,l=e;return Object.keys(this.schema).forEach((function(n){var t=i.schema[n],o=i.hasDefined(e,n)?e[n]:void 0,a=r(o,t),u=a[0],s=a[1],m=a[2];s||n in c&&!c[n]||(h=!1),!m||n in c&&!c[n]||(f=!0),i.hasDefined(e,n)&&l[n]!==u&&(l[n]=u)})),[l,h,f]},o(i,null,[{key:"key",get:function(){if("production"!==process.env.NODE_ENV&&(""===this.name||"Entity"===this.name))throw new Error("Entity classes without a name must define `static get key()`");return this.name}}]),i}(S);function w(e){return null!==e&&void 0!==e.pk}"production"!==process.env.NODE_ENV&&(E.fromJS=function(e){if(void 0===this.prototype.pk)throw new Error("cannot construct on abstract types");return S.fromJS.call(this,e)});var k=function(e){function n(){return e.apply(this,arguments)||this}return r(n,e),n.denormalize=function(e,n){return[e,!0,!1]},n}(E),j=function(e){var t={},r=z(e);return[function e(i,o){if(!o)return[i,!0,!1];if(!o.denormalize||"function"!=typeof o.denormalize){if("function"==typeof o)return i instanceof o?[i,!0,!1]:[new o(i),!0,!1];if("object"==typeof o)return(Array.isArray(o)?l:d)(o,i,e)}return null===i?[i,!0,!1]:w(o)?void 0===i?[i,!1,!1]:function(e,t,r,i,o){var a=i(e,t);if(a===u)return[void 0,!0,!0];if("object"!=typeof a||null===a)return[a,!1,!1];o[t.key]||(o[t.key]={});var s=!0,c=!1;if(!o[t.key][e]){var f=n(a)||a instanceof k?a:t.fromJS(a);o[t.key][e]=f;var h=t.denormalize(f,r);o[t.key][e]=h[0],s=h[1],c=h[2]}return[o[t.key][e],s,c]}(i,o,e,r,t):"function"==typeof o.denormalize?o.denormalize(i,e):[i,!0,!1]},t]},z=function(e){var t=n(e);return function(n,r){var i=r.key;return"object"==typeof n?n:t?e.getIn([i,n]):e[i]&&e[i][n]}},_=function e(n,t,r,i,o,a){return n&&i&&["function","object"].includes(typeof i)?i.normalize&&"function"==typeof i.normalize?i.normalize(n,t,r,e,o,a):"function"==typeof i?new i(n):(Array.isArray(i)?h:p)(i,n,t,r,e,o,a):n};var N=function(e){function n(n,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return e.call(this,n,t)||this}r(n,e);var t=n.prototype;return t.normalize=function(e,n,t,r,i,o){return this.normalizeValue(e,n,t,r,i,o)},t.denormalize=function(e,n){return this.denormalizeValue(e,n)},n}(a),A=function(e){function n(){return e.apply(this,arguments)||this}r(n,e);var t=n.prototype;return t.normalize=function(e,n,t,r,i,o){var a=this;return Object.keys(e).reduce((function(n,t,u){var s,c=e[t];return null!=c?Object.assign({},n,((s={})[t]=a.normalizeValue(c,e,t,r,i,o),s)):n}),{})},t.denormalize=function(e,n){var t=this,r=!0,i=!1;return[Object.keys(e).reduce((function(o,a){var u,s=e[a],c=t.denormalizeValue(s,n),f=c[0],h=c[1],l=c[2];return h||(r=!1),l&&(i=!0),!h||l?o:Object.assign({},o,((u={})[a]=f,u))}),{}),r,i]},n}(a),D=function(){function e(e){if("production"!==process.env.NODE_ENV&&!e)throw new Error('Expected option "entity" not found on DeleteSchema.');this._entity=e}var n=e.prototype;return n.normalize=function(e,n,t,r,i,o){if("string"==typeof e)return e;var a=this._entity.fromJS(e,n,t),s=a.pk(n,t);return i(this._entity,u,a,n,t),s},n.denormalize=function(e,n){return n(e,this._entity)},n._denormalizeNullable=function(){return[]},n._normalizeNullable=function(){return[]},n.merge=function(e,n){return n},e}(),x=Object.freeze({__proto__:null,Union:N,Values:A,Array:m,Object:y,Delete:D});e.DELETED=u,e.Entity=E,e.FlatEntity=k,e.SimpleRecord=S,e.denormalize=function(e,n,t){if("production"!==process.env.NODE_ENV&&void 0===n)throw new Error("schema needed");if(void 0!==e){var r=j(t),i=r[0],o=r[1];return[].concat(i(e,n),[o])}return[void 0,!1,!1,{}]},e.isEntity=w,e.normalize=function(e,n){var t=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(n);if(null===e||typeof e!==t){if("production"!==process.env.NODE_ENV){throw"string"==typeof e&&function(e){try{return"string"!=typeof JSON.parse(e)}catch(e){return!1}}(e)?new Error('Normalizing a string, but this does match schema.\n\nParsing this input string as JSON worked. This likely indicates fetch function did not parse\nthe JSON. By default, this only happens if "content-type" header includes "json".\nSee https://resthooks.io/docs/guides/custom-networking for more information\n\n Schema: '+JSON.stringify(n,void 0,2)+'\n Input: "'+e+'"'):new Error('Unexpected input given to normalize. Expected type to be "'+t+'", found "'+(null===e?"null":typeof e)+'".\n\n Schema: '+JSON.stringify(n,void 0,2)+'\n Input: "'+e+'"')}throw new Error('Unexpected input given to normalize. Expected type to be "'+t+'", found "'+(null===e?"null":typeof e)+'".')}var r={},i={},o=function(e,n){return function(t,r,i,o,a){var u=t.key,s=t.pk(i,o,a);u in e||(e[u]={});var c=e[u][s];if(e[u][s]=c?t.merge(c,r):r,Array.isArray(t.indexes)){var f=e[u][s];u in n||(n[u]={});for(var h,l=b(t.indexes);!(h=l()).done;){var m=h.value;m in n[u]||(n[u][m]={});var p=n[u][m];c&&delete p[c[m]],m in f?p[f[m]]=s:"production"!==process.env.NODE_ENV&&console.warn("Index not found in entity. Indexes must be top-level members of your entity.\nIndex: "+m+"\nEntity: "+JSON.stringify(f,void 0,2))}}}}(r,i);return{entities:r,indexes:i,result:_(e,e,void 0,n,o,{})}},e.schema=x,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).rest_hooks_normalizr={})}(this,(function(e){"use strict";function n(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(Object.hasOwnProperty.call(e,"__ownerID")||e._map&&Object.hasOwnProperty.call(e._map,"__ownerID")))}function t(e,n,t){var r=!0,i=!1;return[Object.keys(e).reduce((function(n,o){var a=""+o,u=t(n.get(a),e[a]),s=u[0],c=u[1],f=u[2];return c||(r=!1),f&&(i=!0),n.has(a)?n.set(a,s):n}),n),r,i]}function r(e,n){e.prototype=Object.create(n.prototype),e.prototype.constructor=e,e.__proto__=n}function i(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function o(e,n,t){return n&&i(e.prototype,n),t&&i(e,t),e}var a=function(){function e(e,n){n&&(this._schemaAttribute="string"==typeof n?function(e){return e[n]}:n),this.define(e)}var t=e.prototype;return t.define=function(e){this.schema=e},t.getSchemaAttribute=function(e,n,t){return!this.isSingleSchema&&this._schemaAttribute(e,n,t)},t.inferSchema=function(e,n,t){if(this.isSingleSchema)return this.schema;var r=this.getSchemaAttribute(e,n,t);return this.schema[r]},t.normalizeValue=function(e,n,t,r,i,o){var a=this.inferSchema(e,n,t);if(!a)return e;var u=r(e,n,t,a,i,o);return this.isSingleSchema||null==u?u:{id:u,schema:this.getSchemaAttribute(e,n,t)}},t.denormalizeValue=function(e,t){var r=n(e)?e.get("schema"):e.schema;return this.isSingleSchema||r?t((this.isSingleSchema?void 0:n(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[r]):[e,!0,!0]},o(e,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),e}(),u=Symbol("ENTITY WAS DELETED"),s=function(e){if(Array.isArray(e)&&e.length>1)throw new Error("Expected schema definition to be a single schema, but found "+e.length+".");return e[0]},c=function(e){return Array.isArray(e)?e:Object.keys(e).map((function(n){return e[n]}))},f=function(e){var n=e[1],t=e[2];return n&&!t},l=function(e,n,t,r,i,o,a){return e=s(e),c(n).map((function(n,u){return i(n,t,r,e,o,a)}))},h=function(e,n,t){e=s(e);var r=!1,i=!0;if(void 0===n&&e){var o=t(void 0,e);i=o[1],r=o[2]}return[n&&n.map?n.map((function(n){return t(n,e)})).filter(f).map((function(e){return e[0]})):n,i,r]},m=function(e){function n(){return e.apply(this,arguments)||this}r(n,e);var t=n.prototype;return t.normalize=function(e,n,t,r,i,o){var a=this;return c(e).map((function(e,u){return a.normalizeValue(e,n,t,r,i,o)})).filter((function(e){return null!=e}))},t.denormalize=function(e,n){var t=this,r=!1,i=!0;if(void 0===e&&this.schema){var o=n(void 0,this.schema);i=o[1],r=o[2]}return[e&&e.map?e.map((function(e){return t.denormalizeValue(e,n)})).filter(f).map((function(e){return e[0]})):e,i,r]},n}(a),p=function(e,n,t,r,i,o,a){var u=Object.assign({},n);return Object.keys(e).forEach((function(t){var r=e[t],s=i(n[t],n,t,r,o,a);null==s?delete u[t]:u[t]=s})),u},d=function(e,r,i){if(n(r))return t(e,r,i);var o=Object.assign({},r),a=!0,u=!1;return Object.keys(e).forEach((function(n){var t=i(o[n],e[n]),r=t[0],s=t[1],c=t[2];void 0!==o[n]&&(o[n]=r),c&&(u=!0),s||(a=!1)})),[o,a,u]},y=function(){function e(e){this.define(e)}var n=e.prototype;return n.define=function(e){this.schema=Object.keys(e).reduce((function(n,t){var r,i=e[t];return Object.assign({},n,((r={})[t]=i,r))}),this.schema||{})},n.normalize=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return p.apply(void 0,[this.schema].concat(n))},n.denormalize=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return d.apply(void 0,[this.schema].concat(n))},e}();function v(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function b(e,n){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=function(e,n){if(e){if("string"==typeof e)return v(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?v(e,n):void 0}}(e))||n&&e&&"number"==typeof e.length){t&&(e=t);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=e[Symbol.iterator]()).next.bind(t)}var g=Symbol("Defined Members"),O=Symbol("unq"),S=function(){function e(){}return e.prototype.toString=function(){return this[O]},e.toJSON=function(){return{name:this.name,schema:this.schema}},e.fromJS=function(n,t,r){void 0===n&&(n={});var i=new this(n);return n instanceof e&&(n=n.constructor.toObjectDefined(n)),Object.assign(i,n),Object.defineProperty(i,g,{value:Object.keys(n),writable:!1}),Object.defineProperty(i,O,{value:""+Math.random(),writable:!1}),i},e.merge=function(e,n){var t=Object.assign(this.toObjectDefined(e),this.toObjectDefined(n));return this.fromJS(t)},e.hasDefined=function(e,n){return e[g].includes(n)},e.toObjectDefined=function(e){for(var n,t={},r=b(e[g]);!(n=r()).done;){var i=n.value;t[i]=e[i]}return t},e.keysDefined=function(e){return e[g]},e.normalize=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return p.apply(void 0,[this.schema].concat(n))},e.denormalize=function(e,n){var t=this,r=new this,i=Object.assign({},e),o=!1,a=!0;return Object.keys(this.schema).forEach((function(e){var u=n(i[e],t.schema[e]),s=u[0],c=u[1],f=u[2];void 0!==i[e]&&(i[e]=s),c||e in r&&!r[e]||(a=!1),!f||e in r&&!r[e]||(o=!0)})),[this.fromJS(i),a,o]},e.asSchema=function(){return"development"===process.env.NODE_ENV&&console.error("asSchema() is deprecated - use Entity directly instead."),this},e}();S.schema={};var E=function(e){function i(){return e.apply(this,arguments)||this}return r(i,e),i.toJSON=function(){return Object.assign({},e.toJSON.call(this),{key:this.key})},i.pk=function(e,n,t){return this.prototype.pk.call(e,n,t)||t},i.normalize=function(e,n,t,r,i,o){var a=this;if("string"==typeof e)return e;var u=this.fromJS(e,n,t);if("production"!==process.env.NODE_ENV){for(var s,c=new this,f=new Set(Object.keys(c)),l=this.keysDefined(u),h=[[],[],[]],m=h[0],p=h[1],d=h[2],y=b(l);!(s=y()).done;){var v=s.value;f.has(v)?m.push(v):d.push(v)}for(var g,O=b(f);!(g=O()).done;){var S=g.value;m.includes(S)||p.push(S)}if((Math.max(l.length/2,1)<=d.length&&f.size>Math.max(d.length,2)||m.length<Math.min(1,f.size/2))&&f.size){var E=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:\n Found: "+m+"\n Missing: "+p+"\n Unexpected keys: "+d+"\n Value: "+JSON.stringify(this.toObjectDefined(u),null,2));throw E.status=400,E}}var w=u.pk(n,t);if(void 0!==w&&""!==w){var k=this.key;return k in o||(o[k]={}),w in o[k]||(o[k][w]=[]),o[k][w].some((function(n){return n===e}))?w:(o[k][w].push(e),Object.keys(this.schema).forEach((function(e){if(Object.hasOwnProperty.call(u,e)){var n=a.schema[e];u[e]=r(u[e],u,e,n,i,o)}})),i(this,u,u,n,t),w)}if("production"!==process.env.NODE_ENV){var j=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 j.status=400,j}},i.denormalize=function(e,r){var i=this;if(n(e)){var o=t(this.schema,e,r),a=o[0],u=o[1],s=o[2];return[this.fromJS(a.toObject()),u,s]}var c=new this,f=!1,l=!0,h=e;return Object.keys(this.schema).forEach((function(n){var t=i.schema[n],o=i.hasDefined(e,n)?e[n]:void 0,a=r(o,t),u=a[0],s=a[1],m=a[2];s||n in c&&!c[n]||(l=!1),!m||n in c&&!c[n]||(f=!0),i.hasDefined(e,n)&&h[n]!==u&&(h[n]=u)})),[h,l,f]},o(i,null,[{key:"key",get:function(){if("production"!==process.env.NODE_ENV&&(""===this.name||"Entity"===this.name))throw new Error("Entity classes without a name must define `static get key()`");return this.name}}]),i}(S);function w(e){return null!==e&&void 0!==e.pk}"production"!==process.env.NODE_ENV&&(E.fromJS=function(e){if(void 0===this.prototype.pk)throw new Error("cannot construct on abstract types");return S.fromJS.call(this,e)});var k=function(e){function n(){return e.apply(this,arguments)||this}return r(n,e),n.denormalize=function(e,n){return[e,!0,!1]},n}(E),j=function(e){var t={},r=z(e);return[function e(i,o){if(!o)return[i,!0,!1];if(!o.denormalize||"function"!=typeof o.denormalize){if("function"==typeof o)return i instanceof o?[i,!0,!1]:[new o(i),!0,!1];if("object"==typeof o)return(Array.isArray(o)?h:d)(o,i,e)}return null===i?[i,!0,!1]:w(o)?void 0===i?[i,!1,!1]:function(e,t,r,i,o){var a=i(e,t);if(a===u)return[void 0,!0,!0];if("object"!=typeof a||null===a)return[a,!1,!1];o[t.key]||(o[t.key]={});var s=!0,c=!1;if(!o[t.key][e]){var f=n(a)||a instanceof k?a:t.fromJS(a);o[t.key][e]=f;var l=t.denormalize(f,r);o[t.key][e]=l[0],s=l[1],c=l[2]}return[o[t.key][e],s,c]}(i,o,e,r,t):"function"==typeof o.denormalize?o.denormalize(i,e):[i,!0,!1]},t]},z=function(e){var t=n(e);return function(n,r){var i=r.key;return"object"==typeof n?n:t?e.getIn([i,n]):e[i]&&e[i][n]}},_=function e(n,t,r,i,o,a){return n&&i&&["function","object"].includes(typeof i)?i.normalize&&"function"==typeof i.normalize?i.normalize(n,t,r,e,o,a):"function"==typeof i?new i(n):(Array.isArray(i)?l:p)(i,n,t,r,e,o,a):n};var N=function(e){function n(n,t){if(!t)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return e.call(this,n,t)||this}r(n,e);var t=n.prototype;return t.normalize=function(e,n,t,r,i,o){return this.normalizeValue(e,n,t,r,i,o)},t.denormalize=function(e,n){return this.denormalizeValue(e,n)},n}(a),A=function(e){function n(){return e.apply(this,arguments)||this}r(n,e);var t=n.prototype;return t.normalize=function(e,n,t,r,i,o){var a=this;return Object.keys(e).reduce((function(n,t,u){var s,c=e[t];return null!=c?Object.assign({},n,((s={})[t]=a.normalizeValue(c,e,t,r,i,o),s)):n}),{})},t.denormalize=function(e,n){var t=this,r=!0,i=!1;return[Object.keys(e).reduce((function(o,a){var u,s=e[a],c=t.denormalizeValue(s,n),f=c[0],l=c[1],h=c[2];return l||(r=!1),h&&(i=!0),!l||h?o:Object.assign({},o,((u={})[a]=f,u))}),{}),r,i]},n}(a),D=function(){function e(e){if("production"!==process.env.NODE_ENV&&!e)throw new Error('Expected option "entity" not found on DeleteSchema.');this._entity=e}var n=e.prototype;return n.normalize=function(e,n,t,r,i,o){if("string"==typeof e)return e;var a=this._entity.fromJS(e,n,t),s=a.pk(n,t);return i(this._entity,u,a,n,t),s},n.denormalize=function(e,n){return n(e,this._entity)},n._denormalizeNullable=function(){return[]},n._normalizeNullable=function(){return[]},n.merge=function(e,n){return n},e}(),x=Object.freeze({__proto__:null,Union:N,Values:A,Array:m,Object:y,Delete:D});e.DELETED=u,e.Entity=E,e.FlatEntity=k,e.SimpleRecord=S,e.denormalize=function(e,n,t){if("production"!==process.env.NODE_ENV&&void 0===n)throw new Error("schema needed");if(void 0!==e){var r=j(t),i=r[0],o=r[1];return[].concat(i(e,n),[o])}return[void 0,!1,!1,{}]},e.isEntity=w,e.normalize=function(e,n){var t=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(n);if(null===e||typeof e!==t){if("production"!==process.env.NODE_ENV){throw"string"==typeof e&&function(e){try{return"string"!=typeof JSON.parse(e)}catch(e){return!1}}(e)?new Error('Normalizing a string, but this does match schema.\n\nParsing this input string as JSON worked. This likely indicates fetch function did not parse\nthe JSON. By default, this only happens if "content-type" header includes "json".\nSee https://resthooks.io/docs/guides/custom-networking for more information\n\n Schema: '+JSON.stringify(n,void 0,2)+'\n Input: "'+e+'"'):new Error('Unexpected input given to normalize. Expected type to be "'+t+'", found "'+(null===e?"null":typeof e)+'".\n\n Schema: '+JSON.stringify(n,void 0,2)+'\n Input: "'+e+'"')}throw new Error('Unexpected input given to normalize. Expected type to be "'+t+'", found "'+(null===e?"null":typeof e)+'".')}var r={},i={},o=function(e,n){return function(t,r,i,o,a){var u=t.key,s=t.pk(i,o,a);u in e||(e[u]={});var c=e[u][s];if(e[u][s]=c?t.merge(c,r):r,Array.isArray(t.indexes)){var f=e[u][s];u in n||(n[u]={});for(var l,h=b(t.indexes);!(l=h()).done;){var m=l.value;m in n[u]||(n[u][m]={});var p=n[u][m];c&&delete p[c[m]],m in f?p[f[m]]=s:"production"!==process.env.NODE_ENV&&console.warn("Index not found in entity. Indexes must be top-level members of your entity.\nIndex: "+m+"\nEntity: "+JSON.stringify(f,void 0,2))}}}}(r,i);return{entities:r,indexes:i,result:_(e,e,void 0,n,o,{})}},e.schema=x,Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "@rest-hooks/normalizr",
"version": "6.0.0-j.0",
"version": "6.0.0-j.1",
"description": "Normalizes and denormalizes JSON according to schema for Redux and Flux applications",

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

"dist/",
"lib/",
"LICENSE",

@@ -29,12 +30,12 @@ "README.md"

"main": "dist/normalizr.js",
"module": "dist/normalizr.es.js",
"typings": "dist/index.d.ts",
"module": "lib/index.js",
"typings": "lib/index.d.ts",
"sideEffects": false,
"scripts": {
"build": "run-p build:js:*",
"build": "yarn run build:lib && yarn run build:bundle",
"build:bundle": "run-p build:js:*",
"build:js:development": "BROWSERSLIST_ENV=legacy NODE_ENV=development rollup -c",
"build:js:production": "BROWSERSLIST_ENV=legacy NODE_ENV=production rollup -c",
"build:js:es_development": "BROWSERSLIST_ENV=production NODE_ENV=development rollup -c",
"build:js:bundle": "BROWSERSLIST_ENV=production NODE_ENV=production rollup -c",
"build:clean": "rimraf dist *.tsbuildinfo",
"build:lib": "cross-env NODE_ENV=production ROOT_PATH_PREFIX='@rest-hooks/normalizr' babel --root-mode upward src --out-dir lib --source-maps inline --extensions '.ts,.tsx,.js' --ignore '**/__tests__/**' --ignore '**/*.d.ts'",
"build:clean": "rimraf dist lib *.tsbuildinfo",
"lint": "yarn lint:cmd --fix",

@@ -67,3 +68,3 @@ "lint:ci": "yarn lint:cmd",

},
"gitHead": "9f1c93016d32dbb9c93e33b14e225debf1febe56"
"gitHead": "2c30271056703287e287d2b06d22e81c6ba78f37"
}
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