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.10 to 6.0.0-beta.12

20

CHANGELOG.md

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

## 6.0.0-beta.12 (2020-06-13)
* docs: Add field deserialization ([05686cb](https://github.com/coinbase/rest-hooks/commit/05686cb))
* feat: Declarative schema deserialization (#355) ([9dbb019](https://github.com/coinbase/rest-hooks/commit/9dbb019)), closes [#355](https://github.com/coinbase/rest-hooks/issues/355)
## 6.0.0-beta.11 (2020-06-06)
* enhance: Catch Entity key on node 14 ([2a99cd3](https://github.com/coinbase/rest-hooks/commit/2a99cd3))
* feat: SimpleRecord can have optional entities by setting default to null (#350) ([b656185](https://github.com/coinbase/rest-hooks/commit/b656185)), closes [#350](https://github.com/coinbase/rest-hooks/issues/350)
* internal: Add test for complex schema.Values() case (#349) ([d14802a](https://github.com/coinbase/rest-hooks/commit/d14802a)), closes [#349](https://github.com/coinbase/rest-hooks/issues/349)
* internal: eslint major, plugin minor ([1532f7a](https://github.com/coinbase/rest-hooks/commit/1532f7a))
## [6.0.0-beta.10](https://github.com/coinbase/rest-hooks/compare/@rest-hooks/normalizr@6.0.0-beta.9...@rest-hooks/normalizr@6.0.0-beta.10) (2020-05-20)

@@ -8,0 +28,0 @@

2

dist/entities/Entity.d.ts

@@ -25,3 +25,3 @@ import SimpleRecord from './SimpleRecord';

static pk<T extends typeof Entity>(this: T, value: Partial<AbstractInstanceType<T>>, parent?: any, key?: string): string | undefined;
static normalize(input: any, parent: any, key: string | undefined, visit: Function, addEntity: Function, visitedEntities: Record<string, any>): any;
static normalize(input: any, parent: any, key: string | undefined, visit: (...args: any) => any, addEntity: (...args: any) => any, visitedEntities: Record<string, any>): any;
static denormalize<T extends typeof SimpleRecord>(this: T, entity: AbstractInstanceType<T>, unvisit: schema.UnvisitFunction): [AbstractInstanceType<T>, boolean];

@@ -28,0 +28,0 @@ }

@@ -26,3 +26,3 @@ import { AbstractInstanceType, Schema, NormalizedEntity } from '../types';

static normalize<T extends typeof SimpleRecord>(this: T, ...args: any[]): NormalizedEntity<T>;
static denormalize<T extends typeof SimpleRecord>(this: T, ...args: any[]): [AbstractInstanceType<T>, boolean];
static denormalize<T extends typeof SimpleRecord>(this: T, input: any, unvisit: any): [AbstractInstanceType<T>, boolean];
static asSchema<T extends typeof SimpleRecord>(this: T): T;

@@ -29,0 +29,0 @@ }

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

/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
const DefinedMembersKey = Symbol('Defined Members');

@@ -237,2 +238,7 @@ const UniqueIdentifierKey = Symbol('unq');

const instance = new this(props);
if (props instanceof SimpleRecord) {
props = props.constructor.toObjectDefined(props);
}
Object.assign(instance, props);

@@ -286,6 +292,23 @@ Object.defineProperty(instance, DefinedMembersKey, {

static denormalize(...args) {
const [res, found] = denormalize$1(this.schema, ...args); // useDenormalized will memo based on entities, so creating a new object each time is fine
static denormalize(input, unvisit) {
// TODO: This creates unneeded memory pressure
const instance = new this();
const object = { ...input
};
let found = true;
Object.keys(this.schema).forEach(key => {
const [item, foundItem] = unvisit(object[key], this.schema[key]);
return [this.fromJS(res), found];
if (object[key] !== undefined) {
object[key] = item;
} // members who default to falsy values are considered 'optional'
// if falsy value, and default is actually set then it is optional so pass through
if (!foundItem && !(key in instance && !instance[key])) {
found = false;
}
}); // useDenormalized will memo based on entities, so creating a new object each time is fine
return [this.fromJS(object), found];
}

@@ -309,2 +332,4 @@ /* istanbul ignore next */

/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/** Represents data that should be deduped by specifying a primary key. */

@@ -322,3 +347,3 @@ class Entity extends SimpleRecord {

/* istanbul ignore next */
if (process.env.NODE_ENV !== 'production' && this.name === '') throw new Error('Entity classes without a name must define `static get key()`');
if (process.env.NODE_ENV !== 'production' && (this.name === '' || this.name === 'Entity')) throw new Error('Entity classes without a name must define `static get key()`');
return this.name;

@@ -341,3 +366,5 @@ }

static normalize(input, parent, key, visit, addEntity, visitedEntities) {
// TODO: what's store needs to be a differing type from fromJS
// pass over already processed entities
if (typeof input === 'string') return input; // TODO: what's store needs to be a differing type from fromJS
const processedEntity = this.fromJS(input, parent, key);

@@ -419,3 +446,3 @@ /* istanbul ignore else */

Object.keys(this.schema).forEach(key => {
if (Object.hasOwnProperty.call(processedEntity, key) && typeof processedEntity[key] === 'object') {
if (Object.hasOwnProperty.call(processedEntity, key)) {
const schema = this.schema[key];

@@ -430,7 +457,11 @@ processedEntity[key] = visit(processedEntity[key], processedEntity, key, schema, addEntity, visitedEntities);

static denormalize(entity, unvisit) {
// TODO: this entire function is redundant with SimpleRecord, however right now we're storing the Entity instance
// itself in cache. Once we offer full memoization, we will store raw objects and this can be consolidated with SimpleRecord
if (isImmutable(entity)) {
const [denormEntity, found] = denormalizeImmutable(this.schema, entity, unvisit);
return [this.fromJS(denormEntity.toObject()), found];
}
} // TODO: This creates unneeded memory pressure
const instance = new this();
let found = true;

@@ -440,5 +471,7 @@ const denormEntity = entity;

const schema = this.schema[key];
const [value, foundItem] = unvisit(entity[key], schema);
const input = this.hasDefined(entity, key) ? entity[key] : undefined;
const [value, foundItem] = unvisit(input, schema); // members who default to falsy values are considered 'optional'
// if falsy value, and default is actually set then it is optional so pass through
if (!foundItem) {
if (!foundItem && !(key in instance && !instance[key])) {
found = false;

@@ -508,5 +541,10 @@ }

if (typeof schema === 'object' && (!schema.denormalize || typeof schema.denormalize !== 'function')) {
const method = Array.isArray(schema) ? denormalize : denormalize$1;
return method(schema, input, unvisit);
if (!schema.denormalize || typeof schema.denormalize !== 'function') {
if (typeof schema === 'function') {
if (input instanceof schema) return [input, true];
return [new schema(input), true];
} else if (typeof schema === 'object') {
const method = Array.isArray(schema) ? denormalize : denormalize$1;
return method(schema, input, unvisit);
}
} // null is considered intentional, thus always 'found' as true

@@ -551,4 +589,5 @@

};
};
}; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
const denormalize$2 = (input, schema, entities) => {

@@ -567,7 +606,12 @@ /* istanbul ignore next */

const visit = (value, parent, key, schema, addEntity, visitedEntities) => {
if (typeof value !== 'object' || !value || !schema) {
if (!value || !schema || !['function', 'object'].includes(typeof schema)) {
return value;
}
if (typeof schema === 'object' && (!schema.normalize || typeof schema.normalize !== 'function')) {
if (!schema.normalize || typeof schema.normalize !== 'function') {
// serializable
if (typeof schema === 'function') {
return new schema(value);
}
const method = Array.isArray(schema) ? normalize : normalize$1;

@@ -631,4 +675,5 @@ return method(schema, value, parent, key, visit, addEntity, visitedEntities);

return ['object', 'function'].includes(typeof schema) ? 'object' : typeof schema;
}
} // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
const normalize$2 = (input, schema) => {

@@ -635,0 +680,0 @@ const schemaType = expectedSchemaType(schema);

@@ -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,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 h=Symbol("Defined Members"),l=Symbol("unq");class m{toString(){return this[l]}static fromJS(e={},t,n){const r=new this(e);return Object.assign(r,e),Object.defineProperty(r,h,{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[h].includes(t)}static toObjectDefined(e){const t={};for(const n of e[h])t[n]=e[n];return t}static keysDefined(e){return e[h]}static normalize(...e){return a(this.schema,...e)}static denormalize(...e){const[t,n]=u(this.schema,...e);return[this.fromJS(t),n]}static asSchema(){return"development"===process.env.NODE_ENV&&console.error("asSchema() is deprecated - use Entity directly instead."),this}}m.schema={};class d 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 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)),n=this.keysDefined(o),[r,s,i]=[[],[],[]];for(const e of n)t.has(e)?r.push(e):i.push(e);for(const e of t)r.includes(e)||s.push(e);if((Math.max(n.length/2,1)<=i.length&&t.size>Math.max(i.length,2)||r.length<Math.min(1,t.size/2))&&t.size){const 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: ${r}\n Missing: ${s}\n Unexpected keys: ${i}\n Value: ${JSON.stringify(this.toObjectDefined(o),null,2)}`);throw e.status=400,e}}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}return}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 f(e){return null!==e&&void 0!==e.pk}"production"!==process.env.NODE_ENV&&(d.fromJS=function(e){if(void 0===this.prototype.pk)throw new Error("cannot construct on abstract types");return m.fromJS.call(this,e)});class p extends d{static denormalize(e,t){return[e,!0]}}const y=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]:f(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 p?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]}},g=(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,g,s,i)}return r.normalize(e,t,n,g,s,i)};var O=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(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(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(Object.assign({},t),{},{[n]:r})},this.schema||{})}normalize(...e){return a(this.schema,...e)}denormalize(...e){return u(this.schema,...e)}}});e.Entity=d,e.FlatEntity=p,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]=y(n);return[...r(e,t),s]}return[void 0,!1,{}]},e.isEntity=f,e.normalize=(e,t)=>{const n=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(t);if(null===e||typeof e!==n){if("production"!==process.env.NODE_ENV){const r=e=>{try{return"string"!=typeof JSON.parse(e)}catch(e){return!1}};throw"string"==typeof e&&r(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(t,void 0,2)}\n Input: "${e}"`):new Error(`Unexpected input given to normalize. Expected type to be "${n}", found "${null===e?"null":typeof e}".\n\n Schema: ${JSON.stringify(t,void 0,2)}\n Input: "${e}"`)}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:g(e,e,void 0,t,i,{})}},e.schema=O,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;if(!this.isSingleSchema&&!r)return[e,!0];return n((this.isSingleSchema?void 0:t(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[r])}}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);return 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 h=Symbol("Defined Members"),l=Symbol("unq");class f{toString(){return this[l]}static fromJS(e={},t,n){const r=new this(e);return e instanceof f&&(e=e.constructor.toObjectDefined(e)),Object.assign(r,e),Object.defineProperty(r,h,{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[h].includes(t)}static toObjectDefined(e){const t={};for(const n of e[h])t[n]=e[n];return t}static keysDefined(e){return e[h]}static normalize(...e){return a(this.schema,...e)}static denormalize(e,t){const n=new this,r=Object.assign({},e);let s=!0;return Object.keys(this.schema).forEach(e=>{const[i,o]=t(r[e],this.schema[e]);void 0!==r[e]&&(r[e]=i),o||e in n&&!n[e]||(s=!1)}),[this.fromJS(r),s]}static asSchema(){return"development"===process.env.NODE_ENV&&console.error("asSchema() is deprecated - use Entity directly instead."),this}}f.schema={};class m extends f{static get key(){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}static pk(e,t,n){return this.prototype.pk.call(e,t,n)||n}static normalize(e,t,n,r,s,i){if("string"==typeof e)return e;const o=this.fromJS(e,t,n);if("production"!==process.env.NODE_ENV){const e=new this,t=new Set(Object.keys(e)),n=this.keysDefined(o),[r,s,i]=[[],[],[]];for(const e of n)t.has(e)?r.push(e):i.push(e);for(const e of t)r.includes(e)||s.push(e);if((Math.max(n.length/2,1)<=i.length&&t.size>Math.max(i.length,2)||r.length<Math.min(1,t.size/2))&&t.size){const 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: ${r}\n Missing: ${s}\n Unexpected keys: ${i}\n Value: ${JSON.stringify(this.toObjectDefined(o),null,2)}`);throw e.status=400,e}}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}return}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)){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]}const s=new this;let i=!0;const o=e;return Object.keys(this.schema).forEach(t=>{const n=this.schema[t],c=this.hasDefined(e,t)?e[t]:void 0,[a,u]=r(c,n);u||t in s&&!s[t]||(i=!1),this.hasDefined(e,t)&&o[t]!==a&&(o[t]=a)}),[o,i]}}function d(e){return null!==e&&void 0!==e.pk}"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 p extends m{static denormalize(e,t){return[e,!0]}}const y=e=>{const n={},r=b(e);return[function e(s,i){if(!i)return[s,!0];if(!i.denormalize||"function"!=typeof i.denormalize){if("function"==typeof i)return s instanceof i?[s,!0]:[new i(s),!0];if("object"==typeof i){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 p?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]}},g=(e,t,n,r,s,i)=>{if(!e||!r||!["function","object"].includes(typeof r))return e;if(!r.normalize||"function"!=typeof r.normalize){if("function"==typeof r)return new r(e);return(Array.isArray(r)?o:a)(r,e,t,n,g,s,i)}return r.normalize(e,t,n,g,s,i)};var O=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=p,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]=y(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){if("production"!==process.env.NODE_ENV){const r=e=>{try{return"string"!=typeof JSON.parse(e)}catch(e){return!1}};throw"string"==typeof e&&r(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(t,void 0,2)}\n Input: "${e}"`):new Error(`Unexpected input given to normalize. Expected type to be "${n}", found "${null===e?"null":typeof e}".\n\n Schema: ${JSON.stringify(t,void 0,2)}\n Input: "${e}"`)}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:g(e,e,void 0,t,i,{})}},e.schema=O,Object.defineProperty(e,"__esModule",{value:!0})}));

@@ -215,2 +215,3 @@ var rest_hooks_normalizr = (function (exports) {

/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
const DefinedMembersKey = Symbol('Defined Members');

@@ -238,2 +239,7 @@ const UniqueIdentifierKey = Symbol('unq');

const instance = new this(props);
if (props instanceof SimpleRecord) {
props = props.constructor.toObjectDefined(props);
}
Object.assign(instance, props);

@@ -287,6 +293,23 @@ Object.defineProperty(instance, DefinedMembersKey, {

static denormalize(...args) {
const [res, found] = denormalize$1(this.schema, ...args); // useDenormalized will memo based on entities, so creating a new object each time is fine
static denormalize(input, unvisit) {
// TODO: This creates unneeded memory pressure
const instance = new this();
const object = { ...input
};
let found = true;
Object.keys(this.schema).forEach(key => {
const [item, foundItem] = unvisit(object[key], this.schema[key]);
return [this.fromJS(res), found];
if (object[key] !== undefined) {
object[key] = item;
} // members who default to falsy values are considered 'optional'
// if falsy value, and default is actually set then it is optional so pass through
if (!foundItem && !(key in instance && !instance[key])) {
found = false;
}
}); // useDenormalized will memo based on entities, so creating a new object each time is fine
return [this.fromJS(object), found];
}

@@ -310,2 +333,4 @@ /* istanbul ignore next */

/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/** Represents data that should be deduped by specifying a primary key. */

@@ -323,3 +348,3 @@ class Entity extends SimpleRecord {

/* istanbul ignore next */
if (process.env.NODE_ENV !== 'production' && this.name === '') throw new Error('Entity classes without a name must define `static get key()`');
if (process.env.NODE_ENV !== 'production' && (this.name === '' || this.name === 'Entity')) throw new Error('Entity classes without a name must define `static get key()`');
return this.name;

@@ -342,3 +367,5 @@ }

static normalize(input, parent, key, visit, addEntity, visitedEntities) {
// TODO: what's store needs to be a differing type from fromJS
// pass over already processed entities
if (typeof input === 'string') return input; // TODO: what's store needs to be a differing type from fromJS
const processedEntity = this.fromJS(input, parent, key);

@@ -420,3 +447,3 @@ /* istanbul ignore else */

Object.keys(this.schema).forEach(key => {
if (Object.hasOwnProperty.call(processedEntity, key) && typeof processedEntity[key] === 'object') {
if (Object.hasOwnProperty.call(processedEntity, key)) {
const schema = this.schema[key];

@@ -431,7 +458,11 @@ processedEntity[key] = visit(processedEntity[key], processedEntity, key, schema, addEntity, visitedEntities);

static denormalize(entity, unvisit) {
// TODO: this entire function is redundant with SimpleRecord, however right now we're storing the Entity instance
// itself in cache. Once we offer full memoization, we will store raw objects and this can be consolidated with SimpleRecord
if (isImmutable(entity)) {
const [denormEntity, found] = denormalizeImmutable(this.schema, entity, unvisit);
return [this.fromJS(denormEntity.toObject()), found];
}
} // TODO: This creates unneeded memory pressure
const instance = new this();
let found = true;

@@ -441,5 +472,7 @@ const denormEntity = entity;

const schema = this.schema[key];
const [value, foundItem] = unvisit(entity[key], schema);
const input = this.hasDefined(entity, key) ? entity[key] : undefined;
const [value, foundItem] = unvisit(input, schema); // members who default to falsy values are considered 'optional'
// if falsy value, and default is actually set then it is optional so pass through
if (!foundItem) {
if (!foundItem && !(key in instance && !instance[key])) {
found = false;

@@ -509,5 +542,10 @@ }

if (typeof schema === 'object' && (!schema.denormalize || typeof schema.denormalize !== 'function')) {
const method = Array.isArray(schema) ? denormalize : denormalize$1;
return method(schema, input, unvisit);
if (!schema.denormalize || typeof schema.denormalize !== 'function') {
if (typeof schema === 'function') {
if (input instanceof schema) return [input, true];
return [new schema(input), true];
} else if (typeof schema === 'object') {
const method = Array.isArray(schema) ? denormalize : denormalize$1;
return method(schema, input, unvisit);
}
} // null is considered intentional, thus always 'found' as true

@@ -552,4 +590,5 @@

};
};
}; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
const denormalize$2 = (input, schema, entities) => {

@@ -568,7 +607,12 @@ /* istanbul ignore next */

const visit = (value, parent, key, schema, addEntity, visitedEntities) => {
if (typeof value !== 'object' || !value || !schema) {
if (!value || !schema || !['function', 'object'].includes(typeof schema)) {
return value;
}
if (typeof schema === 'object' && (!schema.normalize || typeof schema.normalize !== 'function')) {
if (!schema.normalize || typeof schema.normalize !== 'function') {
// serializable
if (typeof schema === 'function') {
return new schema(value);
}
const method = Array.isArray(schema) ? normalize : normalize$1;

@@ -632,4 +676,5 @@ return method(schema, value, parent, key, visit, addEntity, visitedEntities);

return ['object', 'function'].includes(typeof schema) ? 'object' : typeof schema;
}
} // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
const normalize$2 = (input, schema) => {

@@ -636,0 +681,0 @@ const schemaType = expectedSchemaType(schema);

@@ -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,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 h=Symbol("Defined Members"),l=Symbol("unq");class m{toString(){return this[l]}static fromJS(e={},t,n){const r=new this(e);return Object.assign(r,e),Object.defineProperty(r,h,{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[h].includes(t)}static toObjectDefined(e){const t={};for(const n of e[h])t[n]=e[n];return t}static keysDefined(e){return e[h]}static normalize(...e){return a(this.schema,...e)}static denormalize(...e){const[t,n]=u(this.schema,...e);return[this.fromJS(t),n]}static asSchema(){return"development"===process.env.NODE_ENV&&console.error("asSchema() is deprecated - use Entity directly instead."),this}}m.schema={};class d 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 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)),n=this.keysDefined(o),[r,s,i]=[[],[],[]];for(const e of n)t.has(e)?r.push(e):i.push(e);for(const e of t)r.includes(e)||s.push(e);if((Math.max(n.length/2,1)<=i.length&&t.size>Math.max(i.length,2)||r.length<Math.min(1,t.size/2))&&t.size){const 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: ${r}\n Missing: ${s}\n Unexpected keys: ${i}\n Value: ${JSON.stringify(this.toObjectDefined(o),null,2)}`);throw e.status=400,e}}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}return}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 f(e){return null!==e&&void 0!==e.pk}"production"!==process.env.NODE_ENV&&(d.fromJS=function(e){if(void 0===this.prototype.pk)throw new Error("cannot construct on abstract types");return m.fromJS.call(this,e)});class p extends d{static denormalize(e,t){return[e,!0]}}const y=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]:f(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 p?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]}},g=(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,g,s,i)}return r.normalize(e,t,n,g,s,i)};var O=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(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(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(Object.assign({},t),{},{[n]:r})},this.schema||{})}normalize(...e){return a(this.schema,...e)}denormalize(...e){return u(this.schema,...e)}}});return e.Entity=d,e.FlatEntity=p,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]=y(n);return[...r(e,t),s]}return[void 0,!1,{}]},e.isEntity=f,e.normalize=(e,t)=>{const n=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(t);if(null===e||typeof e!==n){if("production"!==process.env.NODE_ENV){const r=e=>{try{return"string"!=typeof JSON.parse(e)}catch(e){return!1}};throw"string"==typeof e&&r(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(t,void 0,2)}\n Input: "${e}"`):new Error(`Unexpected input given to normalize. Expected type to be "${n}", found "${null===e?"null":typeof e}".\n\n Schema: ${JSON.stringify(t,void 0,2)}\n Input: "${e}"`)}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:g(e,e,void 0,t,i,{})}},e.schema=O,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;if(!this.isSingleSchema&&!r)return[e,!0];return n((this.isSingleSchema?void 0:t(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[r])}}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);return 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 h=Symbol("Defined Members"),l=Symbol("unq");class f{toString(){return this[l]}static fromJS(e={},t,n){const r=new this(e);return e instanceof f&&(e=e.constructor.toObjectDefined(e)),Object.assign(r,e),Object.defineProperty(r,h,{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[h].includes(t)}static toObjectDefined(e){const t={};for(const n of e[h])t[n]=e[n];return t}static keysDefined(e){return e[h]}static normalize(...e){return a(this.schema,...e)}static denormalize(e,t){const n=new this,r=Object.assign({},e);let s=!0;return Object.keys(this.schema).forEach(e=>{const[i,o]=t(r[e],this.schema[e]);void 0!==r[e]&&(r[e]=i),o||e in n&&!n[e]||(s=!1)}),[this.fromJS(r),s]}static asSchema(){return"development"===process.env.NODE_ENV&&console.error("asSchema() is deprecated - use Entity directly instead."),this}}f.schema={};class m extends f{static get key(){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}static pk(e,t,n){return this.prototype.pk.call(e,t,n)||n}static normalize(e,t,n,r,s,i){if("string"==typeof e)return e;const o=this.fromJS(e,t,n);if("production"!==process.env.NODE_ENV){const e=new this,t=new Set(Object.keys(e)),n=this.keysDefined(o),[r,s,i]=[[],[],[]];for(const e of n)t.has(e)?r.push(e):i.push(e);for(const e of t)r.includes(e)||s.push(e);if((Math.max(n.length/2,1)<=i.length&&t.size>Math.max(i.length,2)||r.length<Math.min(1,t.size/2))&&t.size){const 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: ${r}\n Missing: ${s}\n Unexpected keys: ${i}\n Value: ${JSON.stringify(this.toObjectDefined(o),null,2)}`);throw e.status=400,e}}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}return}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)){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]}const s=new this;let i=!0;const o=e;return Object.keys(this.schema).forEach(t=>{const n=this.schema[t],c=this.hasDefined(e,t)?e[t]:void 0,[a,u]=r(c,n);u||t in s&&!s[t]||(i=!1),this.hasDefined(e,t)&&o[t]!==a&&(o[t]=a)}),[o,i]}}function d(e){return null!==e&&void 0!==e.pk}"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 p extends m{static denormalize(e,t){return[e,!0]}}const y=e=>{const n={},r=b(e);return[function e(s,i){if(!i)return[s,!0];if(!i.denormalize||"function"!=typeof i.denormalize){if("function"==typeof i)return s instanceof i?[s,!0]:[new i(s),!0];if("object"==typeof i){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 p?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]}},g=(e,t,n,r,s,i)=>{if(!e||!r||!["function","object"].includes(typeof r))return e;if(!r.normalize||"function"!=typeof r.normalize){if("function"==typeof r)return new r(e);return(Array.isArray(r)?o:a)(r,e,t,n,g,s,i)}return r.normalize(e,t,n,g,s,i)};var O=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=m,e.FlatEntity=p,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]=y(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){if("production"!==process.env.NODE_ENV){const r=e=>{try{return"string"!=typeof JSON.parse(e)}catch(e){return!1}};throw"string"==typeof e&&r(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(t,void 0,2)}\n Input: "${e}"`):new Error(`Unexpected input given to normalize. Expected type to be "${n}", found "${null===e?"null":typeof e}".\n\n Schema: ${JSON.stringify(t,void 0,2)}\n Input: "${e}"`)}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:g(e,e,void 0,t,i,{})}},e.schema=O,e}({});

@@ -194,3 +194,3 @@ /**

const schema = definition[key];
return Object.assign(Object.assign({}, entitySchema), {}, {
return Object.assign({}, entitySchema, {
[key]: schema

@@ -211,2 +211,3 @@ });

/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
const DefinedMembersKey = Symbol('Defined Members');

@@ -234,2 +235,7 @@ const UniqueIdentifierKey = Symbol('unq');

const instance = new this(props);
if (props instanceof SimpleRecord) {
props = props.constructor.toObjectDefined(props);
}
Object.assign(instance, props);

@@ -283,6 +289,22 @@ Object.defineProperty(instance, DefinedMembersKey, {

static denormalize(...args) {
const [res, found] = denormalize$1(this.schema, ...args); // useDenormalized will memo based on entities, so creating a new object each time is fine
static denormalize(input, unvisit) {
// TODO: This creates unneeded memory pressure
const instance = new this();
const object = Object.assign({}, input);
let found = true;
Object.keys(this.schema).forEach(key => {
const [item, foundItem] = unvisit(object[key], this.schema[key]);
return [this.fromJS(res), found];
if (object[key] !== undefined) {
object[key] = item;
} // members who default to falsy values are considered 'optional'
// if falsy value, and default is actually set then it is optional so pass through
if (!foundItem && !(key in instance && !instance[key])) {
found = false;
}
}); // useDenormalized will memo based on entities, so creating a new object each time is fine
return [this.fromJS(object), found];
}

@@ -306,2 +328,4 @@ /* istanbul ignore next */

/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/** Represents data that should be deduped by specifying a primary key. */

@@ -319,3 +343,3 @@ class Entity extends SimpleRecord {

/* istanbul ignore next */
if (process.env.NODE_ENV !== 'production' && this.name === '') throw new Error('Entity classes without a name must define `static get key()`');
if (process.env.NODE_ENV !== 'production' && (this.name === '' || this.name === 'Entity')) throw new Error('Entity classes without a name must define `static get key()`');
return this.name;

@@ -338,3 +362,5 @@ }

static normalize(input, parent, key, visit, addEntity, visitedEntities) {
// TODO: what's store needs to be a differing type from fromJS
// pass over already processed entities
if (typeof input === 'string') return input; // TODO: what's store needs to be a differing type from fromJS
const processedEntity = this.fromJS(input, parent, key);

@@ -416,3 +442,3 @@ /* istanbul ignore else */

Object.keys(this.schema).forEach(key => {
if (Object.hasOwnProperty.call(processedEntity, key) && typeof processedEntity[key] === 'object') {
if (Object.hasOwnProperty.call(processedEntity, key)) {
const schema = this.schema[key];

@@ -427,7 +453,11 @@ processedEntity[key] = visit(processedEntity[key], processedEntity, key, schema, addEntity, visitedEntities);

static denormalize(entity, unvisit) {
// TODO: this entire function is redundant with SimpleRecord, however right now we're storing the Entity instance
// itself in cache. Once we offer full memoization, we will store raw objects and this can be consolidated with SimpleRecord
if (isImmutable(entity)) {
const [denormEntity, found] = denormalizeImmutable(this.schema, entity, unvisit);
return [this.fromJS(denormEntity.toObject()), found];
}
} // TODO: This creates unneeded memory pressure
const instance = new this();
let found = true;

@@ -437,5 +467,7 @@ const denormEntity = entity;

const schema = this.schema[key];
const [value, foundItem] = unvisit(entity[key], schema);
const input = this.hasDefined(entity, key) ? entity[key] : undefined;
const [value, foundItem] = unvisit(input, schema); // members who default to falsy values are considered 'optional'
// if falsy value, and default is actually set then it is optional so pass through
if (!foundItem) {
if (!foundItem && !(key in instance && !instance[key])) {
found = false;

@@ -505,5 +537,10 @@ }

if (typeof schema === 'object' && (!schema.denormalize || typeof schema.denormalize !== 'function')) {
const method = Array.isArray(schema) ? denormalize : denormalize$1;
return method(schema, input, unvisit);
if (!schema.denormalize || typeof schema.denormalize !== 'function') {
if (typeof schema === 'function') {
if (input instanceof schema) return [input, true];
return [new schema(input), true];
} else if (typeof schema === 'object') {
const method = Array.isArray(schema) ? denormalize : denormalize$1;
return method(schema, input, unvisit);
}
} // null is considered intentional, thus always 'found' as true

@@ -548,4 +585,5 @@

};
};
}; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
const denormalize$2 = (input, schema, entities) => {

@@ -564,7 +602,12 @@ /* istanbul ignore next */

const visit = (value, parent, key, schema, addEntity, visitedEntities) => {
if (typeof value !== 'object' || !value || !schema) {
if (!value || !schema || !['function', 'object'].includes(typeof schema)) {
return value;
}
if (typeof schema === 'object' && (!schema.normalize || typeof schema.normalize !== 'function')) {
if (!schema.normalize || typeof schema.normalize !== 'function') {
// serializable
if (typeof schema === 'function') {
return new schema(value);
}
const method = Array.isArray(schema) ? normalize : normalize$1;

@@ -628,4 +671,5 @@ return method(schema, value, parent, key, visit, addEntity, visitedEntities);

return ['object', 'function'].includes(typeof schema) ? 'object' : typeof schema;
}
} // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
const normalize$2 = (input, schema) => {

@@ -700,3 +744,3 @@ const schemaType = expectedSchemaType(schema);

const value = input[key];
return value !== undefined && value !== null ? Object.assign(Object.assign({}, output), {}, {
return value !== undefined && value !== null ? Object.assign({}, output, {
[key]: this.normalizeValue(value, input, key, visit, addEntity, visitedEntities)

@@ -717,3 +761,3 @@ }) : output;

return Object.assign(Object.assign({}, output), {}, {
return Object.assign({}, output, {
[key]: value

@@ -720,0 +764,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,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"),h=Symbol("unq");class l{toString(){return this[h]}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,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[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]}static normalize(...e){return c(this.schema,...e)}static denormalize(...e){const[t,n]=a(this.schema,...e);return[this.fromJS(t),n]}static asSchema(){return"development"===process.env.NODE_ENV&&console.error("asSchema() is deprecated - use Entity directly instead."),this}}l.schema={};class m extends l{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 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)),n=this.keysDefined(o),[r,s,i]=[[],[],[]];for(const e of n)t.has(e)?r.push(e):i.push(e);for(const e of t)r.includes(e)||s.push(e);if((Math.max(n.length/2,1)<=i.length&&t.size>Math.max(i.length,2)||r.length<Math.min(1,t.size/2))&&t.size){const 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: ${r}\n Missing: ${s}\n Unexpected keys: ${i}\n Value: ${JSON.stringify(this.toObjectDefined(o),null,2)}`);throw e.status=400,e}}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}return}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 d(e){return null!==e&&void 0!==e.pk}"production"!==process.env.NODE_ENV&&(m.fromJS=function(e){if(void 0===this.prototype.pk)throw new Error("cannot construct on abstract types");return l.fromJS.call(this,e)});class f 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]:d(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 f?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)=>{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,{}]},g=(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,g,s,o)}return r.normalize(e,t,n,g,s,o)};const O=(e,t)=>{const n=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(t);if(null===e||typeof e!==n){if("production"!==process.env.NODE_ENV){const r=e=>{try{return"string"!=typeof JSON.parse(e)}catch(e){return!1}};throw"string"==typeof e&&r(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(t,void 0,2)}\n Input: "${e}"`):new Error(`Unexpected input given to normalize. Expected type to be "${n}", found "${null===e?"null":typeof e}".\n\n Schema: ${JSON.stringify(t,void 0,2)}\n Input: "${e}"`)}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:g(e,e,void 0,t,i,{})}};var S=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(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(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(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,f as FlatEntity,l as SimpleRecord,b as denormalize,d as isEntity,O as normalize,S 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;if(!this.isSingleSchema&&!r)return[t,!0];return n((this.isSingleSchema?void 0:e(t)?t.get("id"):t.id)||t,this.isSingleSchema?this.schema:this.schema[r])}}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);return 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"),h=Symbol("unq");class l{toString(){return this[h]}static fromJS(e={},t,n){const r=new this(e);return e instanceof l&&(e=e.constructor.toObjectDefined(e)),Object.assign(r,e),Object.defineProperty(r,u,{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[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]}static normalize(...e){return c(this.schema,...e)}static denormalize(e,t){const n=new this,r=Object.assign({},e);let s=!0;return Object.keys(this.schema).forEach(e=>{const[i,o]=t(r[e],this.schema[e]);void 0!==r[e]&&(r[e]=i),o||e in n&&!n[e]||(s=!1)}),[this.fromJS(r),s]}static asSchema(){return"development"===process.env.NODE_ENV&&console.error("asSchema() is deprecated - use Entity directly instead."),this}}l.schema={};class f extends l{static get key(){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}static pk(e,t,n){return this.prototype.pk.call(e,t,n)||n}static normalize(e,t,n,r,s,i){if("string"==typeof e)return e;const o=this.fromJS(e,t,n);if("production"!==process.env.NODE_ENV){const e=new this,t=new Set(Object.keys(e)),n=this.keysDefined(o),[r,s,i]=[[],[],[]];for(const e of n)t.has(e)?r.push(e):i.push(e);for(const e of t)r.includes(e)||s.push(e);if((Math.max(n.length/2,1)<=i.length&&t.size>Math.max(i.length,2)||r.length<Math.min(1,t.size/2))&&t.size){const 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: ${r}\n Missing: ${s}\n Unexpected keys: ${i}\n Value: ${JSON.stringify(this.toObjectDefined(o),null,2)}`);throw e.status=400,e}}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}return}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)){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]}const s=new this;let i=!0;const o=n;return Object.keys(this.schema).forEach(e=>{const t=this.schema[e],c=this.hasDefined(n,e)?n[e]:void 0,[a,u]=r(c,t);u||e in s&&!s[e]||(i=!1),this.hasDefined(n,e)&&o[e]!==a&&(o[e]=a)}),[o,i]}}function m(e){return null!==e&&void 0!==e.pk}"production"!==process.env.NODE_ENV&&(f.fromJS=function(e){if(void 0===this.prototype.pk)throw new Error("cannot construct on abstract types");return l.fromJS.call(this,e)});class d extends f{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(!i.denormalize||"function"!=typeof i.denormalize){if("function"==typeof i)return s instanceof i?[s,!0]:[new i(s),!0];if("object"==typeof i){return(Array.isArray(i)?o:a)(i,s,t)}}return null===s?[s,!0]:m(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)=>{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,{}]},g=(e,t,n,r,s,o)=>{if(!e||!r||!["function","object"].includes(typeof r))return e;if(!r.normalize||"function"!=typeof r.normalize){if("function"==typeof r)return new r(e);return(Array.isArray(r)?i:c)(r,e,t,n,g,s,o)}return r.normalize(e,t,n,g,s,o)};const O=(e,t)=>{const n=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(t);if(null===e||typeof e!==n){if("production"!==process.env.NODE_ENV){const r=e=>{try{return"string"!=typeof JSON.parse(e)}catch(e){return!1}};throw"string"==typeof e&&r(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(t,void 0,2)}\n Input: "${e}"`):new Error(`Unexpected input given to normalize. Expected type to be "${n}", found "${null===e?"null":typeof e}".\n\n Schema: ${JSON.stringify(t,void 0,2)}\n Input: "${e}"`)}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:g(e,e,void 0,t,i,{})}};var S=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{f as Entity,d as FlatEntity,l as SimpleRecord,b as denormalize,m as isEntity,O as normalize,S as schema};

@@ -216,2 +216,3 @@ 'use strict';

/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
const DefinedMembersKey = Symbol('Defined Members');

@@ -239,2 +240,7 @@ const UniqueIdentifierKey = Symbol('unq');

const instance = new this(props);
if (props instanceof SimpleRecord) {
props = props.constructor.toObjectDefined(props);
}
Object.assign(instance, props);

@@ -288,6 +294,23 @@ Object.defineProperty(instance, DefinedMembersKey, {

static denormalize(...args) {
const [res, found] = denormalize$1(this.schema, ...args); // useDenormalized will memo based on entities, so creating a new object each time is fine
static denormalize(input, unvisit) {
// TODO: This creates unneeded memory pressure
const instance = new this();
const object = { ...input
};
let found = true;
Object.keys(this.schema).forEach(key => {
const [item, foundItem] = unvisit(object[key], this.schema[key]);
return [this.fromJS(res), found];
if (object[key] !== undefined) {
object[key] = item;
} // members who default to falsy values are considered 'optional'
// if falsy value, and default is actually set then it is optional so pass through
if (!foundItem && !(key in instance && !instance[key])) {
found = false;
}
}); // useDenormalized will memo based on entities, so creating a new object each time is fine
return [this.fromJS(object), found];
}

@@ -311,2 +334,4 @@ /* istanbul ignore next */

/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/** Represents data that should be deduped by specifying a primary key. */

@@ -324,3 +349,3 @@ class Entity extends SimpleRecord {

/* istanbul ignore next */
if (process.env.NODE_ENV !== 'production' && this.name === '') throw new Error('Entity classes without a name must define `static get key()`');
if (process.env.NODE_ENV !== 'production' && (this.name === '' || this.name === 'Entity')) throw new Error('Entity classes without a name must define `static get key()`');
return this.name;

@@ -343,3 +368,5 @@ }

static normalize(input, parent, key, visit, addEntity, visitedEntities) {
// TODO: what's store needs to be a differing type from fromJS
// pass over already processed entities
if (typeof input === 'string') return input; // TODO: what's store needs to be a differing type from fromJS
const processedEntity = this.fromJS(input, parent, key);

@@ -421,3 +448,3 @@ /* istanbul ignore else */

Object.keys(this.schema).forEach(key => {
if (Object.hasOwnProperty.call(processedEntity, key) && typeof processedEntity[key] === 'object') {
if (Object.hasOwnProperty.call(processedEntity, key)) {
const schema = this.schema[key];

@@ -432,7 +459,11 @@ processedEntity[key] = visit(processedEntity[key], processedEntity, key, schema, addEntity, visitedEntities);

static denormalize(entity, unvisit) {
// TODO: this entire function is redundant with SimpleRecord, however right now we're storing the Entity instance
// itself in cache. Once we offer full memoization, we will store raw objects and this can be consolidated with SimpleRecord
if (isImmutable(entity)) {
const [denormEntity, found] = denormalizeImmutable(this.schema, entity, unvisit);
return [this.fromJS(denormEntity.toObject()), found];
}
} // TODO: This creates unneeded memory pressure
const instance = new this();
let found = true;

@@ -442,5 +473,7 @@ const denormEntity = entity;

const schema = this.schema[key];
const [value, foundItem] = unvisit(entity[key], schema);
const input = this.hasDefined(entity, key) ? entity[key] : undefined;
const [value, foundItem] = unvisit(input, schema); // members who default to falsy values are considered 'optional'
// if falsy value, and default is actually set then it is optional so pass through
if (!foundItem) {
if (!foundItem && !(key in instance && !instance[key])) {
found = false;

@@ -510,5 +543,10 @@ }

if (typeof schema === 'object' && (!schema.denormalize || typeof schema.denormalize !== 'function')) {
const method = Array.isArray(schema) ? denormalize : denormalize$1;
return method(schema, input, unvisit);
if (!schema.denormalize || typeof schema.denormalize !== 'function') {
if (typeof schema === 'function') {
if (input instanceof schema) return [input, true];
return [new schema(input), true];
} else if (typeof schema === 'object') {
const method = Array.isArray(schema) ? denormalize : denormalize$1;
return method(schema, input, unvisit);
}
} // null is considered intentional, thus always 'found' as true

@@ -553,4 +591,5 @@

};
};
}; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
const denormalize$2 = (input, schema, entities) => {

@@ -569,7 +608,12 @@ /* istanbul ignore next */

const visit = (value, parent, key, schema, addEntity, visitedEntities) => {
if (typeof value !== 'object' || !value || !schema) {
if (!value || !schema || !['function', 'object'].includes(typeof schema)) {
return value;
}
if (typeof schema === 'object' && (!schema.normalize || typeof schema.normalize !== 'function')) {
if (!schema.normalize || typeof schema.normalize !== 'function') {
// serializable
if (typeof schema === 'function') {
return new schema(value);
}
const method = Array.isArray(schema) ? normalize : normalize$1;

@@ -633,4 +677,5 @@ return method(schema, value, parent, key, visit, addEntity, visitedEntities);

return ['object', 'function'].includes(typeof schema) ? 'object' : typeof schema;
}
} // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
const normalize$2 = (input, schema) => {

@@ -637,0 +682,0 @@ const schemaType = expectedSchemaType(schema);

@@ -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"),h=Symbol("unq");class l{toString(){return this[h]}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,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[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]}static normalize(...e){return c(this.schema,...e)}static denormalize(...e){const[t,n]=a(this.schema,...e);return[this.fromJS(t),n]}static asSchema(){return"development"===process.env.NODE_ENV&&console.error("asSchema() is deprecated - use Entity directly instead."),this}}l.schema={};class m extends l{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 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)),n=this.keysDefined(o),[r,s,i]=[[],[],[]];for(const e of n)t.has(e)?r.push(e):i.push(e);for(const e of t)r.includes(e)||s.push(e);if((Math.max(n.length/2,1)<=i.length&&t.size>Math.max(i.length,2)||r.length<Math.min(1,t.size/2))&&t.size){const 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: ${r}\n Missing: ${s}\n Unexpected keys: ${i}\n Value: ${JSON.stringify(this.toObjectDefined(o),null,2)}`);throw e.status=400,e}}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}return}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 d(e){return null!==e&&void 0!==e.pk}"production"!==process.env.NODE_ENV&&(m.fromJS=function(e){if(void 0===this.prototype.pk)throw new Error("cannot construct on abstract types");return l.fromJS.call(this,e)});class f 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]:d(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 f?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 g=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(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(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(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=f,exports.SimpleRecord=l,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=d,exports.normalize=(e,t)=>{const n=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(t);if(null===e||typeof e!==n){if("production"!==process.env.NODE_ENV){const r=e=>{try{return"string"!=typeof JSON.parse(e)}catch(e){return!1}};throw"string"==typeof e&&r(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(t,void 0,2)}\n Input: "${e}"`):new Error(`Unexpected input given to normalize. Expected type to be "${n}", found "${null===e?"null":typeof e}".\n\n Schema: ${JSON.stringify(t,void 0,2)}\n Input: "${e}"`)}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=g;
"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;if(!this.isSingleSchema&&!r)return[t,!0];return n((this.isSingleSchema?void 0:e(t)?t.get("id"):t.id)||t,this.isSingleSchema?this.schema:this.schema[r])}}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);return 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"),h=Symbol("unq");class l{toString(){return this[h]}static fromJS(e={},t,n){const r=new this(e);return e instanceof l&&(e=e.constructor.toObjectDefined(e)),Object.assign(r,e),Object.defineProperty(r,u,{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[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]}static normalize(...e){return c(this.schema,...e)}static denormalize(e,t){const n=new this,r=Object.assign({},e);let s=!0;return Object.keys(this.schema).forEach(e=>{const[i,o]=t(r[e],this.schema[e]);void 0!==r[e]&&(r[e]=i),o||e in n&&!n[e]||(s=!1)}),[this.fromJS(r),s]}static asSchema(){return"development"===process.env.NODE_ENV&&console.error("asSchema() is deprecated - use Entity directly instead."),this}}l.schema={};class f extends l{static get key(){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}static pk(e,t,n){return this.prototype.pk.call(e,t,n)||n}static normalize(e,t,n,r,s,i){if("string"==typeof e)return e;const o=this.fromJS(e,t,n);if("production"!==process.env.NODE_ENV){const e=new this,t=new Set(Object.keys(e)),n=this.keysDefined(o),[r,s,i]=[[],[],[]];for(const e of n)t.has(e)?r.push(e):i.push(e);for(const e of t)r.includes(e)||s.push(e);if((Math.max(n.length/2,1)<=i.length&&t.size>Math.max(i.length,2)||r.length<Math.min(1,t.size/2))&&t.size){const 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: ${r}\n Missing: ${s}\n Unexpected keys: ${i}\n Value: ${JSON.stringify(this.toObjectDefined(o),null,2)}`);throw e.status=400,e}}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}return}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)){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]}const s=new this;let i=!0;const o=n;return Object.keys(this.schema).forEach(e=>{const t=this.schema[e],c=this.hasDefined(n,e)?n[e]:void 0,[a,u]=r(c,t);u||e in s&&!s[e]||(i=!1),this.hasDefined(n,e)&&o[e]!==a&&(o[e]=a)}),[o,i]}}function m(e){return null!==e&&void 0!==e.pk}"production"!==process.env.NODE_ENV&&(f.fromJS=function(e){if(void 0===this.prototype.pk)throw new Error("cannot construct on abstract types");return l.fromJS.call(this,e)});class d extends f{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(!i.denormalize||"function"!=typeof i.denormalize){if("function"==typeof i)return s instanceof i?[s,!0]:[new i(s),!0];if("object"==typeof i){return(Array.isArray(i)?o:a)(i,s,t)}}return null===s?[s,!0]:m(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(!e||!r||!["function","object"].includes(typeof r))return e;if(!r.normalize||"function"!=typeof r.normalize){if("function"==typeof r)return new r(e);return(Array.isArray(r)?i:c)(r,e,t,n,b,s,o)}return r.normalize(e,t,n,b,s,o)};var g=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=f,exports.FlatEntity=d,exports.SimpleRecord=l,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=m,exports.normalize=(e,t)=>{const n=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(t);if(null===e||typeof e!==n){if("production"!==process.env.NODE_ENV){const r=e=>{try{return"string"!=typeof JSON.parse(e)}catch(e){return!1}};throw"string"==typeof e&&r(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(t,void 0,2)}\n Input: "${e}"`):new Error(`Unexpected input given to normalize. Expected type to be "${n}", found "${null===e?"null":typeof e}".\n\n Schema: ${JSON.stringify(t,void 0,2)}\n Input: "${e}"`)}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=g;

@@ -218,2 +218,3 @@ (function (global, factory) {

/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
const DefinedMembersKey = Symbol('Defined Members');

@@ -241,2 +242,7 @@ const UniqueIdentifierKey = Symbol('unq');

const instance = new this(props);
if (props instanceof SimpleRecord) {
props = props.constructor.toObjectDefined(props);
}
Object.assign(instance, props);

@@ -290,6 +296,23 @@ Object.defineProperty(instance, DefinedMembersKey, {

static denormalize(...args) {
const [res, found] = denormalize$1(this.schema, ...args); // useDenormalized will memo based on entities, so creating a new object each time is fine
static denormalize(input, unvisit) {
// TODO: This creates unneeded memory pressure
const instance = new this();
const object = { ...input
};
let found = true;
Object.keys(this.schema).forEach(key => {
const [item, foundItem] = unvisit(object[key], this.schema[key]);
return [this.fromJS(res), found];
if (object[key] !== undefined) {
object[key] = item;
} // members who default to falsy values are considered 'optional'
// if falsy value, and default is actually set then it is optional so pass through
if (!foundItem && !(key in instance && !instance[key])) {
found = false;
}
}); // useDenormalized will memo based on entities, so creating a new object each time is fine
return [this.fromJS(object), found];
}

@@ -313,2 +336,4 @@ /* istanbul ignore next */

/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/** Represents data that should be deduped by specifying a primary key. */

@@ -326,3 +351,3 @@ class Entity extends SimpleRecord {

/* istanbul ignore next */
if (process.env.NODE_ENV !== 'production' && this.name === '') throw new Error('Entity classes without a name must define `static get key()`');
if (process.env.NODE_ENV !== 'production' && (this.name === '' || this.name === 'Entity')) throw new Error('Entity classes without a name must define `static get key()`');
return this.name;

@@ -345,3 +370,5 @@ }

static normalize(input, parent, key, visit, addEntity, visitedEntities) {
// TODO: what's store needs to be a differing type from fromJS
// pass over already processed entities
if (typeof input === 'string') return input; // TODO: what's store needs to be a differing type from fromJS
const processedEntity = this.fromJS(input, parent, key);

@@ -423,3 +450,3 @@ /* istanbul ignore else */

Object.keys(this.schema).forEach(key => {
if (Object.hasOwnProperty.call(processedEntity, key) && typeof processedEntity[key] === 'object') {
if (Object.hasOwnProperty.call(processedEntity, key)) {
const schema = this.schema[key];

@@ -434,7 +461,11 @@ processedEntity[key] = visit(processedEntity[key], processedEntity, key, schema, addEntity, visitedEntities);

static denormalize(entity, unvisit) {
// TODO: this entire function is redundant with SimpleRecord, however right now we're storing the Entity instance
// itself in cache. Once we offer full memoization, we will store raw objects and this can be consolidated with SimpleRecord
if (isImmutable(entity)) {
const [denormEntity, found] = denormalizeImmutable(this.schema, entity, unvisit);
return [this.fromJS(denormEntity.toObject()), found];
}
} // TODO: This creates unneeded memory pressure
const instance = new this();
let found = true;

@@ -444,5 +475,7 @@ const denormEntity = entity;

const schema = this.schema[key];
const [value, foundItem] = unvisit(entity[key], schema);
const input = this.hasDefined(entity, key) ? entity[key] : undefined;
const [value, foundItem] = unvisit(input, schema); // members who default to falsy values are considered 'optional'
// if falsy value, and default is actually set then it is optional so pass through
if (!foundItem) {
if (!foundItem && !(key in instance && !instance[key])) {
found = false;

@@ -512,5 +545,10 @@ }

if (typeof schema === 'object' && (!schema.denormalize || typeof schema.denormalize !== 'function')) {
const method = Array.isArray(schema) ? denormalize : denormalize$1;
return method(schema, input, unvisit);
if (!schema.denormalize || typeof schema.denormalize !== 'function') {
if (typeof schema === 'function') {
if (input instanceof schema) return [input, true];
return [new schema(input), true];
} else if (typeof schema === 'object') {
const method = Array.isArray(schema) ? denormalize : denormalize$1;
return method(schema, input, unvisit);
}
} // null is considered intentional, thus always 'found' as true

@@ -555,4 +593,5 @@

};
};
}; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
const denormalize$2 = (input, schema, entities) => {

@@ -571,7 +610,12 @@ /* istanbul ignore next */

const visit = (value, parent, key, schema, addEntity, visitedEntities) => {
if (typeof value !== 'object' || !value || !schema) {
if (!value || !schema || !['function', 'object'].includes(typeof schema)) {
return value;
}
if (typeof schema === 'object' && (!schema.normalize || typeof schema.normalize !== 'function')) {
if (!schema.normalize || typeof schema.normalize !== 'function') {
// serializable
if (typeof schema === 'function') {
return new schema(value);
}
const method = Array.isArray(schema) ? normalize : normalize$1;

@@ -635,4 +679,5 @@ return method(schema, value, parent, key, visit, addEntity, visitedEntities);

return ['object', 'function'].includes(typeof schema) ? 'object' : typeof schema;
}
} // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
const normalize$2 = (input, schema) => {

@@ -639,0 +684,0 @@ const schemaType = expectedSchemaType(schema);

@@ -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,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 h=Symbol("Defined Members"),l=Symbol("unq");class m{toString(){return this[l]}static fromJS(e={},t,n){const r=new this(e);return Object.assign(r,e),Object.defineProperty(r,h,{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[h].includes(t)}static toObjectDefined(e){const t={};for(const n of e[h])t[n]=e[n];return t}static keysDefined(e){return e[h]}static normalize(...e){return a(this.schema,...e)}static denormalize(...e){const[t,n]=u(this.schema,...e);return[this.fromJS(t),n]}static asSchema(){return"development"===process.env.NODE_ENV&&console.error("asSchema() is deprecated - use Entity directly instead."),this}}m.schema={};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 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)),n=this.keysDefined(o),[r,s,i]=[[],[],[]];for(const e of n)t.has(e)?r.push(e):i.push(e);for(const e of t)r.includes(e)||s.push(e);if((Math.max(n.length/2,1)<=i.length&&t.size>Math.max(i.length,2)||r.length<Math.min(1,t.size/2))&&t.size){const 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: ${r}\n Missing: ${s}\n Unexpected keys: ${i}\n Value: ${JSON.stringify(this.toObjectDefined(o),null,2)}`);throw e.status=400,e}}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}return}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}"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 p extends f{static denormalize(e,t){return[e,!0]}}const y=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 p?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]}},g=(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,g,s,i)}return r.normalize(e,t,n,g,s,i)};var O=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(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(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(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=p,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]=y(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){if("production"!==process.env.NODE_ENV){const r=e=>{try{return"string"!=typeof JSON.parse(e)}catch(e){return!1}};throw"string"==typeof e&&r(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(t,void 0,2)}\n Input: "${e}"`):new Error(`Unexpected input given to normalize. Expected type to be "${n}", found "${null===e?"null":typeof e}".\n\n Schema: ${JSON.stringify(t,void 0,2)}\n Input: "${e}"`)}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:g(e,e,void 0,t,i,{})}},e.schema=O,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,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;if(!this.isSingleSchema&&!r)return[e,!0];return n((this.isSingleSchema?void 0:t(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[r])}}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);return 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 h=Symbol("Defined Members"),l=Symbol("unq");class f{toString(){return this[l]}static fromJS(e={},t,n){const r=new this(e);return e instanceof f&&(e=e.constructor.toObjectDefined(e)),Object.assign(r,e),Object.defineProperty(r,h,{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[h].includes(t)}static toObjectDefined(e){const t={};for(const n of e[h])t[n]=e[n];return t}static keysDefined(e){return e[h]}static normalize(...e){return a(this.schema,...e)}static denormalize(e,t){const n=new this,r=Object.assign({},e);let i=!0;return Object.keys(this.schema).forEach(e=>{const[s,o]=t(r[e],this.schema[e]);void 0!==r[e]&&(r[e]=s),o||e in n&&!n[e]||(i=!1)}),[this.fromJS(r),i]}static asSchema(){return"development"===process.env.NODE_ENV&&console.error("asSchema() is deprecated - use Entity directly instead."),this}}f.schema={};class m extends f{static get key(){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}static pk(e,t,n){return this.prototype.pk.call(e,t,n)||n}static normalize(e,t,n,r,i,s){if("string"==typeof e)return e;const o=this.fromJS(e,t,n);if("production"!==process.env.NODE_ENV){const e=new this,t=new Set(Object.keys(e)),n=this.keysDefined(o),[r,i,s]=[[],[],[]];for(const e of n)t.has(e)?r.push(e):s.push(e);for(const e of t)r.includes(e)||i.push(e);if((Math.max(n.length/2,1)<=s.length&&t.size>Math.max(s.length,2)||r.length<Math.min(1,t.size/2))&&t.size){const 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: ${r}\n Missing: ${i}\n Unexpected keys: ${s}\n Value: ${JSON.stringify(this.toObjectDefined(o),null,2)}`);throw e.status=400,e}}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}return}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)){const t=this.schema[e];o[e]=r(o[e],o,e,t,i,s)}}),i(this,o,o,t,n)),c}static denormalize(e,r){if(t(e)){const[t,i]=n(this.schema,e,r);return[this.fromJS(t.toObject()),i]}const i=new this;let s=!0;const o=e;return Object.keys(this.schema).forEach(t=>{const n=this.schema[t],c=this.hasDefined(e,t)?e[t]:void 0,[a,u]=r(c,n);u||t in i&&!i[t]||(s=!1),this.hasDefined(e,t)&&o[t]!==a&&(o[t]=a)}),[o,s]}}function d(e){return null!==e&&void 0!==e.pk}"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 p extends m{static denormalize(e,t){return[e,!0]}}const y=e=>{const n={},r=b(e);return[function e(i,s){if(!s)return[i,!0];if(!s.denormalize||"function"!=typeof s.denormalize){if("function"==typeof s)return i instanceof s?[i,!0]:[new s(i),!0];if("object"==typeof s){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 p?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]}},g=(e,t,n,r,i,s)=>{if(!e||!r||!["function","object"].includes(typeof r))return e;if(!r.normalize||"function"!=typeof r.normalize){if("function"==typeof r)return new r(e);return(Array.isArray(r)?o:a)(r,e,t,n,g,i,s)}return r.normalize(e,t,n,g,i,s)};var O=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=m,e.FlatEntity=p,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,i]=y(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){if("production"!==process.env.NODE_ENV){const r=e=>{try{return"string"!=typeof JSON.parse(e)}catch(e){return!1}};throw"string"==typeof e&&r(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(t,void 0,2)}\n Input: "${e}"`):new Error(`Unexpected input given to normalize. Expected type to be "${n}", found "${null===e?"null":typeof e}".\n\n Schema: ${JSON.stringify(t,void 0,2)}\n Input: "${e}"`)}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(i,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:g(e,e,void 0,t,s,{})}},e.schema=O,Object.defineProperty(e,"__esModule",{value:!0})}));

@@ -33,2 +33,8 @@ import {

export type Serializable<
T extends { toJSON(): string } = { toJSON(): string }
> = {
prototype: T;
};
export interface SchemaSimple {

@@ -39,4 +45,4 @@ normalize(

key: any,
visit: Function,
addEntity: Function,
visit: (...args: any) => any,
addEntity: (...args: any) => any,
visitedEntities: Record<string, any>,

@@ -70,4 +76,4 @@ ): any;

key: any,
visit: Function,
addEntity: Function,
visit: (...args: any) => any,
addEntity: (...args: any) => any,
visitedEntities: Record<string, any>,

@@ -95,4 +101,4 @@ ): Normalize<S>[];

key: any,
visit: Function,
addEntity: Function,
visit: (...args: any) => any,
addEntity: (...args: any) => any,
visitedEntities: Record<string, any>,

@@ -127,4 +133,4 @@ ): NormalizeObject<O>;

key: any,
visit: Function,
addEntity: Function,
visit: (...args: any) => any,
addEntity: (...args: any) => any,
visitedEntities: Record<string, any>,

@@ -169,4 +175,4 @@ ): UnionResult<Choices>;

key: any,
visit: Function,
addEntity: Function,
visit: (...args: any) => any,
addEntity: (...args: any) => any,
visitedEntities: Record<string, any>,

@@ -173,0 +179,0 @@ ): Record<

@@ -30,3 +30,3 @@ import type { default as schema, EntityInterface } from './schema';

export interface RecordClass<T = any> extends NestedSchemaClass<T> {
fromJS: Function;
fromJS: (...args: any) => AbstractInstanceType<T>;
}

@@ -38,12 +38,12 @@ export declare type DenormalizeNullableNestedSchema<S extends NestedSchemaClass> = keyof S['schema'] extends never ? S['prototype'] : string extends keyof S['schema'] ? S['prototype'] : {

export declare type NormalizeReturnType<T> = T extends (...args: any) => infer R ? R : never;
export declare type Denormalize<S> = S extends EntityInterface<infer U> ? U : S extends RecordClass ? AbstractInstanceType<S> : S extends schema.SchemaClass ? DenormalizeReturnType<S['denormalize']> : S extends Array<infer F> ? Denormalize<F>[] : S extends {
export declare type Denormalize<S> = S extends EntityInterface<infer U> ? U : S extends RecordClass ? AbstractInstanceType<S> : S extends schema.SchemaClass ? DenormalizeReturnType<S['denormalize']> : S extends schema.Serializable<infer T> ? T : S extends Array<infer F> ? Denormalize<F>[] : S extends {
[K: string]: any;
} ? DenormalizeObject<S> : S;
export declare type DenormalizeNullable<S> = S extends EntityInterface<any> ? DenormalizeNullableNestedSchema<S> | undefined : S extends RecordClass ? DenormalizeNullableNestedSchema<S> : S extends schema.SchemaClass ? DenormalizeReturnType<S['_denormalizeNullable']> : S extends Array<infer F> ? Denormalize<F>[] | undefined : S extends {
export declare type DenormalizeNullable<S> = S extends EntityInterface<any> ? DenormalizeNullableNestedSchema<S> | undefined : S extends RecordClass ? DenormalizeNullableNestedSchema<S> : S extends schema.SchemaClass ? DenormalizeReturnType<S['_denormalizeNullable']> : S extends schema.Serializable<infer T> ? T : S extends Array<infer F> ? Denormalize<F>[] | undefined : S extends {
[K: string]: any;
} ? DenormalizeNullableObject<S> : S;
export declare type Normalize<S> = S extends EntityInterface ? string : S extends RecordClass ? NormalizeObject<S['schema']> : S extends schema.SchemaClass ? NormalizeReturnType<S['normalize']> : S extends Array<infer F> ? Normalize<F>[] : S extends {
export declare type Normalize<S> = S extends EntityInterface ? string : S extends RecordClass ? NormalizeObject<S['schema']> : S extends schema.SchemaClass ? NormalizeReturnType<S['normalize']> : S extends schema.Serializable<infer T> ? T : S extends Array<infer F> ? Normalize<F>[] : S extends {
[K: string]: any;
} ? NormalizeObject<S> : S;
export declare type NormalizeNullable<S> = S extends EntityInterface ? string | undefined : S extends RecordClass ? NormalizedNullableObject<S['schema']> : S extends schema.SchemaClass ? NormalizeReturnType<S['_normalizeNullable']> : S extends Array<infer F> ? Normalize<F>[] | undefined : S extends {
export declare type NormalizeNullable<S> = S extends EntityInterface ? string | undefined : S extends RecordClass ? NormalizedNullableObject<S['schema']> : S extends schema.SchemaClass ? NormalizeReturnType<S['_normalizeNullable']> : S extends schema.Serializable<infer T> ? T : S extends Array<infer F> ? Normalize<F>[] | undefined : S extends {
[K: string]: any;

@@ -53,3 +53,3 @@ } ? NormalizedNullableObject<S> : S;

[K: string]: any;
} | Schema[] | schema.SchemaSimple;
} | Schema[] | schema.SchemaSimple | schema.Serializable;
export declare type NormalizedIndex = {

@@ -56,0 +56,0 @@ readonly [entityKey: string]: {

{
"name": "@rest-hooks/normalizr",
"version": "6.0.0-beta.10",
"version": "6.0.0-beta.12",
"description": "Normalizes and denormalizes JSON according to schema for Redux and Flux applications",

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

},
"gitHead": "4bcd3a24cf20d69a9cb2705e74133490b07ff567"
"gitHead": "719ddbe9638d7bf0e8fd3d1da113202ac6aaa059"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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