New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@rest-hooks/normalizr

Package Overview
Dependencies
Maintainers
1
Versions
126
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rest-hooks/normalizr - npm Package Compare versions

Comparing version 6.0.0-i.1 to 6.0.0-j.0

8

CHANGELOG.md

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

## 6.0.0-j.0 (2020-07-27)
* fix: Make normalizr commonjs bundle transpile classes ([6812990](https://github.com/coinbase/rest-hooks/commit/6812990))
## 6.0.0-i.1 (2020-07-22)

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

821

dist/normalizr.amd.js

@@ -30,10 +30,14 @@ define(['exports'], function (exports) { 'use strict';

function denormalizeImmutable(schema, input, unvisit) {
let found = true;
let deleted = false;
return [Object.keys(schema).reduce((object, key) => {
var found = true;
var deleted = false;
return [Object.keys(schema).reduce(function (object, key) {
// Immutable maps cast keys to strings on write so we need to ensure
// we're accessing them using string keys.
const stringKey = `${key}`;
const [item, foundItem, deletedItem] = unvisit(object.get(stringKey), schema[stringKey]);
var stringKey = "" + key;
var _unvisit = unvisit(object.get(stringKey), schema[stringKey]),
item = _unvisit[0],
foundItem = _unvisit[1],
deletedItem = _unvisit[2];
if (!foundItem) {

@@ -55,6 +59,30 @@ found = false;

class PolymorphicSchema {
constructor(definition, schemaAttribute) {
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
var PolymorphicSchema = /*#__PURE__*/function () {
function PolymorphicSchema(definition, schemaAttribute) {
if (schemaAttribute) {
this._schemaAttribute = typeof schemaAttribute === 'string' ? input => input[schemaAttribute] : schemaAttribute;
this._schemaAttribute = typeof schemaAttribute === 'string' ? function (input) {
return input[schemaAttribute];
} : schemaAttribute;
}

@@ -65,15 +93,13 @@

get isSingleSchema() {
return !this._schemaAttribute;
}
var _proto = PolymorphicSchema.prototype;
define(definition) {
_proto.define = function define(definition) {
this.schema = definition;
}
};
getSchemaAttribute(input, parent, key) {
_proto.getSchemaAttribute = function getSchemaAttribute(input, parent, key) {
return !this.isSingleSchema && this._schemaAttribute(input, parent, key);
}
};
inferSchema(input, parent, key) {
_proto.inferSchema = function inferSchema(input, parent, key) {
if (this.isSingleSchema) {

@@ -83,8 +109,8 @@ return this.schema;

const attr = this.getSchemaAttribute(input, parent, key);
var attr = this.getSchemaAttribute(input, parent, key);
return this.schema[attr];
}
};
normalizeValue(value, parent, key, visit, addEntity, visitedEntities) {
const schema = this.inferSchema(value, parent, key);
_proto.normalizeValue = function normalizeValue(value, parent, key, visit, addEntity, visitedEntities) {
var schema = this.inferSchema(value, parent, key);

@@ -95,3 +121,3 @@ if (!schema) {

const normalizedValue = visit(value, parent, key, schema, addEntity, visitedEntities);
var normalizedValue = visit(value, parent, key, schema, addEntity, visitedEntities);
return this.isSingleSchema || normalizedValue === undefined || normalizedValue === null ? normalizedValue : {

@@ -101,6 +127,6 @@ id: normalizedValue,

};
}
};
denormalizeValue(value, unvisit) {
const schemaKey = isImmutable(value) ? value.get('schema') : value.schema;
_proto.denormalizeValue = function denormalizeValue(value, unvisit) {
var schemaKey = isImmutable(value) ? value.get('schema') : value.schema;

@@ -111,16 +137,24 @@ if (!this.isSingleSchema && !schemaKey) {

const id = this.isSingleSchema ? undefined : isImmutable(value) ? value.get('id') : value.id;
const schema = this.isSingleSchema ? this.schema : this.schema[schemaKey];
var id = this.isSingleSchema ? undefined : isImmutable(value) ? value.get('id') : value.id;
var schema = this.isSingleSchema ? this.schema : this.schema[schemaKey];
return unvisit(id || value, schema);
}
};
}
_createClass(PolymorphicSchema, [{
key: "isSingleSchema",
get: function get() {
return !this._schemaAttribute;
}
}]);
const DELETED = Symbol('ENTITY WAS DELETED');
return PolymorphicSchema;
}();
const validateSchema = definition => {
const isArray = Array.isArray(definition);
var DELETED = Symbol('ENTITY WAS DELETED');
var validateSchema = function validateSchema(definition) {
var isArray = Array.isArray(definition);
if (isArray && definition.length > 1) {
throw new Error(`Expected schema definition to be a single schema, but found ${definition.length}.`);
throw new Error("Expected schema definition to be a single schema, but found " + definition.length + ".");
}

@@ -131,49 +165,92 @@

const getValues = input => Array.isArray(input) ? input : Object.keys(input).map(key => input[key]);
var getValues = function getValues(input) {
return Array.isArray(input) ? input : Object.keys(input).map(function (key) {
return input[key];
});
};
const filterEmpty = ([, foundItem, deletedItem]) => foundItem && !deletedItem;
var filterEmpty = function filterEmpty(_ref) {
var foundItem = _ref[1],
deletedItem = _ref[2];
return foundItem && !deletedItem;
};
const normalize = (schema, input, parent, key, visit, addEntity, visitedEntities) => {
var normalize = function normalize(schema, input, parent, key, visit, addEntity, visitedEntities) {
schema = validateSchema(schema);
const values = getValues(input); // Special case: Arrays pass *their* parent on to their children, since there
var values = getValues(input); // Special case: Arrays pass *their* parent on to their children, since there
// is not any special information that can be gathered from themselves directly
return values.map((value, index) => visit(value, parent, key, schema, addEntity, visitedEntities));
return values.map(function (value, index) {
return visit(value, parent, key, schema, addEntity, visitedEntities);
});
};
const denormalize = (schema, input, unvisit) => {
var denormalize = function denormalize(schema, input, unvisit) {
schema = validateSchema(schema);
let deleted = false;
let found = true;
var deleted = false;
var found = true;
if (input === undefined && schema) {
[, found, deleted] = unvisit(undefined, schema);
var _unvisit = unvisit(undefined, schema);
found = _unvisit[1];
deleted = _unvisit[2];
}
return [input && input.map ? input.map(entityOrId => unvisit(entityOrId, schema)).filter(filterEmpty).map(([value]) => value) : input, found, deleted];
return [input && input.map ? input.map(function (entityOrId) {
return unvisit(entityOrId, schema);
}).filter(filterEmpty).map(function (_ref2) {
var value = _ref2[0];
return value;
}) : input, found, deleted];
};
class ArraySchema extends PolymorphicSchema {
normalize(input, parent, key, visit, addEntity, visitedEntities) {
const values = getValues(input);
return values.map((value, index) => this.normalizeValue(value, parent, key, visit, addEntity, visitedEntities)).filter(value => value !== undefined && value !== null);
var ArraySchema = /*#__PURE__*/function (_PolymorphicSchema) {
_inheritsLoose(ArraySchema, _PolymorphicSchema);
function ArraySchema() {
return _PolymorphicSchema.apply(this, arguments) || this;
}
denormalize(input, unvisit) {
let deleted = false;
let found = true;
var _proto = ArraySchema.prototype;
_proto.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {
var _this = this;
var values = getValues(input);
return values.map(function (value, index) {
return _this.normalizeValue(value, parent, key, visit, addEntity, visitedEntities);
}).filter(function (value) {
return value !== undefined && value !== null;
});
};
_proto.denormalize = function denormalize(input, unvisit) {
var _this2 = this;
var deleted = false;
var found = true;
if (input === undefined && this.schema) {
[, found, deleted] = unvisit(undefined, this.schema);
var _unvisit2 = unvisit(undefined, this.schema);
found = _unvisit2[1];
deleted = _unvisit2[2];
}
return [input && input.map ? input.map(entityOrId => this.denormalizeValue(entityOrId, unvisit)).filter(filterEmpty).map(([value]) => value) : input, found, deleted];
}
return [input && input.map ? input.map(function (entityOrId) {
return _this2.denormalizeValue(entityOrId, unvisit);
}).filter(filterEmpty).map(function (_ref3) {
var value = _ref3[0];
return value;
}) : input, found, deleted];
};
}
return ArraySchema;
}(PolymorphicSchema);
const normalize$1 = (schema, input, parent, key, visit, addEntity, visitedEntities) => {
const object = { ...input
};
Object.keys(schema).forEach(key => {
const localSchema = schema[key];
const value = visit(input[key], input, key, localSchema, addEntity, visitedEntities);
var _normalize = function normalize(schema, input, parent, key, visit, addEntity, visitedEntities) {
var object = Object.assign({}, input);
Object.keys(schema).forEach(function (key) {
var localSchema = schema[key];
var value = visit(input[key], input, key, localSchema, addEntity, visitedEntities);

@@ -188,3 +265,4 @@ if (value === undefined || value === null) {

};
const denormalize$1 = (schema, input, unvisit) => {
var _denormalize = function denormalize(schema, input, unvisit) {
if (isImmutable(input)) {

@@ -194,8 +272,10 @@ return denormalizeImmutable(schema, input, unvisit);

const object = { ...input
};
let found = true;
let deleted = false;
Object.keys(schema).forEach(key => {
const [item, foundItem, deletedItem] = unvisit(object[key], schema[key]);
var object = Object.assign({}, input);
var found = true;
var deleted = false;
Object.keys(schema).forEach(function (key) {
var _unvisit = unvisit(object[key], schema[key]),
item = _unvisit[0],
foundItem = _unvisit[1],
deletedItem = _unvisit[2];

@@ -216,38 +296,97 @@ if (object[key] !== undefined) {

};
class ObjectSchema {
constructor(definition) {
var ObjectSchema = /*#__PURE__*/function () {
function ObjectSchema(definition) {
this.define(definition);
}
define(definition) {
this.schema = Object.keys(definition).reduce((entitySchema, key) => {
const schema = definition[key];
return { ...entitySchema,
[key]: schema
};
var _proto = ObjectSchema.prototype;
_proto.define = function define(definition) {
this.schema = Object.keys(definition).reduce(function (entitySchema, key) {
var _Object$assign;
var schema = definition[key];
return Object.assign({}, entitySchema, (_Object$assign = {}, _Object$assign[key] = schema, _Object$assign));
}, this.schema || {});
}
};
normalize(...args) {
return normalize$1(this.schema, ...args);
_proto.normalize = function normalize() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _normalize.apply(void 0, [this.schema].concat(args));
};
_proto.denormalize = function denormalize() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return _denormalize.apply(void 0, [this.schema].concat(args));
};
return ObjectSchema;
}();
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) {
arr2[i] = arr[i];
}
denormalize(...args) {
return denormalize$1(this.schema, ...args);
return arr2;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
var it;
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
if (it) o = it;
var i = 0;
return function () {
if (i >= o.length) return {
done: true
};
return {
done: false,
value: o[i++]
};
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
it = o[Symbol.iterator]();
return it.next.bind(it);
}
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
const DefinedMembersKey = Symbol('Defined Members');
const UniqueIdentifierKey = Symbol('unq');
var DefinedMembersKey = Symbol('Defined Members');
var UniqueIdentifierKey = Symbol('unq');
/** Immutable record that keeps track of which members are defined vs defaults. */
class SimpleRecord {
toString() {
var SimpleRecord = /*#__PURE__*/function () {
function SimpleRecord() {}
var _proto = SimpleRecord.prototype;
_proto.toString = function toString() {
// we don't make _unq a member so it doesn't play a role in type compatibility
return this[UniqueIdentifierKey];
}
};
static toJSON() {
SimpleRecord.toJSON = function toJSON() {
return {

@@ -259,4 +398,4 @@ name: this.name,

/** Defines nested entities */
;
/** Factory method to convert from Plain JS Objects.

@@ -268,6 +407,10 @@ *

*/
static fromJS( // TODO: this should only accept members that are not functions
props = {}, parent, key) {
SimpleRecord.fromJS = function fromJS( // TODO: this should only accept members that are not functions
props, parent, key) {
if (props === void 0) {
props = {};
}
// we type guarded abstract case above, so ok to force typescript to allow constructor call
const instance = new this(props);
var instance = new this(props);

@@ -285,3 +428,3 @@ if (props instanceof SimpleRecord) {

Object.defineProperty(instance, UniqueIdentifierKey, {
value: `${Math.random()}`,
value: "" + Math.random(),
writable: false

@@ -292,21 +435,22 @@ });

/** Creates new instance copying over defined values of arguments */
;
static merge(existing, incoming) {
const props = Object.assign(this.toObjectDefined(existing), this.toObjectDefined(incoming));
SimpleRecord.merge = function merge(existing, incoming) {
var props = Object.assign(this.toObjectDefined(existing), this.toObjectDefined(incoming));
return this.fromJS(props);
}
/** Whether key is non-default */
;
static hasDefined(instance, key) {
SimpleRecord.hasDefined = function hasDefined(instance, key) {
return instance[DefinedMembersKey].includes(key);
}
/** Returns simple object with all the non-default members */
;
SimpleRecord.toObjectDefined = function toObjectDefined(instance) {
var defined = {};
static toObjectDefined(instance) {
const defined = {};
for (const member of instance[DefinedMembersKey]) {
for (var _iterator = _createForOfIteratorHelperLoose(instance[DefinedMembersKey]), _step; !(_step = _iterator()).done;) {
var member = _step.value;
defined[member] = instance[member];

@@ -318,21 +462,29 @@ }

/** Returns array of all keys that have values defined in instance */
;
static keysDefined(instance) {
SimpleRecord.keysDefined = function keysDefined(instance) {
return instance[DefinedMembersKey];
}
};
static normalize(...args) {
return normalize$1(this.schema, ...args);
}
SimpleRecord.normalize = function normalize() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
static denormalize(input, unvisit) {
return _normalize.apply(void 0, [this.schema].concat(args));
};
SimpleRecord.denormalize = function denormalize(input, unvisit) {
var _this = this;
// TODO: This creates unneeded memory pressure
const instance = new this();
const object = { ...input
};
let deleted = false;
let found = true;
Object.keys(this.schema).forEach(key => {
const [item, foundItem, deletedItem] = unvisit(object[key], this.schema[key]);
var instance = new this();
var object = Object.assign({}, input);
var deleted = false;
var found = true;
Object.keys(this.schema).forEach(function (key) {
var _unvisit = unvisit(object[key], _this.schema[key]),
item = _unvisit[0],
foundItem = _unvisit[1],
deletedItem = _unvisit[2];

@@ -357,5 +509,5 @@ if (object[key] !== undefined) {

/* istanbul ignore next */
;
static asSchema() {
SimpleRecord.asSchema = function asSchema() {
/* istanbul ignore next */

@@ -369,15 +521,21 @@ if (process.env.NODE_ENV === 'development') {

return this;
}
};
}
return SimpleRecord;
}();
SimpleRecord.schema = {};
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/** Represents data that should be deduped by specifying a primary key. */
var Entity = /*#__PURE__*/function (_SimpleRecord) {
_inheritsLoose(Entity, _SimpleRecord);
/** Represents data that should be deduped by specifying a primary key. */
class Entity extends SimpleRecord {
static toJSON() {
return { ...super.toJSON(),
function Entity() {
return _SimpleRecord.apply(this, arguments) || this;
}
Entity.toJSON = function toJSON() {
return Object.assign({}, _SimpleRecord.toJSON.call(this), {
key: this.key
};
});
}

@@ -390,13 +548,4 @@ /**

*/
;
/** Returns the globally unique identifier for the static Entity */
static get key() {
/* istanbul ignore next */
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;
}
/** Defines indexes to enable lookup by */
/**

@@ -409,20 +558,27 @@ * A unique identifier for each Entity

*/
static pk(value, parent, key) {
Entity.pk = function pk(value, parent, key) {
return this.prototype.pk.call(value, parent, key) || key;
}
};
static normalize(input, parent, key, visit, addEntity, visitedEntities) {
Entity.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {
var _this = this;
// 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);
var processedEntity = this.fromJS(input, parent, key);
/* istanbul ignore else */
if (process.env.NODE_ENV !== 'production') {
const instanceSample = new this();
const keysOfRecord = new Set(Object.keys(instanceSample));
const keysOfProps = this.keysDefined(processedEntity);
const [found, missing, unexpected] = [[], [], []];
var instanceSample = new this();
var keysOfRecord = new Set(Object.keys(instanceSample));
var keysOfProps = this.keysDefined(processedEntity);
var _ref = [[], [], []],
found = _ref[0],
missing = _ref[1],
unexpected = _ref[2];
for (const keyOfProps of keysOfProps) {
for (var _iterator = _createForOfIteratorHelperLoose(keysOfProps), _step; !(_step = _iterator()).done;) {
var keyOfProps = _step.value;
if (keysOfRecord.has(keyOfProps)) {

@@ -435,3 +591,5 @@ found.push(keyOfProps);

for (const keyOfRecord of keysOfRecord) {
for (var _iterator2 = _createForOfIteratorHelperLoose(keysOfRecord), _step2; !(_step2 = _iterator2()).done;) {
var keyOfRecord = _step2.value;
if (!found.includes(keyOfRecord)) {

@@ -444,12 +602,3 @@ missing.push(keyOfRecord);

if ((Math.max(keysOfProps.length / 2, 1) <= unexpected.length && keysOfRecord.size > Math.max(unexpected.length, 2) || found.length < Math.min(1, keysOfRecord.size / 2)) && keysOfRecord.size) {
const error = new Error(`Attempted to initialize ${this.name} with substantially different than expected keys
This is likely due to a malformed response.
Try inspecting the network response or fetch() return value.
Expected keys:
Found: ${found}
Missing: ${missing}
Unexpected keys: ${unexpected}
Value: ${JSON.stringify(this.toObjectDefined(processedEntity), null, 2)}`);
var error = 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: " + found + "\n Missing: " + missing + "\n Unexpected keys: " + unexpected + "\n Value: " + JSON.stringify(this.toObjectDefined(processedEntity), null, 2));
error.status = 400;

@@ -460,16 +609,10 @@ throw error;

const id = processedEntity.pk(parent, key);
var id = processedEntity.pk(parent, key);
if (id === undefined || id === '') {
if (process.env.NODE_ENV !== 'production') {
const error = new Error(`Missing usable resource key when normalizing response.
var _error = 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: " + (input && JSON.stringify(input, null, 2)) + "\n ");
This is likely due to a malformed response.
Try inspecting the network response or fetch() return value.
Entity: ${this.name}
Value: ${input && JSON.stringify(input, null, 2)}
`);
error.status = 400;
throw error;
_error.status = 400;
throw _error;
} else {

@@ -481,3 +624,3 @@ // these make the keys get deleted

const entityType = this.key;
var entityType = this.key;

@@ -492,3 +635,5 @@ if (!(entityType in visitedEntities)) {

if (visitedEntities[entityType][id].some(entity => entity === input)) {
if (visitedEntities[entityType][id].some(function (entity) {
return entity === input;
})) {
return id;

@@ -498,6 +643,6 @@ }

visitedEntities[entityType][id].push(input);
Object.keys(this.schema).forEach(key => {
Object.keys(this.schema).forEach(function (key) {
if (Object.hasOwnProperty.call(processedEntity, key)) {
const schema = this.schema[key];
processedEntity[key] = visit(processedEntity[key], processedEntity, key, schema, addEntity, visitedEntities);
var _schema = _this.schema[key];
processedEntity[key] = visit(processedEntity[key], processedEntity, key, _schema, addEntity, visitedEntities);
}

@@ -507,23 +652,34 @@ });

return id;
}
};
static denormalize(entity, unvisit) {
Entity.denormalize = function denormalize(entity, unvisit) {
var _this2 = this;
// 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, deleted] = denormalizeImmutable(this.schema, entity, unvisit);
return [this.fromJS(denormEntity.toObject()), found, deleted];
var _denormalizeImmutable = denormalizeImmutable(this.schema, entity, unvisit),
_denormEntity = _denormalizeImmutable[0],
_found = _denormalizeImmutable[1],
_deleted = _denormalizeImmutable[2];
return [this.fromJS(_denormEntity.toObject()), _found, _deleted];
} // TODO: This creates unneeded memory pressure
const instance = new this();
let deleted = false;
let found = true;
const denormEntity = entity;
Object.keys(this.schema).forEach(key => {
const schema = this.schema[key];
const input = this.hasDefined(entity, key) ? entity[key] : undefined;
const [value, foundItem, deletedItem] = unvisit(input, schema); // members who default to falsy values are considered 'optional'
var instance = new this();
var deleted = false;
var found = true;
var denormEntity = entity;
Object.keys(this.schema).forEach(function (key) {
var schema = _this2.schema[key];
var input = _this2.hasDefined(entity, key) ? entity[key] : undefined;
var _unvisit = unvisit(input, schema),
value = _unvisit[0],
foundItem = _unvisit[1],
deletedItem = _unvisit[2]; // 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])) {

@@ -537,3 +693,3 @@ found = false;

if (this.hasDefined(entity, key) && denormEntity[key] !== value) {
if (_this2.hasDefined(entity, key) && denormEntity[key] !== value) {
denormEntity[key] = value;

@@ -543,6 +699,20 @@ }

return [denormEntity, found, deleted];
}
};
}
_createClass(Entity, null, [{
key: "key",
/** Returns the globally unique identifier for the static Entity */
get: function get() {
/* istanbul ignore next */
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;
}
/** Defines indexes to enable lookup by */
}]);
return Entity;
}(SimpleRecord);
if (process.env.NODE_ENV !== 'production') {

@@ -561,12 +731,19 @@ // for those not using TypeScript this is a good catch to ensure they are defining

class FlatEntity extends Entity {
static denormalize(entity, unvisit) {
return [entity, true, false];
var FlatEntity = /*#__PURE__*/function (_Entity) {
_inheritsLoose(FlatEntity, _Entity);
function FlatEntity() {
return _Entity.apply(this, arguments) || this;
}
}
FlatEntity.denormalize = function denormalize(entity, unvisit) {
return [entity, true, false];
};
const unvisitEntity = (id, schema, unvisit, getEntity, cache) => {
const entity = getEntity(id, schema);
return FlatEntity;
}(Entity);
var unvisitEntity = function unvisitEntity(id, schema, unvisit, getEntity, cache) {
var entity = getEntity(id, schema);
if (entity === DELETED) {

@@ -584,12 +761,17 @@ return [undefined, true, true];

let found = true;
let deleted = false;
var found = true;
var deleted = false;
if (!cache[schema.key][id]) {
// Ensure we don't mutate it non-immutable objects
const entityCopy = isImmutable(entity) || entity instanceof FlatEntity ? entity : schema.fromJS(entity); // Need to set this first so that if it is referenced further within the
var entityCopy = isImmutable(entity) || entity instanceof FlatEntity ? entity : schema.fromJS(entity); // Need to set this first so that if it is referenced further within the
// denormalization the reference will already exist.
cache[schema.key][id] = entityCopy;
[cache[schema.key][id], found, deleted] = schema.denormalize(entityCopy, unvisit);
var _schema$denormalize = schema.denormalize(entityCopy, unvisit);
cache[schema.key][id] = _schema$denormalize[0];
found = _schema$denormalize[1];
deleted = _schema$denormalize[2];
}

@@ -600,5 +782,5 @@

const getUnvisit = entities => {
const cache = {};
const getEntity = getEntities(entities);
var getUnvisit = function getUnvisit(entities) {
var cache = {};
var getEntity = getEntities(entities);
return [function unvisit(input, schema) {

@@ -612,3 +794,3 @@ if (!schema) return [input, true, false];

} else if (typeof schema === 'object') {
const method = Array.isArray(schema) ? denormalize : denormalize$1;
var method = Array.isArray(schema) ? denormalize : _denormalize;
return method(schema, input, unvisit);

@@ -640,6 +822,6 @@ }

const getEntities = entities => {
const isImmutable$1 = isImmutable(entities);
return (entityOrId, schema) => {
const schemaKey = schema.key;
var getEntities = function getEntities(entities) {
var isImmutable$1 = isImmutable(entities);
return function (entityOrId, schema) {
var schemaKey = schema.key;

@@ -659,3 +841,3 @@ if (typeof entityOrId === 'object') {

const denormalize$2 = (input, schema, entities) => {
var denormalize$1 = function denormalize(input, schema, entities) {
/* istanbul ignore next */

@@ -665,4 +847,7 @@ if (process.env.NODE_ENV !== 'production' && schema === undefined) throw new Error('schema needed');

if (typeof input !== 'undefined') {
const [unvisit, cache] = getUnvisit(entities);
return [...unvisit(input, schema), cache];
var _getUnvisit = getUnvisit(entities),
unvisit = _getUnvisit[0],
cache = _getUnvisit[1];
return [].concat(unvisit(input, schema), [cache]);
}

@@ -673,3 +858,3 @@

const visit = (value, parent, key, schema, addEntity, visitedEntities) => {
var visit = function visit(value, parent, key, schema, addEntity, visitedEntities) {
if (!value || !schema || !['function', 'object'].includes(typeof schema)) {

@@ -685,3 +870,3 @@ return value;

const method = Array.isArray(schema) ? normalize : normalize$1;
var method = Array.isArray(schema) ? normalize : _normalize;
return method(schema, value, parent, key, visit, addEntity, visitedEntities);

@@ -693,49 +878,51 @@ }

const addEntities = (entities, indexes) => (schema, processedEntity, value, parent, key) => {
const schemaKey = schema.key;
const id = schema.pk(value, parent, key);
var addEntities = function addEntities(entities, indexes) {
return function (schema, processedEntity, value, parent, key) {
var schemaKey = schema.key;
var id = schema.pk(value, parent, key);
if (!(schemaKey in entities)) {
entities[schemaKey] = {};
}
if (!(schemaKey in entities)) {
entities[schemaKey] = {};
}
const existingEntity = entities[schemaKey][id];
var existingEntity = entities[schemaKey][id];
if (existingEntity) {
entities[schemaKey][id] = schema.merge(existingEntity, processedEntity);
} else {
entities[schemaKey][id] = processedEntity;
} // update index
if (existingEntity) {
entities[schemaKey][id] = schema.merge(existingEntity, processedEntity);
} else {
entities[schemaKey][id] = processedEntity;
} // update index
if (Array.isArray(schema.indexes)) {
const entity = entities[schemaKey][id];
if (Array.isArray(schema.indexes)) {
var entity = entities[schemaKey][id];
if (!(schemaKey in indexes)) {
indexes[schemaKey] = {};
}
for (const index of schema.indexes) {
if (!(index in indexes[schemaKey])) {
indexes[schemaKey][index] = {};
if (!(schemaKey in indexes)) {
indexes[schemaKey] = {};
}
const indexMap = indexes[schemaKey][index];
for (var _iterator = _createForOfIteratorHelperLoose(schema.indexes), _step; !(_step = _iterator()).done;) {
var index = _step.value;
if (existingEntity) {
delete indexMap[existingEntity[index]];
}
if (!(index in indexes[schemaKey])) {
indexes[schemaKey][index] = {};
}
if (index in entity) {
indexMap[entity[index]] = id;
var indexMap = indexes[schemaKey][index];
if (existingEntity) {
delete indexMap[existingEntity[index]];
}
if (index in entity) {
indexMap[entity[index]] = id;
}
/* istanbul ignore next */
else if ( // eslint-disable-next-line no-undef
process.env.NODE_ENV !== 'production') {
console.warn("Index not found in entity. Indexes must be top-level members of your entity.\nIndex: " + index + "\nEntity: " + JSON.stringify(entity, undefined, 2));
}
}
/* istanbul ignore next */
else if ( // eslint-disable-next-line no-undef
process.env.NODE_ENV !== 'production') {
console.warn(`Index not found in entity. Indexes must be top-level members of your entity.
Index: ${index}
Entity: ${JSON.stringify(entity, undefined, 2)}`);
}
}
}
};
};

@@ -748,4 +935,4 @@

const normalize$2 = (input, schema) => {
const schemaType = expectedSchemaType(schema);
var normalize$1 = function normalize(input, schema) {
var schemaType = expectedSchemaType(schema);

@@ -755,3 +942,3 @@ if (input === null || typeof input !== schemaType) {

if (process.env.NODE_ENV !== 'production') {
const parseWorks = input => {
var parseWorks = function parseWorks(input) {
try {

@@ -765,35 +952,27 @@ return typeof JSON.parse(input) !== 'string';

if (typeof input === 'string' && parseWorks(input)) {
throw new Error(`Normalizing a string, but this does match schema.
Parsing this input string as JSON worked. This likely indicates fetch function did not parse
the JSON. By default, this only happens if "content-type" header includes "json".
See https://resthooks.io/docs/guides/custom-networking for more information
Schema: ${JSON.stringify(schema, undefined, 2)}
Input: "${input}"`);
throw 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(schema, undefined, 2) + "\n Input: \"" + input + "\"");
} else {
throw new Error(`Unexpected input given to normalize. Expected type to be "${schemaType}", found "${input === null ? 'null' : typeof input}".
Schema: ${JSON.stringify(schema, undefined, 2)}
Input: "${input}"`);
throw new Error("Unexpected input given to normalize. Expected type to be \"" + schemaType + "\", found \"" + (input === null ? 'null' : typeof input) + "\".\n\n Schema: " + JSON.stringify(schema, undefined, 2) + "\n Input: \"" + input + "\"");
}
} else {
throw new Error(`Unexpected input given to normalize. Expected type to be "${schemaType}", found "${input === null ? 'null' : typeof input}".`);
throw new Error("Unexpected input given to normalize. Expected type to be \"" + schemaType + "\", found \"" + (input === null ? 'null' : typeof input) + "\".");
}
}
const entities = {};
const indexes = {};
const addEntity = addEntities(entities, indexes);
const visitedEntities = {};
const result = visit(input, input, undefined, schema, addEntity, visitedEntities);
var entities = {};
var indexes = {};
var addEntity = addEntities(entities, indexes);
var visitedEntities = {};
var result = visit(input, input, undefined, schema, addEntity, visitedEntities);
return {
entities,
indexes,
result
entities: entities,
indexes: indexes,
result: result
};
};
class UnionSchema extends PolymorphicSchema {
constructor(definition, schemaAttribute) {
var UnionSchema = /*#__PURE__*/function (_PolymorphicSchema) {
_inheritsLoose(UnionSchema, _PolymorphicSchema);
function UnionSchema(definition, schemaAttribute) {
if (!schemaAttribute) {

@@ -803,32 +982,53 @@ throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');

super(definition, schemaAttribute);
return _PolymorphicSchema.call(this, definition, schemaAttribute) || this;
}
normalize(input, parent, key, visit, addEntity, visitedEntities) {
var _proto = UnionSchema.prototype;
_proto.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {
return this.normalizeValue(input, parent, key, visit, addEntity, visitedEntities);
}
};
denormalize(input, unvisit) {
_proto.denormalize = function denormalize(input, unvisit) {
return this.denormalizeValue(input, unvisit);
};
return UnionSchema;
}(PolymorphicSchema);
var ValuesSchema = /*#__PURE__*/function (_PolymorphicSchema) {
_inheritsLoose(ValuesSchema, _PolymorphicSchema);
function ValuesSchema() {
return _PolymorphicSchema.apply(this, arguments) || this;
}
}
var _proto = ValuesSchema.prototype;
class ValuesSchema extends PolymorphicSchema {
normalize(input, parent, key, visit, addEntity, visitedEntities) {
return Object.keys(input).reduce((output, key, index) => {
const value = input[key];
return value !== undefined && value !== null ? { ...output,
[key]: this.normalizeValue(value, input, key, visit, addEntity, visitedEntities)
} : output;
_proto.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {
var _this = this;
return Object.keys(input).reduce(function (output, key, index) {
var _Object$assign;
var value = input[key];
return value !== undefined && value !== null ? Object.assign({}, output, (_Object$assign = {}, _Object$assign[key] = _this.normalizeValue(value, input, key, visit, addEntity, visitedEntities), _Object$assign)) : output;
}, {});
}
};
denormalize(input, unvisit) {
let found = true;
let deleted = false;
return [Object.keys(input).reduce((output, key) => {
const entityOrId = input[key];
const [value, foundItem, deletedItem] = this.denormalizeValue(entityOrId, unvisit);
_proto.denormalize = function denormalize(input, unvisit) {
var _this2 = this;
var found = true;
var deleted = false;
return [Object.keys(input).reduce(function (output, key) {
var _Object$assign2;
var entityOrId = input[key];
var _this2$denormalizeVal = _this2.denormalizeValue(entityOrId, unvisit),
value = _this2$denormalizeVal[0],
foundItem = _this2$denormalizeVal[1],
deletedItem = _this2$denormalizeVal[2];
if (!foundItem) {

@@ -843,13 +1043,13 @@ found = false;

if (!foundItem || deletedItem) return output;
return { ...output,
[key]: value
};
return Object.assign({}, output, (_Object$assign2 = {}, _Object$assign2[key] = value, _Object$assign2));
}, {}), found, deleted];
}
};
}
return ValuesSchema;
}(PolymorphicSchema);
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
class Delete {
constructor(entity) {
var Delete = /*#__PURE__*/function () {
function Delete(entity) {
if (process.env.NODE_ENV !== 'production' && !entity) {

@@ -862,36 +1062,39 @@ throw new Error('Expected option "entity" not found on DeleteSchema.');

normalize(input, parent, key, visit, addEntity, visitedEntities) {
var _proto = Delete.prototype;
_proto.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {
// 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._entity.fromJS(input, parent, key);
var processedEntity = this._entity.fromJS(input, parent, key);
const id = processedEntity.pk(parent, key);
var id = processedEntity.pk(parent, key);
addEntity(this._entity, DELETED, processedEntity, parent, key);
return id;
}
};
denormalize(id, unvisit) {
_proto.denormalize = function denormalize(id, unvisit) {
return unvisit(id, this._entity);
}
/* istanbul ignore next */
;
_denormalizeNullable() {
_proto._denormalizeNullable = function _denormalizeNullable() {
return [];
}
/* istanbul ignore next */
;
_normalizeNullable() {
_proto._normalizeNullable = function _normalizeNullable() {
return [];
}
/* istanbul ignore next */
;
merge(existing, incoming) {
_proto.merge = function merge(existing, incoming) {
return incoming;
}
};
}
return Delete;
}();

@@ -913,5 +1116,5 @@ /* istanbul ignore file */

exports.SimpleRecord = SimpleRecord;
exports.denormalize = denormalize$2;
exports.denormalize = denormalize$1;
exports.isEntity = isEntity;
exports.normalize = normalize$2;
exports.normalize = normalize$1;
exports.schema = schema;

@@ -918,0 +1121,0 @@

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

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

@@ -31,10 +31,14 @@ var rest_hooks_normalizr = (function (exports) {

function denormalizeImmutable(schema, input, unvisit) {
let found = true;
let deleted = false;
return [Object.keys(schema).reduce((object, key) => {
var found = true;
var deleted = false;
return [Object.keys(schema).reduce(function (object, key) {
// Immutable maps cast keys to strings on write so we need to ensure
// we're accessing them using string keys.
const stringKey = `${key}`;
const [item, foundItem, deletedItem] = unvisit(object.get(stringKey), schema[stringKey]);
var stringKey = "" + key;
var _unvisit = unvisit(object.get(stringKey), schema[stringKey]),
item = _unvisit[0],
foundItem = _unvisit[1],
deletedItem = _unvisit[2];
if (!foundItem) {

@@ -56,6 +60,30 @@ found = false;

class PolymorphicSchema {
constructor(definition, schemaAttribute) {
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
var PolymorphicSchema = /*#__PURE__*/function () {
function PolymorphicSchema(definition, schemaAttribute) {
if (schemaAttribute) {
this._schemaAttribute = typeof schemaAttribute === 'string' ? input => input[schemaAttribute] : schemaAttribute;
this._schemaAttribute = typeof schemaAttribute === 'string' ? function (input) {
return input[schemaAttribute];
} : schemaAttribute;
}

@@ -66,15 +94,13 @@

get isSingleSchema() {
return !this._schemaAttribute;
}
var _proto = PolymorphicSchema.prototype;
define(definition) {
_proto.define = function define(definition) {
this.schema = definition;
}
};
getSchemaAttribute(input, parent, key) {
_proto.getSchemaAttribute = function getSchemaAttribute(input, parent, key) {
return !this.isSingleSchema && this._schemaAttribute(input, parent, key);
}
};
inferSchema(input, parent, key) {
_proto.inferSchema = function inferSchema(input, parent, key) {
if (this.isSingleSchema) {

@@ -84,8 +110,8 @@ return this.schema;

const attr = this.getSchemaAttribute(input, parent, key);
var attr = this.getSchemaAttribute(input, parent, key);
return this.schema[attr];
}
};
normalizeValue(value, parent, key, visit, addEntity, visitedEntities) {
const schema = this.inferSchema(value, parent, key);
_proto.normalizeValue = function normalizeValue(value, parent, key, visit, addEntity, visitedEntities) {
var schema = this.inferSchema(value, parent, key);

@@ -96,3 +122,3 @@ if (!schema) {

const normalizedValue = visit(value, parent, key, schema, addEntity, visitedEntities);
var normalizedValue = visit(value, parent, key, schema, addEntity, visitedEntities);
return this.isSingleSchema || normalizedValue === undefined || normalizedValue === null ? normalizedValue : {

@@ -102,6 +128,6 @@ id: normalizedValue,

};
}
};
denormalizeValue(value, unvisit) {
const schemaKey = isImmutable(value) ? value.get('schema') : value.schema;
_proto.denormalizeValue = function denormalizeValue(value, unvisit) {
var schemaKey = isImmutable(value) ? value.get('schema') : value.schema;

@@ -112,16 +138,24 @@ if (!this.isSingleSchema && !schemaKey) {

const id = this.isSingleSchema ? undefined : isImmutable(value) ? value.get('id') : value.id;
const schema = this.isSingleSchema ? this.schema : this.schema[schemaKey];
var id = this.isSingleSchema ? undefined : isImmutable(value) ? value.get('id') : value.id;
var schema = this.isSingleSchema ? this.schema : this.schema[schemaKey];
return unvisit(id || value, schema);
}
};
}
_createClass(PolymorphicSchema, [{
key: "isSingleSchema",
get: function get() {
return !this._schemaAttribute;
}
}]);
const DELETED = Symbol('ENTITY WAS DELETED');
return PolymorphicSchema;
}();
const validateSchema = definition => {
const isArray = Array.isArray(definition);
var DELETED = Symbol('ENTITY WAS DELETED');
var validateSchema = function validateSchema(definition) {
var isArray = Array.isArray(definition);
if (isArray && definition.length > 1) {
throw new Error(`Expected schema definition to be a single schema, but found ${definition.length}.`);
throw new Error("Expected schema definition to be a single schema, but found " + definition.length + ".");
}

@@ -132,49 +166,92 @@

const getValues = input => Array.isArray(input) ? input : Object.keys(input).map(key => input[key]);
var getValues = function getValues(input) {
return Array.isArray(input) ? input : Object.keys(input).map(function (key) {
return input[key];
});
};
const filterEmpty = ([, foundItem, deletedItem]) => foundItem && !deletedItem;
var filterEmpty = function filterEmpty(_ref) {
var foundItem = _ref[1],
deletedItem = _ref[2];
return foundItem && !deletedItem;
};
const normalize = (schema, input, parent, key, visit, addEntity, visitedEntities) => {
var normalize = function normalize(schema, input, parent, key, visit, addEntity, visitedEntities) {
schema = validateSchema(schema);
const values = getValues(input); // Special case: Arrays pass *their* parent on to their children, since there
var values = getValues(input); // Special case: Arrays pass *their* parent on to their children, since there
// is not any special information that can be gathered from themselves directly
return values.map((value, index) => visit(value, parent, key, schema, addEntity, visitedEntities));
return values.map(function (value, index) {
return visit(value, parent, key, schema, addEntity, visitedEntities);
});
};
const denormalize = (schema, input, unvisit) => {
var denormalize = function denormalize(schema, input, unvisit) {
schema = validateSchema(schema);
let deleted = false;
let found = true;
var deleted = false;
var found = true;
if (input === undefined && schema) {
[, found, deleted] = unvisit(undefined, schema);
var _unvisit = unvisit(undefined, schema);
found = _unvisit[1];
deleted = _unvisit[2];
}
return [input && input.map ? input.map(entityOrId => unvisit(entityOrId, schema)).filter(filterEmpty).map(([value]) => value) : input, found, deleted];
return [input && input.map ? input.map(function (entityOrId) {
return unvisit(entityOrId, schema);
}).filter(filterEmpty).map(function (_ref2) {
var value = _ref2[0];
return value;
}) : input, found, deleted];
};
class ArraySchema extends PolymorphicSchema {
normalize(input, parent, key, visit, addEntity, visitedEntities) {
const values = getValues(input);
return values.map((value, index) => this.normalizeValue(value, parent, key, visit, addEntity, visitedEntities)).filter(value => value !== undefined && value !== null);
var ArraySchema = /*#__PURE__*/function (_PolymorphicSchema) {
_inheritsLoose(ArraySchema, _PolymorphicSchema);
function ArraySchema() {
return _PolymorphicSchema.apply(this, arguments) || this;
}
denormalize(input, unvisit) {
let deleted = false;
let found = true;
var _proto = ArraySchema.prototype;
_proto.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {
var _this = this;
var values = getValues(input);
return values.map(function (value, index) {
return _this.normalizeValue(value, parent, key, visit, addEntity, visitedEntities);
}).filter(function (value) {
return value !== undefined && value !== null;
});
};
_proto.denormalize = function denormalize(input, unvisit) {
var _this2 = this;
var deleted = false;
var found = true;
if (input === undefined && this.schema) {
[, found, deleted] = unvisit(undefined, this.schema);
var _unvisit2 = unvisit(undefined, this.schema);
found = _unvisit2[1];
deleted = _unvisit2[2];
}
return [input && input.map ? input.map(entityOrId => this.denormalizeValue(entityOrId, unvisit)).filter(filterEmpty).map(([value]) => value) : input, found, deleted];
}
return [input && input.map ? input.map(function (entityOrId) {
return _this2.denormalizeValue(entityOrId, unvisit);
}).filter(filterEmpty).map(function (_ref3) {
var value = _ref3[0];
return value;
}) : input, found, deleted];
};
}
return ArraySchema;
}(PolymorphicSchema);
const normalize$1 = (schema, input, parent, key, visit, addEntity, visitedEntities) => {
const object = { ...input
};
Object.keys(schema).forEach(key => {
const localSchema = schema[key];
const value = visit(input[key], input, key, localSchema, addEntity, visitedEntities);
var _normalize = function normalize(schema, input, parent, key, visit, addEntity, visitedEntities) {
var object = Object.assign({}, input);
Object.keys(schema).forEach(function (key) {
var localSchema = schema[key];
var value = visit(input[key], input, key, localSchema, addEntity, visitedEntities);

@@ -189,3 +266,4 @@ if (value === undefined || value === null) {

};
const denormalize$1 = (schema, input, unvisit) => {
var _denormalize = function denormalize(schema, input, unvisit) {
if (isImmutable(input)) {

@@ -195,8 +273,10 @@ return denormalizeImmutable(schema, input, unvisit);

const object = { ...input
};
let found = true;
let deleted = false;
Object.keys(schema).forEach(key => {
const [item, foundItem, deletedItem] = unvisit(object[key], schema[key]);
var object = Object.assign({}, input);
var found = true;
var deleted = false;
Object.keys(schema).forEach(function (key) {
var _unvisit = unvisit(object[key], schema[key]),
item = _unvisit[0],
foundItem = _unvisit[1],
deletedItem = _unvisit[2];

@@ -217,38 +297,97 @@ if (object[key] !== undefined) {

};
class ObjectSchema {
constructor(definition) {
var ObjectSchema = /*#__PURE__*/function () {
function ObjectSchema(definition) {
this.define(definition);
}
define(definition) {
this.schema = Object.keys(definition).reduce((entitySchema, key) => {
const schema = definition[key];
return { ...entitySchema,
[key]: schema
};
var _proto = ObjectSchema.prototype;
_proto.define = function define(definition) {
this.schema = Object.keys(definition).reduce(function (entitySchema, key) {
var _Object$assign;
var schema = definition[key];
return Object.assign({}, entitySchema, (_Object$assign = {}, _Object$assign[key] = schema, _Object$assign));
}, this.schema || {});
}
};
normalize(...args) {
return normalize$1(this.schema, ...args);
_proto.normalize = function normalize() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _normalize.apply(void 0, [this.schema].concat(args));
};
_proto.denormalize = function denormalize() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return _denormalize.apply(void 0, [this.schema].concat(args));
};
return ObjectSchema;
}();
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) {
arr2[i] = arr[i];
}
denormalize(...args) {
return denormalize$1(this.schema, ...args);
return arr2;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
var it;
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
if (it) o = it;
var i = 0;
return function () {
if (i >= o.length) return {
done: true
};
return {
done: false,
value: o[i++]
};
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
it = o[Symbol.iterator]();
return it.next.bind(it);
}
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
const DefinedMembersKey = Symbol('Defined Members');
const UniqueIdentifierKey = Symbol('unq');
var DefinedMembersKey = Symbol('Defined Members');
var UniqueIdentifierKey = Symbol('unq');
/** Immutable record that keeps track of which members are defined vs defaults. */
class SimpleRecord {
toString() {
var SimpleRecord = /*#__PURE__*/function () {
function SimpleRecord() {}
var _proto = SimpleRecord.prototype;
_proto.toString = function toString() {
// we don't make _unq a member so it doesn't play a role in type compatibility
return this[UniqueIdentifierKey];
}
};
static toJSON() {
SimpleRecord.toJSON = function toJSON() {
return {

@@ -260,4 +399,4 @@ name: this.name,

/** Defines nested entities */
;
/** Factory method to convert from Plain JS Objects.

@@ -269,6 +408,10 @@ *

*/
static fromJS( // TODO: this should only accept members that are not functions
props = {}, parent, key) {
SimpleRecord.fromJS = function fromJS( // TODO: this should only accept members that are not functions
props, parent, key) {
if (props === void 0) {
props = {};
}
// we type guarded abstract case above, so ok to force typescript to allow constructor call
const instance = new this(props);
var instance = new this(props);

@@ -286,3 +429,3 @@ if (props instanceof SimpleRecord) {

Object.defineProperty(instance, UniqueIdentifierKey, {
value: `${Math.random()}`,
value: "" + Math.random(),
writable: false

@@ -293,21 +436,22 @@ });

/** Creates new instance copying over defined values of arguments */
;
static merge(existing, incoming) {
const props = Object.assign(this.toObjectDefined(existing), this.toObjectDefined(incoming));
SimpleRecord.merge = function merge(existing, incoming) {
var props = Object.assign(this.toObjectDefined(existing), this.toObjectDefined(incoming));
return this.fromJS(props);
}
/** Whether key is non-default */
;
static hasDefined(instance, key) {
SimpleRecord.hasDefined = function hasDefined(instance, key) {
return instance[DefinedMembersKey].includes(key);
}
/** Returns simple object with all the non-default members */
;
SimpleRecord.toObjectDefined = function toObjectDefined(instance) {
var defined = {};
static toObjectDefined(instance) {
const defined = {};
for (const member of instance[DefinedMembersKey]) {
for (var _iterator = _createForOfIteratorHelperLoose(instance[DefinedMembersKey]), _step; !(_step = _iterator()).done;) {
var member = _step.value;
defined[member] = instance[member];

@@ -319,21 +463,29 @@ }

/** Returns array of all keys that have values defined in instance */
;
static keysDefined(instance) {
SimpleRecord.keysDefined = function keysDefined(instance) {
return instance[DefinedMembersKey];
}
};
static normalize(...args) {
return normalize$1(this.schema, ...args);
}
SimpleRecord.normalize = function normalize() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
static denormalize(input, unvisit) {
return _normalize.apply(void 0, [this.schema].concat(args));
};
SimpleRecord.denormalize = function denormalize(input, unvisit) {
var _this = this;
// TODO: This creates unneeded memory pressure
const instance = new this();
const object = { ...input
};
let deleted = false;
let found = true;
Object.keys(this.schema).forEach(key => {
const [item, foundItem, deletedItem] = unvisit(object[key], this.schema[key]);
var instance = new this();
var object = Object.assign({}, input);
var deleted = false;
var found = true;
Object.keys(this.schema).forEach(function (key) {
var _unvisit = unvisit(object[key], _this.schema[key]),
item = _unvisit[0],
foundItem = _unvisit[1],
deletedItem = _unvisit[2];

@@ -358,5 +510,5 @@ if (object[key] !== undefined) {

/* istanbul ignore next */
;
static asSchema() {
SimpleRecord.asSchema = function asSchema() {
/* istanbul ignore next */

@@ -370,15 +522,21 @@ if (process.env.NODE_ENV === 'development') {

return this;
}
};
}
return SimpleRecord;
}();
SimpleRecord.schema = {};
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/** Represents data that should be deduped by specifying a primary key. */
var Entity = /*#__PURE__*/function (_SimpleRecord) {
_inheritsLoose(Entity, _SimpleRecord);
/** Represents data that should be deduped by specifying a primary key. */
class Entity extends SimpleRecord {
static toJSON() {
return { ...super.toJSON(),
function Entity() {
return _SimpleRecord.apply(this, arguments) || this;
}
Entity.toJSON = function toJSON() {
return Object.assign({}, _SimpleRecord.toJSON.call(this), {
key: this.key
};
});
}

@@ -391,13 +549,4 @@ /**

*/
;
/** Returns the globally unique identifier for the static Entity */
static get key() {
/* istanbul ignore next */
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;
}
/** Defines indexes to enable lookup by */
/**

@@ -410,20 +559,27 @@ * A unique identifier for each Entity

*/
static pk(value, parent, key) {
Entity.pk = function pk(value, parent, key) {
return this.prototype.pk.call(value, parent, key) || key;
}
};
static normalize(input, parent, key, visit, addEntity, visitedEntities) {
Entity.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {
var _this = this;
// 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);
var processedEntity = this.fromJS(input, parent, key);
/* istanbul ignore else */
if (process.env.NODE_ENV !== 'production') {
const instanceSample = new this();
const keysOfRecord = new Set(Object.keys(instanceSample));
const keysOfProps = this.keysDefined(processedEntity);
const [found, missing, unexpected] = [[], [], []];
var instanceSample = new this();
var keysOfRecord = new Set(Object.keys(instanceSample));
var keysOfProps = this.keysDefined(processedEntity);
var _ref = [[], [], []],
found = _ref[0],
missing = _ref[1],
unexpected = _ref[2];
for (const keyOfProps of keysOfProps) {
for (var _iterator = _createForOfIteratorHelperLoose(keysOfProps), _step; !(_step = _iterator()).done;) {
var keyOfProps = _step.value;
if (keysOfRecord.has(keyOfProps)) {

@@ -436,3 +592,5 @@ found.push(keyOfProps);

for (const keyOfRecord of keysOfRecord) {
for (var _iterator2 = _createForOfIteratorHelperLoose(keysOfRecord), _step2; !(_step2 = _iterator2()).done;) {
var keyOfRecord = _step2.value;
if (!found.includes(keyOfRecord)) {

@@ -445,12 +603,3 @@ missing.push(keyOfRecord);

if ((Math.max(keysOfProps.length / 2, 1) <= unexpected.length && keysOfRecord.size > Math.max(unexpected.length, 2) || found.length < Math.min(1, keysOfRecord.size / 2)) && keysOfRecord.size) {
const error = new Error(`Attempted to initialize ${this.name} with substantially different than expected keys
This is likely due to a malformed response.
Try inspecting the network response or fetch() return value.
Expected keys:
Found: ${found}
Missing: ${missing}
Unexpected keys: ${unexpected}
Value: ${JSON.stringify(this.toObjectDefined(processedEntity), null, 2)}`);
var error = 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: " + found + "\n Missing: " + missing + "\n Unexpected keys: " + unexpected + "\n Value: " + JSON.stringify(this.toObjectDefined(processedEntity), null, 2));
error.status = 400;

@@ -461,16 +610,10 @@ throw error;

const id = processedEntity.pk(parent, key);
var id = processedEntity.pk(parent, key);
if (id === undefined || id === '') {
if (process.env.NODE_ENV !== 'production') {
const error = new Error(`Missing usable resource key when normalizing response.
var _error = 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: " + (input && JSON.stringify(input, null, 2)) + "\n ");
This is likely due to a malformed response.
Try inspecting the network response or fetch() return value.
Entity: ${this.name}
Value: ${input && JSON.stringify(input, null, 2)}
`);
error.status = 400;
throw error;
_error.status = 400;
throw _error;
} else {

@@ -482,3 +625,3 @@ // these make the keys get deleted

const entityType = this.key;
var entityType = this.key;

@@ -493,3 +636,5 @@ if (!(entityType in visitedEntities)) {

if (visitedEntities[entityType][id].some(entity => entity === input)) {
if (visitedEntities[entityType][id].some(function (entity) {
return entity === input;
})) {
return id;

@@ -499,6 +644,6 @@ }

visitedEntities[entityType][id].push(input);
Object.keys(this.schema).forEach(key => {
Object.keys(this.schema).forEach(function (key) {
if (Object.hasOwnProperty.call(processedEntity, key)) {
const schema = this.schema[key];
processedEntity[key] = visit(processedEntity[key], processedEntity, key, schema, addEntity, visitedEntities);
var _schema = _this.schema[key];
processedEntity[key] = visit(processedEntity[key], processedEntity, key, _schema, addEntity, visitedEntities);
}

@@ -508,23 +653,34 @@ });

return id;
}
};
static denormalize(entity, unvisit) {
Entity.denormalize = function denormalize(entity, unvisit) {
var _this2 = this;
// 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, deleted] = denormalizeImmutable(this.schema, entity, unvisit);
return [this.fromJS(denormEntity.toObject()), found, deleted];
var _denormalizeImmutable = denormalizeImmutable(this.schema, entity, unvisit),
_denormEntity = _denormalizeImmutable[0],
_found = _denormalizeImmutable[1],
_deleted = _denormalizeImmutable[2];
return [this.fromJS(_denormEntity.toObject()), _found, _deleted];
} // TODO: This creates unneeded memory pressure
const instance = new this();
let deleted = false;
let found = true;
const denormEntity = entity;
Object.keys(this.schema).forEach(key => {
const schema = this.schema[key];
const input = this.hasDefined(entity, key) ? entity[key] : undefined;
const [value, foundItem, deletedItem] = unvisit(input, schema); // members who default to falsy values are considered 'optional'
var instance = new this();
var deleted = false;
var found = true;
var denormEntity = entity;
Object.keys(this.schema).forEach(function (key) {
var schema = _this2.schema[key];
var input = _this2.hasDefined(entity, key) ? entity[key] : undefined;
var _unvisit = unvisit(input, schema),
value = _unvisit[0],
foundItem = _unvisit[1],
deletedItem = _unvisit[2]; // 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])) {

@@ -538,3 +694,3 @@ found = false;

if (this.hasDefined(entity, key) && denormEntity[key] !== value) {
if (_this2.hasDefined(entity, key) && denormEntity[key] !== value) {
denormEntity[key] = value;

@@ -544,6 +700,20 @@ }

return [denormEntity, found, deleted];
}
};
}
_createClass(Entity, null, [{
key: "key",
/** Returns the globally unique identifier for the static Entity */
get: function get() {
/* istanbul ignore next */
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;
}
/** Defines indexes to enable lookup by */
}]);
return Entity;
}(SimpleRecord);
if (process.env.NODE_ENV !== 'production') {

@@ -562,12 +732,19 @@ // for those not using TypeScript this is a good catch to ensure they are defining

class FlatEntity extends Entity {
static denormalize(entity, unvisit) {
return [entity, true, false];
var FlatEntity = /*#__PURE__*/function (_Entity) {
_inheritsLoose(FlatEntity, _Entity);
function FlatEntity() {
return _Entity.apply(this, arguments) || this;
}
}
FlatEntity.denormalize = function denormalize(entity, unvisit) {
return [entity, true, false];
};
const unvisitEntity = (id, schema, unvisit, getEntity, cache) => {
const entity = getEntity(id, schema);
return FlatEntity;
}(Entity);
var unvisitEntity = function unvisitEntity(id, schema, unvisit, getEntity, cache) {
var entity = getEntity(id, schema);
if (entity === DELETED) {

@@ -585,12 +762,17 @@ return [undefined, true, true];

let found = true;
let deleted = false;
var found = true;
var deleted = false;
if (!cache[schema.key][id]) {
// Ensure we don't mutate it non-immutable objects
const entityCopy = isImmutable(entity) || entity instanceof FlatEntity ? entity : schema.fromJS(entity); // Need to set this first so that if it is referenced further within the
var entityCopy = isImmutable(entity) || entity instanceof FlatEntity ? entity : schema.fromJS(entity); // Need to set this first so that if it is referenced further within the
// denormalization the reference will already exist.
cache[schema.key][id] = entityCopy;
[cache[schema.key][id], found, deleted] = schema.denormalize(entityCopy, unvisit);
var _schema$denormalize = schema.denormalize(entityCopy, unvisit);
cache[schema.key][id] = _schema$denormalize[0];
found = _schema$denormalize[1];
deleted = _schema$denormalize[2];
}

@@ -601,5 +783,5 @@

const getUnvisit = entities => {
const cache = {};
const getEntity = getEntities(entities);
var getUnvisit = function getUnvisit(entities) {
var cache = {};
var getEntity = getEntities(entities);
return [function unvisit(input, schema) {

@@ -613,3 +795,3 @@ if (!schema) return [input, true, false];

} else if (typeof schema === 'object') {
const method = Array.isArray(schema) ? denormalize : denormalize$1;
var method = Array.isArray(schema) ? denormalize : _denormalize;
return method(schema, input, unvisit);

@@ -641,6 +823,6 @@ }

const getEntities = entities => {
const isImmutable$1 = isImmutable(entities);
return (entityOrId, schema) => {
const schemaKey = schema.key;
var getEntities = function getEntities(entities) {
var isImmutable$1 = isImmutable(entities);
return function (entityOrId, schema) {
var schemaKey = schema.key;

@@ -660,3 +842,3 @@ if (typeof entityOrId === 'object') {

const denormalize$2 = (input, schema, entities) => {
var denormalize$1 = function denormalize(input, schema, entities) {
/* istanbul ignore next */

@@ -666,4 +848,7 @@ if (process.env.NODE_ENV !== 'production' && schema === undefined) throw new Error('schema needed');

if (typeof input !== 'undefined') {
const [unvisit, cache] = getUnvisit(entities);
return [...unvisit(input, schema), cache];
var _getUnvisit = getUnvisit(entities),
unvisit = _getUnvisit[0],
cache = _getUnvisit[1];
return [].concat(unvisit(input, schema), [cache]);
}

@@ -674,3 +859,3 @@

const visit = (value, parent, key, schema, addEntity, visitedEntities) => {
var visit = function visit(value, parent, key, schema, addEntity, visitedEntities) {
if (!value || !schema || !['function', 'object'].includes(typeof schema)) {

@@ -686,3 +871,3 @@ return value;

const method = Array.isArray(schema) ? normalize : normalize$1;
var method = Array.isArray(schema) ? normalize : _normalize;
return method(schema, value, parent, key, visit, addEntity, visitedEntities);

@@ -694,49 +879,51 @@ }

const addEntities = (entities, indexes) => (schema, processedEntity, value, parent, key) => {
const schemaKey = schema.key;
const id = schema.pk(value, parent, key);
var addEntities = function addEntities(entities, indexes) {
return function (schema, processedEntity, value, parent, key) {
var schemaKey = schema.key;
var id = schema.pk(value, parent, key);
if (!(schemaKey in entities)) {
entities[schemaKey] = {};
}
if (!(schemaKey in entities)) {
entities[schemaKey] = {};
}
const existingEntity = entities[schemaKey][id];
var existingEntity = entities[schemaKey][id];
if (existingEntity) {
entities[schemaKey][id] = schema.merge(existingEntity, processedEntity);
} else {
entities[schemaKey][id] = processedEntity;
} // update index
if (existingEntity) {
entities[schemaKey][id] = schema.merge(existingEntity, processedEntity);
} else {
entities[schemaKey][id] = processedEntity;
} // update index
if (Array.isArray(schema.indexes)) {
const entity = entities[schemaKey][id];
if (Array.isArray(schema.indexes)) {
var entity = entities[schemaKey][id];
if (!(schemaKey in indexes)) {
indexes[schemaKey] = {};
}
for (const index of schema.indexes) {
if (!(index in indexes[schemaKey])) {
indexes[schemaKey][index] = {};
if (!(schemaKey in indexes)) {
indexes[schemaKey] = {};
}
const indexMap = indexes[schemaKey][index];
for (var _iterator = _createForOfIteratorHelperLoose(schema.indexes), _step; !(_step = _iterator()).done;) {
var index = _step.value;
if (existingEntity) {
delete indexMap[existingEntity[index]];
}
if (!(index in indexes[schemaKey])) {
indexes[schemaKey][index] = {};
}
if (index in entity) {
indexMap[entity[index]] = id;
var indexMap = indexes[schemaKey][index];
if (existingEntity) {
delete indexMap[existingEntity[index]];
}
if (index in entity) {
indexMap[entity[index]] = id;
}
/* istanbul ignore next */
else if ( // eslint-disable-next-line no-undef
process.env.NODE_ENV !== 'production') {
console.warn("Index not found in entity. Indexes must be top-level members of your entity.\nIndex: " + index + "\nEntity: " + JSON.stringify(entity, undefined, 2));
}
}
/* istanbul ignore next */
else if ( // eslint-disable-next-line no-undef
process.env.NODE_ENV !== 'production') {
console.warn(`Index not found in entity. Indexes must be top-level members of your entity.
Index: ${index}
Entity: ${JSON.stringify(entity, undefined, 2)}`);
}
}
}
};
};

@@ -749,4 +936,4 @@

const normalize$2 = (input, schema) => {
const schemaType = expectedSchemaType(schema);
var normalize$1 = function normalize(input, schema) {
var schemaType = expectedSchemaType(schema);

@@ -756,3 +943,3 @@ if (input === null || typeof input !== schemaType) {

if (process.env.NODE_ENV !== 'production') {
const parseWorks = input => {
var parseWorks = function parseWorks(input) {
try {

@@ -766,35 +953,27 @@ return typeof JSON.parse(input) !== 'string';

if (typeof input === 'string' && parseWorks(input)) {
throw new Error(`Normalizing a string, but this does match schema.
Parsing this input string as JSON worked. This likely indicates fetch function did not parse
the JSON. By default, this only happens if "content-type" header includes "json".
See https://resthooks.io/docs/guides/custom-networking for more information
Schema: ${JSON.stringify(schema, undefined, 2)}
Input: "${input}"`);
throw 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(schema, undefined, 2) + "\n Input: \"" + input + "\"");
} else {
throw new Error(`Unexpected input given to normalize. Expected type to be "${schemaType}", found "${input === null ? 'null' : typeof input}".
Schema: ${JSON.stringify(schema, undefined, 2)}
Input: "${input}"`);
throw new Error("Unexpected input given to normalize. Expected type to be \"" + schemaType + "\", found \"" + (input === null ? 'null' : typeof input) + "\".\n\n Schema: " + JSON.stringify(schema, undefined, 2) + "\n Input: \"" + input + "\"");
}
} else {
throw new Error(`Unexpected input given to normalize. Expected type to be "${schemaType}", found "${input === null ? 'null' : typeof input}".`);
throw new Error("Unexpected input given to normalize. Expected type to be \"" + schemaType + "\", found \"" + (input === null ? 'null' : typeof input) + "\".");
}
}
const entities = {};
const indexes = {};
const addEntity = addEntities(entities, indexes);
const visitedEntities = {};
const result = visit(input, input, undefined, schema, addEntity, visitedEntities);
var entities = {};
var indexes = {};
var addEntity = addEntities(entities, indexes);
var visitedEntities = {};
var result = visit(input, input, undefined, schema, addEntity, visitedEntities);
return {
entities,
indexes,
result
entities: entities,
indexes: indexes,
result: result
};
};
class UnionSchema extends PolymorphicSchema {
constructor(definition, schemaAttribute) {
var UnionSchema = /*#__PURE__*/function (_PolymorphicSchema) {
_inheritsLoose(UnionSchema, _PolymorphicSchema);
function UnionSchema(definition, schemaAttribute) {
if (!schemaAttribute) {

@@ -804,32 +983,53 @@ throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');

super(definition, schemaAttribute);
return _PolymorphicSchema.call(this, definition, schemaAttribute) || this;
}
normalize(input, parent, key, visit, addEntity, visitedEntities) {
var _proto = UnionSchema.prototype;
_proto.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {
return this.normalizeValue(input, parent, key, visit, addEntity, visitedEntities);
}
};
denormalize(input, unvisit) {
_proto.denormalize = function denormalize(input, unvisit) {
return this.denormalizeValue(input, unvisit);
};
return UnionSchema;
}(PolymorphicSchema);
var ValuesSchema = /*#__PURE__*/function (_PolymorphicSchema) {
_inheritsLoose(ValuesSchema, _PolymorphicSchema);
function ValuesSchema() {
return _PolymorphicSchema.apply(this, arguments) || this;
}
}
var _proto = ValuesSchema.prototype;
class ValuesSchema extends PolymorphicSchema {
normalize(input, parent, key, visit, addEntity, visitedEntities) {
return Object.keys(input).reduce((output, key, index) => {
const value = input[key];
return value !== undefined && value !== null ? { ...output,
[key]: this.normalizeValue(value, input, key, visit, addEntity, visitedEntities)
} : output;
_proto.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {
var _this = this;
return Object.keys(input).reduce(function (output, key, index) {
var _Object$assign;
var value = input[key];
return value !== undefined && value !== null ? Object.assign({}, output, (_Object$assign = {}, _Object$assign[key] = _this.normalizeValue(value, input, key, visit, addEntity, visitedEntities), _Object$assign)) : output;
}, {});
}
};
denormalize(input, unvisit) {
let found = true;
let deleted = false;
return [Object.keys(input).reduce((output, key) => {
const entityOrId = input[key];
const [value, foundItem, deletedItem] = this.denormalizeValue(entityOrId, unvisit);
_proto.denormalize = function denormalize(input, unvisit) {
var _this2 = this;
var found = true;
var deleted = false;
return [Object.keys(input).reduce(function (output, key) {
var _Object$assign2;
var entityOrId = input[key];
var _this2$denormalizeVal = _this2.denormalizeValue(entityOrId, unvisit),
value = _this2$denormalizeVal[0],
foundItem = _this2$denormalizeVal[1],
deletedItem = _this2$denormalizeVal[2];
if (!foundItem) {

@@ -844,13 +1044,13 @@ found = false;

if (!foundItem || deletedItem) return output;
return { ...output,
[key]: value
};
return Object.assign({}, output, (_Object$assign2 = {}, _Object$assign2[key] = value, _Object$assign2));
}, {}), found, deleted];
}
};
}
return ValuesSchema;
}(PolymorphicSchema);
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
class Delete {
constructor(entity) {
var Delete = /*#__PURE__*/function () {
function Delete(entity) {
if (process.env.NODE_ENV !== 'production' && !entity) {

@@ -863,36 +1063,39 @@ throw new Error('Expected option "entity" not found on DeleteSchema.');

normalize(input, parent, key, visit, addEntity, visitedEntities) {
var _proto = Delete.prototype;
_proto.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {
// 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._entity.fromJS(input, parent, key);
var processedEntity = this._entity.fromJS(input, parent, key);
const id = processedEntity.pk(parent, key);
var id = processedEntity.pk(parent, key);
addEntity(this._entity, DELETED, processedEntity, parent, key);
return id;
}
};
denormalize(id, unvisit) {
_proto.denormalize = function denormalize(id, unvisit) {
return unvisit(id, this._entity);
}
/* istanbul ignore next */
;
_denormalizeNullable() {
_proto._denormalizeNullable = function _denormalizeNullable() {
return [];
}
/* istanbul ignore next */
;
_normalizeNullable() {
_proto._normalizeNullable = function _normalizeNullable() {
return [];
}
/* istanbul ignore next */
;
merge(existing, incoming) {
_proto.merge = function merge(existing, incoming) {
return incoming;
}
};
}
return Delete;
}();

@@ -914,5 +1117,5 @@ /* istanbul ignore file */

exports.SimpleRecord = SimpleRecord;
exports.denormalize = denormalize$2;
exports.denormalize = denormalize$1;
exports.isEntity = isEntity;
exports.normalize = normalize$2;
exports.normalize = normalize$1;
exports.schema = schema;

@@ -919,0 +1122,0 @@

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

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

@@ -32,10 +32,14 @@ 'use strict';

function denormalizeImmutable(schema, input, unvisit) {
let found = true;
let deleted = false;
return [Object.keys(schema).reduce((object, key) => {
var found = true;
var deleted = false;
return [Object.keys(schema).reduce(function (object, key) {
// Immutable maps cast keys to strings on write so we need to ensure
// we're accessing them using string keys.
const stringKey = `${key}`;
const [item, foundItem, deletedItem] = unvisit(object.get(stringKey), schema[stringKey]);
var stringKey = "" + key;
var _unvisit = unvisit(object.get(stringKey), schema[stringKey]),
item = _unvisit[0],
foundItem = _unvisit[1],
deletedItem = _unvisit[2];
if (!foundItem) {

@@ -57,6 +61,30 @@ found = false;

class PolymorphicSchema {
constructor(definition, schemaAttribute) {
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
var PolymorphicSchema = /*#__PURE__*/function () {
function PolymorphicSchema(definition, schemaAttribute) {
if (schemaAttribute) {
this._schemaAttribute = typeof schemaAttribute === 'string' ? input => input[schemaAttribute] : schemaAttribute;
this._schemaAttribute = typeof schemaAttribute === 'string' ? function (input) {
return input[schemaAttribute];
} : schemaAttribute;
}

@@ -67,15 +95,13 @@

get isSingleSchema() {
return !this._schemaAttribute;
}
var _proto = PolymorphicSchema.prototype;
define(definition) {
_proto.define = function define(definition) {
this.schema = definition;
}
};
getSchemaAttribute(input, parent, key) {
_proto.getSchemaAttribute = function getSchemaAttribute(input, parent, key) {
return !this.isSingleSchema && this._schemaAttribute(input, parent, key);
}
};
inferSchema(input, parent, key) {
_proto.inferSchema = function inferSchema(input, parent, key) {
if (this.isSingleSchema) {

@@ -85,8 +111,8 @@ return this.schema;

const attr = this.getSchemaAttribute(input, parent, key);
var attr = this.getSchemaAttribute(input, parent, key);
return this.schema[attr];
}
};
normalizeValue(value, parent, key, visit, addEntity, visitedEntities) {
const schema = this.inferSchema(value, parent, key);
_proto.normalizeValue = function normalizeValue(value, parent, key, visit, addEntity, visitedEntities) {
var schema = this.inferSchema(value, parent, key);

@@ -97,3 +123,3 @@ if (!schema) {

const normalizedValue = visit(value, parent, key, schema, addEntity, visitedEntities);
var normalizedValue = visit(value, parent, key, schema, addEntity, visitedEntities);
return this.isSingleSchema || normalizedValue === undefined || normalizedValue === null ? normalizedValue : {

@@ -103,6 +129,6 @@ id: normalizedValue,

};
}
};
denormalizeValue(value, unvisit) {
const schemaKey = isImmutable(value) ? value.get('schema') : value.schema;
_proto.denormalizeValue = function denormalizeValue(value, unvisit) {
var schemaKey = isImmutable(value) ? value.get('schema') : value.schema;

@@ -113,16 +139,24 @@ if (!this.isSingleSchema && !schemaKey) {

const id = this.isSingleSchema ? undefined : isImmutable(value) ? value.get('id') : value.id;
const schema = this.isSingleSchema ? this.schema : this.schema[schemaKey];
var id = this.isSingleSchema ? undefined : isImmutable(value) ? value.get('id') : value.id;
var schema = this.isSingleSchema ? this.schema : this.schema[schemaKey];
return unvisit(id || value, schema);
}
};
}
_createClass(PolymorphicSchema, [{
key: "isSingleSchema",
get: function get() {
return !this._schemaAttribute;
}
}]);
const DELETED = Symbol('ENTITY WAS DELETED');
return PolymorphicSchema;
}();
const validateSchema = definition => {
const isArray = Array.isArray(definition);
var DELETED = Symbol('ENTITY WAS DELETED');
var validateSchema = function validateSchema(definition) {
var isArray = Array.isArray(definition);
if (isArray && definition.length > 1) {
throw new Error(`Expected schema definition to be a single schema, but found ${definition.length}.`);
throw new Error("Expected schema definition to be a single schema, but found " + definition.length + ".");
}

@@ -133,49 +167,92 @@

const getValues = input => Array.isArray(input) ? input : Object.keys(input).map(key => input[key]);
var getValues = function getValues(input) {
return Array.isArray(input) ? input : Object.keys(input).map(function (key) {
return input[key];
});
};
const filterEmpty = ([, foundItem, deletedItem]) => foundItem && !deletedItem;
var filterEmpty = function filterEmpty(_ref) {
var foundItem = _ref[1],
deletedItem = _ref[2];
return foundItem && !deletedItem;
};
const normalize = (schema, input, parent, key, visit, addEntity, visitedEntities) => {
var normalize = function normalize(schema, input, parent, key, visit, addEntity, visitedEntities) {
schema = validateSchema(schema);
const values = getValues(input); // Special case: Arrays pass *their* parent on to their children, since there
var values = getValues(input); // Special case: Arrays pass *their* parent on to their children, since there
// is not any special information that can be gathered from themselves directly
return values.map((value, index) => visit(value, parent, key, schema, addEntity, visitedEntities));
return values.map(function (value, index) {
return visit(value, parent, key, schema, addEntity, visitedEntities);
});
};
const denormalize = (schema, input, unvisit) => {
var denormalize = function denormalize(schema, input, unvisit) {
schema = validateSchema(schema);
let deleted = false;
let found = true;
var deleted = false;
var found = true;
if (input === undefined && schema) {
[, found, deleted] = unvisit(undefined, schema);
var _unvisit = unvisit(undefined, schema);
found = _unvisit[1];
deleted = _unvisit[2];
}
return [input && input.map ? input.map(entityOrId => unvisit(entityOrId, schema)).filter(filterEmpty).map(([value]) => value) : input, found, deleted];
return [input && input.map ? input.map(function (entityOrId) {
return unvisit(entityOrId, schema);
}).filter(filterEmpty).map(function (_ref2) {
var value = _ref2[0];
return value;
}) : input, found, deleted];
};
class ArraySchema extends PolymorphicSchema {
normalize(input, parent, key, visit, addEntity, visitedEntities) {
const values = getValues(input);
return values.map((value, index) => this.normalizeValue(value, parent, key, visit, addEntity, visitedEntities)).filter(value => value !== undefined && value !== null);
var ArraySchema = /*#__PURE__*/function (_PolymorphicSchema) {
_inheritsLoose(ArraySchema, _PolymorphicSchema);
function ArraySchema() {
return _PolymorphicSchema.apply(this, arguments) || this;
}
denormalize(input, unvisit) {
let deleted = false;
let found = true;
var _proto = ArraySchema.prototype;
_proto.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {
var _this = this;
var values = getValues(input);
return values.map(function (value, index) {
return _this.normalizeValue(value, parent, key, visit, addEntity, visitedEntities);
}).filter(function (value) {
return value !== undefined && value !== null;
});
};
_proto.denormalize = function denormalize(input, unvisit) {
var _this2 = this;
var deleted = false;
var found = true;
if (input === undefined && this.schema) {
[, found, deleted] = unvisit(undefined, this.schema);
var _unvisit2 = unvisit(undefined, this.schema);
found = _unvisit2[1];
deleted = _unvisit2[2];
}
return [input && input.map ? input.map(entityOrId => this.denormalizeValue(entityOrId, unvisit)).filter(filterEmpty).map(([value]) => value) : input, found, deleted];
}
return [input && input.map ? input.map(function (entityOrId) {
return _this2.denormalizeValue(entityOrId, unvisit);
}).filter(filterEmpty).map(function (_ref3) {
var value = _ref3[0];
return value;
}) : input, found, deleted];
};
}
return ArraySchema;
}(PolymorphicSchema);
const normalize$1 = (schema, input, parent, key, visit, addEntity, visitedEntities) => {
const object = { ...input
};
Object.keys(schema).forEach(key => {
const localSchema = schema[key];
const value = visit(input[key], input, key, localSchema, addEntity, visitedEntities);
var _normalize = function normalize(schema, input, parent, key, visit, addEntity, visitedEntities) {
var object = Object.assign({}, input);
Object.keys(schema).forEach(function (key) {
var localSchema = schema[key];
var value = visit(input[key], input, key, localSchema, addEntity, visitedEntities);

@@ -190,3 +267,4 @@ if (value === undefined || value === null) {

};
const denormalize$1 = (schema, input, unvisit) => {
var _denormalize = function denormalize(schema, input, unvisit) {
if (isImmutable(input)) {

@@ -196,8 +274,10 @@ return denormalizeImmutable(schema, input, unvisit);

const object = { ...input
};
let found = true;
let deleted = false;
Object.keys(schema).forEach(key => {
const [item, foundItem, deletedItem] = unvisit(object[key], schema[key]);
var object = Object.assign({}, input);
var found = true;
var deleted = false;
Object.keys(schema).forEach(function (key) {
var _unvisit = unvisit(object[key], schema[key]),
item = _unvisit[0],
foundItem = _unvisit[1],
deletedItem = _unvisit[2];

@@ -218,38 +298,97 @@ if (object[key] !== undefined) {

};
class ObjectSchema {
constructor(definition) {
var ObjectSchema = /*#__PURE__*/function () {
function ObjectSchema(definition) {
this.define(definition);
}
define(definition) {
this.schema = Object.keys(definition).reduce((entitySchema, key) => {
const schema = definition[key];
return { ...entitySchema,
[key]: schema
};
var _proto = ObjectSchema.prototype;
_proto.define = function define(definition) {
this.schema = Object.keys(definition).reduce(function (entitySchema, key) {
var _Object$assign;
var schema = definition[key];
return Object.assign({}, entitySchema, (_Object$assign = {}, _Object$assign[key] = schema, _Object$assign));
}, this.schema || {});
}
};
normalize(...args) {
return normalize$1(this.schema, ...args);
_proto.normalize = function normalize() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _normalize.apply(void 0, [this.schema].concat(args));
};
_proto.denormalize = function denormalize() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return _denormalize.apply(void 0, [this.schema].concat(args));
};
return ObjectSchema;
}();
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) {
arr2[i] = arr[i];
}
denormalize(...args) {
return denormalize$1(this.schema, ...args);
return arr2;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
var it;
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
if (it) o = it;
var i = 0;
return function () {
if (i >= o.length) return {
done: true
};
return {
done: false,
value: o[i++]
};
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
it = o[Symbol.iterator]();
return it.next.bind(it);
}
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
const DefinedMembersKey = Symbol('Defined Members');
const UniqueIdentifierKey = Symbol('unq');
var DefinedMembersKey = Symbol('Defined Members');
var UniqueIdentifierKey = Symbol('unq');
/** Immutable record that keeps track of which members are defined vs defaults. */
class SimpleRecord {
toString() {
var SimpleRecord = /*#__PURE__*/function () {
function SimpleRecord() {}
var _proto = SimpleRecord.prototype;
_proto.toString = function toString() {
// we don't make _unq a member so it doesn't play a role in type compatibility
return this[UniqueIdentifierKey];
}
};
static toJSON() {
SimpleRecord.toJSON = function toJSON() {
return {

@@ -261,4 +400,4 @@ name: this.name,

/** Defines nested entities */
;
/** Factory method to convert from Plain JS Objects.

@@ -270,6 +409,10 @@ *

*/
static fromJS( // TODO: this should only accept members that are not functions
props = {}, parent, key) {
SimpleRecord.fromJS = function fromJS( // TODO: this should only accept members that are not functions
props, parent, key) {
if (props === void 0) {
props = {};
}
// we type guarded abstract case above, so ok to force typescript to allow constructor call
const instance = new this(props);
var instance = new this(props);

@@ -287,3 +430,3 @@ if (props instanceof SimpleRecord) {

Object.defineProperty(instance, UniqueIdentifierKey, {
value: `${Math.random()}`,
value: "" + Math.random(),
writable: false

@@ -294,21 +437,22 @@ });

/** Creates new instance copying over defined values of arguments */
;
static merge(existing, incoming) {
const props = Object.assign(this.toObjectDefined(existing), this.toObjectDefined(incoming));
SimpleRecord.merge = function merge(existing, incoming) {
var props = Object.assign(this.toObjectDefined(existing), this.toObjectDefined(incoming));
return this.fromJS(props);
}
/** Whether key is non-default */
;
static hasDefined(instance, key) {
SimpleRecord.hasDefined = function hasDefined(instance, key) {
return instance[DefinedMembersKey].includes(key);
}
/** Returns simple object with all the non-default members */
;
SimpleRecord.toObjectDefined = function toObjectDefined(instance) {
var defined = {};
static toObjectDefined(instance) {
const defined = {};
for (const member of instance[DefinedMembersKey]) {
for (var _iterator = _createForOfIteratorHelperLoose(instance[DefinedMembersKey]), _step; !(_step = _iterator()).done;) {
var member = _step.value;
defined[member] = instance[member];

@@ -320,21 +464,29 @@ }

/** Returns array of all keys that have values defined in instance */
;
static keysDefined(instance) {
SimpleRecord.keysDefined = function keysDefined(instance) {
return instance[DefinedMembersKey];
}
};
static normalize(...args) {
return normalize$1(this.schema, ...args);
}
SimpleRecord.normalize = function normalize() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
static denormalize(input, unvisit) {
return _normalize.apply(void 0, [this.schema].concat(args));
};
SimpleRecord.denormalize = function denormalize(input, unvisit) {
var _this = this;
// TODO: This creates unneeded memory pressure
const instance = new this();
const object = { ...input
};
let deleted = false;
let found = true;
Object.keys(this.schema).forEach(key => {
const [item, foundItem, deletedItem] = unvisit(object[key], this.schema[key]);
var instance = new this();
var object = Object.assign({}, input);
var deleted = false;
var found = true;
Object.keys(this.schema).forEach(function (key) {
var _unvisit = unvisit(object[key], _this.schema[key]),
item = _unvisit[0],
foundItem = _unvisit[1],
deletedItem = _unvisit[2];

@@ -359,5 +511,5 @@ if (object[key] !== undefined) {

/* istanbul ignore next */
;
static asSchema() {
SimpleRecord.asSchema = function asSchema() {
/* istanbul ignore next */

@@ -371,15 +523,21 @@ if (process.env.NODE_ENV === 'development') {

return this;
}
};
}
return SimpleRecord;
}();
SimpleRecord.schema = {};
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/** Represents data that should be deduped by specifying a primary key. */
var Entity = /*#__PURE__*/function (_SimpleRecord) {
_inheritsLoose(Entity, _SimpleRecord);
/** Represents data that should be deduped by specifying a primary key. */
class Entity extends SimpleRecord {
static toJSON() {
return { ...super.toJSON(),
function Entity() {
return _SimpleRecord.apply(this, arguments) || this;
}
Entity.toJSON = function toJSON() {
return Object.assign({}, _SimpleRecord.toJSON.call(this), {
key: this.key
};
});
}

@@ -392,13 +550,4 @@ /**

*/
;
/** Returns the globally unique identifier for the static Entity */
static get key() {
/* istanbul ignore next */
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;
}
/** Defines indexes to enable lookup by */
/**

@@ -411,20 +560,27 @@ * A unique identifier for each Entity

*/
static pk(value, parent, key) {
Entity.pk = function pk(value, parent, key) {
return this.prototype.pk.call(value, parent, key) || key;
}
};
static normalize(input, parent, key, visit, addEntity, visitedEntities) {
Entity.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {
var _this = this;
// 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);
var processedEntity = this.fromJS(input, parent, key);
/* istanbul ignore else */
if (process.env.NODE_ENV !== 'production') {
const instanceSample = new this();
const keysOfRecord = new Set(Object.keys(instanceSample));
const keysOfProps = this.keysDefined(processedEntity);
const [found, missing, unexpected] = [[], [], []];
var instanceSample = new this();
var keysOfRecord = new Set(Object.keys(instanceSample));
var keysOfProps = this.keysDefined(processedEntity);
var _ref = [[], [], []],
found = _ref[0],
missing = _ref[1],
unexpected = _ref[2];
for (const keyOfProps of keysOfProps) {
for (var _iterator = _createForOfIteratorHelperLoose(keysOfProps), _step; !(_step = _iterator()).done;) {
var keyOfProps = _step.value;
if (keysOfRecord.has(keyOfProps)) {

@@ -437,3 +593,5 @@ found.push(keyOfProps);

for (const keyOfRecord of keysOfRecord) {
for (var _iterator2 = _createForOfIteratorHelperLoose(keysOfRecord), _step2; !(_step2 = _iterator2()).done;) {
var keyOfRecord = _step2.value;
if (!found.includes(keyOfRecord)) {

@@ -446,12 +604,3 @@ missing.push(keyOfRecord);

if ((Math.max(keysOfProps.length / 2, 1) <= unexpected.length && keysOfRecord.size > Math.max(unexpected.length, 2) || found.length < Math.min(1, keysOfRecord.size / 2)) && keysOfRecord.size) {
const error = new Error(`Attempted to initialize ${this.name} with substantially different than expected keys
This is likely due to a malformed response.
Try inspecting the network response or fetch() return value.
Expected keys:
Found: ${found}
Missing: ${missing}
Unexpected keys: ${unexpected}
Value: ${JSON.stringify(this.toObjectDefined(processedEntity), null, 2)}`);
var error = 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: " + found + "\n Missing: " + missing + "\n Unexpected keys: " + unexpected + "\n Value: " + JSON.stringify(this.toObjectDefined(processedEntity), null, 2));
error.status = 400;

@@ -462,16 +611,10 @@ throw error;

const id = processedEntity.pk(parent, key);
var id = processedEntity.pk(parent, key);
if (id === undefined || id === '') {
if (process.env.NODE_ENV !== 'production') {
const error = new Error(`Missing usable resource key when normalizing response.
var _error = 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: " + (input && JSON.stringify(input, null, 2)) + "\n ");
This is likely due to a malformed response.
Try inspecting the network response or fetch() return value.
Entity: ${this.name}
Value: ${input && JSON.stringify(input, null, 2)}
`);
error.status = 400;
throw error;
_error.status = 400;
throw _error;
} else {

@@ -483,3 +626,3 @@ // these make the keys get deleted

const entityType = this.key;
var entityType = this.key;

@@ -494,3 +637,5 @@ if (!(entityType in visitedEntities)) {

if (visitedEntities[entityType][id].some(entity => entity === input)) {
if (visitedEntities[entityType][id].some(function (entity) {
return entity === input;
})) {
return id;

@@ -500,6 +645,6 @@ }

visitedEntities[entityType][id].push(input);
Object.keys(this.schema).forEach(key => {
Object.keys(this.schema).forEach(function (key) {
if (Object.hasOwnProperty.call(processedEntity, key)) {
const schema = this.schema[key];
processedEntity[key] = visit(processedEntity[key], processedEntity, key, schema, addEntity, visitedEntities);
var _schema = _this.schema[key];
processedEntity[key] = visit(processedEntity[key], processedEntity, key, _schema, addEntity, visitedEntities);
}

@@ -509,23 +654,34 @@ });

return id;
}
};
static denormalize(entity, unvisit) {
Entity.denormalize = function denormalize(entity, unvisit) {
var _this2 = this;
// 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, deleted] = denormalizeImmutable(this.schema, entity, unvisit);
return [this.fromJS(denormEntity.toObject()), found, deleted];
var _denormalizeImmutable = denormalizeImmutable(this.schema, entity, unvisit),
_denormEntity = _denormalizeImmutable[0],
_found = _denormalizeImmutable[1],
_deleted = _denormalizeImmutable[2];
return [this.fromJS(_denormEntity.toObject()), _found, _deleted];
} // TODO: This creates unneeded memory pressure
const instance = new this();
let deleted = false;
let found = true;
const denormEntity = entity;
Object.keys(this.schema).forEach(key => {
const schema = this.schema[key];
const input = this.hasDefined(entity, key) ? entity[key] : undefined;
const [value, foundItem, deletedItem] = unvisit(input, schema); // members who default to falsy values are considered 'optional'
var instance = new this();
var deleted = false;
var found = true;
var denormEntity = entity;
Object.keys(this.schema).forEach(function (key) {
var schema = _this2.schema[key];
var input = _this2.hasDefined(entity, key) ? entity[key] : undefined;
var _unvisit = unvisit(input, schema),
value = _unvisit[0],
foundItem = _unvisit[1],
deletedItem = _unvisit[2]; // 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])) {

@@ -539,3 +695,3 @@ found = false;

if (this.hasDefined(entity, key) && denormEntity[key] !== value) {
if (_this2.hasDefined(entity, key) && denormEntity[key] !== value) {
denormEntity[key] = value;

@@ -545,6 +701,20 @@ }

return [denormEntity, found, deleted];
}
};
}
_createClass(Entity, null, [{
key: "key",
/** Returns the globally unique identifier for the static Entity */
get: function get() {
/* istanbul ignore next */
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;
}
/** Defines indexes to enable lookup by */
}]);
return Entity;
}(SimpleRecord);
if (process.env.NODE_ENV !== 'production') {

@@ -563,12 +733,19 @@ // for those not using TypeScript this is a good catch to ensure they are defining

class FlatEntity extends Entity {
static denormalize(entity, unvisit) {
return [entity, true, false];
var FlatEntity = /*#__PURE__*/function (_Entity) {
_inheritsLoose(FlatEntity, _Entity);
function FlatEntity() {
return _Entity.apply(this, arguments) || this;
}
}
FlatEntity.denormalize = function denormalize(entity, unvisit) {
return [entity, true, false];
};
const unvisitEntity = (id, schema, unvisit, getEntity, cache) => {
const entity = getEntity(id, schema);
return FlatEntity;
}(Entity);
var unvisitEntity = function unvisitEntity(id, schema, unvisit, getEntity, cache) {
var entity = getEntity(id, schema);
if (entity === DELETED) {

@@ -586,12 +763,17 @@ return [undefined, true, true];

let found = true;
let deleted = false;
var found = true;
var deleted = false;
if (!cache[schema.key][id]) {
// Ensure we don't mutate it non-immutable objects
const entityCopy = isImmutable(entity) || entity instanceof FlatEntity ? entity : schema.fromJS(entity); // Need to set this first so that if it is referenced further within the
var entityCopy = isImmutable(entity) || entity instanceof FlatEntity ? entity : schema.fromJS(entity); // Need to set this first so that if it is referenced further within the
// denormalization the reference will already exist.
cache[schema.key][id] = entityCopy;
[cache[schema.key][id], found, deleted] = schema.denormalize(entityCopy, unvisit);
var _schema$denormalize = schema.denormalize(entityCopy, unvisit);
cache[schema.key][id] = _schema$denormalize[0];
found = _schema$denormalize[1];
deleted = _schema$denormalize[2];
}

@@ -602,5 +784,5 @@

const getUnvisit = entities => {
const cache = {};
const getEntity = getEntities(entities);
var getUnvisit = function getUnvisit(entities) {
var cache = {};
var getEntity = getEntities(entities);
return [function unvisit(input, schema) {

@@ -614,3 +796,3 @@ if (!schema) return [input, true, false];

} else if (typeof schema === 'object') {
const method = Array.isArray(schema) ? denormalize : denormalize$1;
var method = Array.isArray(schema) ? denormalize : _denormalize;
return method(schema, input, unvisit);

@@ -642,6 +824,6 @@ }

const getEntities = entities => {
const isImmutable$1 = isImmutable(entities);
return (entityOrId, schema) => {
const schemaKey = schema.key;
var getEntities = function getEntities(entities) {
var isImmutable$1 = isImmutable(entities);
return function (entityOrId, schema) {
var schemaKey = schema.key;

@@ -661,3 +843,3 @@ if (typeof entityOrId === 'object') {

const denormalize$2 = (input, schema, entities) => {
var denormalize$1 = function denormalize(input, schema, entities) {
/* istanbul ignore next */

@@ -667,4 +849,7 @@ if (process.env.NODE_ENV !== 'production' && schema === undefined) throw new Error('schema needed');

if (typeof input !== 'undefined') {
const [unvisit, cache] = getUnvisit(entities);
return [...unvisit(input, schema), cache];
var _getUnvisit = getUnvisit(entities),
unvisit = _getUnvisit[0],
cache = _getUnvisit[1];
return [].concat(unvisit(input, schema), [cache]);
}

@@ -675,3 +860,3 @@

const visit = (value, parent, key, schema, addEntity, visitedEntities) => {
var visit = function visit(value, parent, key, schema, addEntity, visitedEntities) {
if (!value || !schema || !['function', 'object'].includes(typeof schema)) {

@@ -687,3 +872,3 @@ return value;

const method = Array.isArray(schema) ? normalize : normalize$1;
var method = Array.isArray(schema) ? normalize : _normalize;
return method(schema, value, parent, key, visit, addEntity, visitedEntities);

@@ -695,49 +880,51 @@ }

const addEntities = (entities, indexes) => (schema, processedEntity, value, parent, key) => {
const schemaKey = schema.key;
const id = schema.pk(value, parent, key);
var addEntities = function addEntities(entities, indexes) {
return function (schema, processedEntity, value, parent, key) {
var schemaKey = schema.key;
var id = schema.pk(value, parent, key);
if (!(schemaKey in entities)) {
entities[schemaKey] = {};
}
if (!(schemaKey in entities)) {
entities[schemaKey] = {};
}
const existingEntity = entities[schemaKey][id];
var existingEntity = entities[schemaKey][id];
if (existingEntity) {
entities[schemaKey][id] = schema.merge(existingEntity, processedEntity);
} else {
entities[schemaKey][id] = processedEntity;
} // update index
if (existingEntity) {
entities[schemaKey][id] = schema.merge(existingEntity, processedEntity);
} else {
entities[schemaKey][id] = processedEntity;
} // update index
if (Array.isArray(schema.indexes)) {
const entity = entities[schemaKey][id];
if (Array.isArray(schema.indexes)) {
var entity = entities[schemaKey][id];
if (!(schemaKey in indexes)) {
indexes[schemaKey] = {};
}
for (const index of schema.indexes) {
if (!(index in indexes[schemaKey])) {
indexes[schemaKey][index] = {};
if (!(schemaKey in indexes)) {
indexes[schemaKey] = {};
}
const indexMap = indexes[schemaKey][index];
for (var _iterator = _createForOfIteratorHelperLoose(schema.indexes), _step; !(_step = _iterator()).done;) {
var index = _step.value;
if (existingEntity) {
delete indexMap[existingEntity[index]];
}
if (!(index in indexes[schemaKey])) {
indexes[schemaKey][index] = {};
}
if (index in entity) {
indexMap[entity[index]] = id;
var indexMap = indexes[schemaKey][index];
if (existingEntity) {
delete indexMap[existingEntity[index]];
}
if (index in entity) {
indexMap[entity[index]] = id;
}
/* istanbul ignore next */
else if ( // eslint-disable-next-line no-undef
process.env.NODE_ENV !== 'production') {
console.warn("Index not found in entity. Indexes must be top-level members of your entity.\nIndex: " + index + "\nEntity: " + JSON.stringify(entity, undefined, 2));
}
}
/* istanbul ignore next */
else if ( // eslint-disable-next-line no-undef
process.env.NODE_ENV !== 'production') {
console.warn(`Index not found in entity. Indexes must be top-level members of your entity.
Index: ${index}
Entity: ${JSON.stringify(entity, undefined, 2)}`);
}
}
}
};
};

@@ -750,4 +937,4 @@

const normalize$2 = (input, schema) => {
const schemaType = expectedSchemaType(schema);
var normalize$1 = function normalize(input, schema) {
var schemaType = expectedSchemaType(schema);

@@ -757,3 +944,3 @@ if (input === null || typeof input !== schemaType) {

if (process.env.NODE_ENV !== 'production') {
const parseWorks = input => {
var parseWorks = function parseWorks(input) {
try {

@@ -767,35 +954,27 @@ return typeof JSON.parse(input) !== 'string';

if (typeof input === 'string' && parseWorks(input)) {
throw new Error(`Normalizing a string, but this does match schema.
Parsing this input string as JSON worked. This likely indicates fetch function did not parse
the JSON. By default, this only happens if "content-type" header includes "json".
See https://resthooks.io/docs/guides/custom-networking for more information
Schema: ${JSON.stringify(schema, undefined, 2)}
Input: "${input}"`);
throw 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(schema, undefined, 2) + "\n Input: \"" + input + "\"");
} else {
throw new Error(`Unexpected input given to normalize. Expected type to be "${schemaType}", found "${input === null ? 'null' : typeof input}".
Schema: ${JSON.stringify(schema, undefined, 2)}
Input: "${input}"`);
throw new Error("Unexpected input given to normalize. Expected type to be \"" + schemaType + "\", found \"" + (input === null ? 'null' : typeof input) + "\".\n\n Schema: " + JSON.stringify(schema, undefined, 2) + "\n Input: \"" + input + "\"");
}
} else {
throw new Error(`Unexpected input given to normalize. Expected type to be "${schemaType}", found "${input === null ? 'null' : typeof input}".`);
throw new Error("Unexpected input given to normalize. Expected type to be \"" + schemaType + "\", found \"" + (input === null ? 'null' : typeof input) + "\".");
}
}
const entities = {};
const indexes = {};
const addEntity = addEntities(entities, indexes);
const visitedEntities = {};
const result = visit(input, input, undefined, schema, addEntity, visitedEntities);
var entities = {};
var indexes = {};
var addEntity = addEntities(entities, indexes);
var visitedEntities = {};
var result = visit(input, input, undefined, schema, addEntity, visitedEntities);
return {
entities,
indexes,
result
entities: entities,
indexes: indexes,
result: result
};
};
class UnionSchema extends PolymorphicSchema {
constructor(definition, schemaAttribute) {
var UnionSchema = /*#__PURE__*/function (_PolymorphicSchema) {
_inheritsLoose(UnionSchema, _PolymorphicSchema);
function UnionSchema(definition, schemaAttribute) {
if (!schemaAttribute) {

@@ -805,32 +984,53 @@ throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');

super(definition, schemaAttribute);
return _PolymorphicSchema.call(this, definition, schemaAttribute) || this;
}
normalize(input, parent, key, visit, addEntity, visitedEntities) {
var _proto = UnionSchema.prototype;
_proto.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {
return this.normalizeValue(input, parent, key, visit, addEntity, visitedEntities);
}
};
denormalize(input, unvisit) {
_proto.denormalize = function denormalize(input, unvisit) {
return this.denormalizeValue(input, unvisit);
};
return UnionSchema;
}(PolymorphicSchema);
var ValuesSchema = /*#__PURE__*/function (_PolymorphicSchema) {
_inheritsLoose(ValuesSchema, _PolymorphicSchema);
function ValuesSchema() {
return _PolymorphicSchema.apply(this, arguments) || this;
}
}
var _proto = ValuesSchema.prototype;
class ValuesSchema extends PolymorphicSchema {
normalize(input, parent, key, visit, addEntity, visitedEntities) {
return Object.keys(input).reduce((output, key, index) => {
const value = input[key];
return value !== undefined && value !== null ? { ...output,
[key]: this.normalizeValue(value, input, key, visit, addEntity, visitedEntities)
} : output;
_proto.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {
var _this = this;
return Object.keys(input).reduce(function (output, key, index) {
var _Object$assign;
var value = input[key];
return value !== undefined && value !== null ? Object.assign({}, output, (_Object$assign = {}, _Object$assign[key] = _this.normalizeValue(value, input, key, visit, addEntity, visitedEntities), _Object$assign)) : output;
}, {});
}
};
denormalize(input, unvisit) {
let found = true;
let deleted = false;
return [Object.keys(input).reduce((output, key) => {
const entityOrId = input[key];
const [value, foundItem, deletedItem] = this.denormalizeValue(entityOrId, unvisit);
_proto.denormalize = function denormalize(input, unvisit) {
var _this2 = this;
var found = true;
var deleted = false;
return [Object.keys(input).reduce(function (output, key) {
var _Object$assign2;
var entityOrId = input[key];
var _this2$denormalizeVal = _this2.denormalizeValue(entityOrId, unvisit),
value = _this2$denormalizeVal[0],
foundItem = _this2$denormalizeVal[1],
deletedItem = _this2$denormalizeVal[2];
if (!foundItem) {

@@ -845,13 +1045,13 @@ found = false;

if (!foundItem || deletedItem) return output;
return { ...output,
[key]: value
};
return Object.assign({}, output, (_Object$assign2 = {}, _Object$assign2[key] = value, _Object$assign2));
}, {}), found, deleted];
}
};
}
return ValuesSchema;
}(PolymorphicSchema);
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
class Delete {
constructor(entity) {
var Delete = /*#__PURE__*/function () {
function Delete(entity) {
if (process.env.NODE_ENV !== 'production' && !entity) {

@@ -864,36 +1064,39 @@ throw new Error('Expected option "entity" not found on DeleteSchema.');

normalize(input, parent, key, visit, addEntity, visitedEntities) {
var _proto = Delete.prototype;
_proto.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {
// 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._entity.fromJS(input, parent, key);
var processedEntity = this._entity.fromJS(input, parent, key);
const id = processedEntity.pk(parent, key);
var id = processedEntity.pk(parent, key);
addEntity(this._entity, DELETED, processedEntity, parent, key);
return id;
}
};
denormalize(id, unvisit) {
_proto.denormalize = function denormalize(id, unvisit) {
return unvisit(id, this._entity);
}
/* istanbul ignore next */
;
_denormalizeNullable() {
_proto._denormalizeNullable = function _denormalizeNullable() {
return [];
}
/* istanbul ignore next */
;
_normalizeNullable() {
_proto._normalizeNullable = function _normalizeNullable() {
return [];
}
/* istanbul ignore next */
;
merge(existing, incoming) {
_proto.merge = function merge(existing, incoming) {
return incoming;
}
};
}
return Delete;
}();

@@ -915,5 +1118,5 @@ /* istanbul ignore file */

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

@@ -34,10 +34,14 @@ (function (global, factory) {

function denormalizeImmutable(schema, input, unvisit) {
let found = true;
let deleted = false;
return [Object.keys(schema).reduce((object, key) => {
var found = true;
var deleted = false;
return [Object.keys(schema).reduce(function (object, key) {
// Immutable maps cast keys to strings on write so we need to ensure
// we're accessing them using string keys.
const stringKey = `${key}`;
const [item, foundItem, deletedItem] = unvisit(object.get(stringKey), schema[stringKey]);
var stringKey = "" + key;
var _unvisit = unvisit(object.get(stringKey), schema[stringKey]),
item = _unvisit[0],
foundItem = _unvisit[1],
deletedItem = _unvisit[2];
if (!foundItem) {

@@ -59,6 +63,30 @@ found = false;

class PolymorphicSchema {
constructor(definition, schemaAttribute) {
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
var PolymorphicSchema = /*#__PURE__*/function () {
function PolymorphicSchema(definition, schemaAttribute) {
if (schemaAttribute) {
this._schemaAttribute = typeof schemaAttribute === 'string' ? input => input[schemaAttribute] : schemaAttribute;
this._schemaAttribute = typeof schemaAttribute === 'string' ? function (input) {
return input[schemaAttribute];
} : schemaAttribute;
}

@@ -69,15 +97,13 @@

get isSingleSchema() {
return !this._schemaAttribute;
}
var _proto = PolymorphicSchema.prototype;
define(definition) {
_proto.define = function define(definition) {
this.schema = definition;
}
};
getSchemaAttribute(input, parent, key) {
_proto.getSchemaAttribute = function getSchemaAttribute(input, parent, key) {
return !this.isSingleSchema && this._schemaAttribute(input, parent, key);
}
};
inferSchema(input, parent, key) {
_proto.inferSchema = function inferSchema(input, parent, key) {
if (this.isSingleSchema) {

@@ -87,8 +113,8 @@ return this.schema;

const attr = this.getSchemaAttribute(input, parent, key);
var attr = this.getSchemaAttribute(input, parent, key);
return this.schema[attr];
}
};
normalizeValue(value, parent, key, visit, addEntity, visitedEntities) {
const schema = this.inferSchema(value, parent, key);
_proto.normalizeValue = function normalizeValue(value, parent, key, visit, addEntity, visitedEntities) {
var schema = this.inferSchema(value, parent, key);

@@ -99,3 +125,3 @@ if (!schema) {

const normalizedValue = visit(value, parent, key, schema, addEntity, visitedEntities);
var normalizedValue = visit(value, parent, key, schema, addEntity, visitedEntities);
return this.isSingleSchema || normalizedValue === undefined || normalizedValue === null ? normalizedValue : {

@@ -105,6 +131,6 @@ id: normalizedValue,

};
}
};
denormalizeValue(value, unvisit) {
const schemaKey = isImmutable(value) ? value.get('schema') : value.schema;
_proto.denormalizeValue = function denormalizeValue(value, unvisit) {
var schemaKey = isImmutable(value) ? value.get('schema') : value.schema;

@@ -115,16 +141,24 @@ if (!this.isSingleSchema && !schemaKey) {

const id = this.isSingleSchema ? undefined : isImmutable(value) ? value.get('id') : value.id;
const schema = this.isSingleSchema ? this.schema : this.schema[schemaKey];
var id = this.isSingleSchema ? undefined : isImmutable(value) ? value.get('id') : value.id;
var schema = this.isSingleSchema ? this.schema : this.schema[schemaKey];
return unvisit(id || value, schema);
}
};
}
_createClass(PolymorphicSchema, [{
key: "isSingleSchema",
get: function get() {
return !this._schemaAttribute;
}
}]);
const DELETED = Symbol('ENTITY WAS DELETED');
return PolymorphicSchema;
}();
const validateSchema = definition => {
const isArray = Array.isArray(definition);
var DELETED = Symbol('ENTITY WAS DELETED');
var validateSchema = function validateSchema(definition) {
var isArray = Array.isArray(definition);
if (isArray && definition.length > 1) {
throw new Error(`Expected schema definition to be a single schema, but found ${definition.length}.`);
throw new Error("Expected schema definition to be a single schema, but found " + definition.length + ".");
}

@@ -135,49 +169,92 @@

const getValues = input => Array.isArray(input) ? input : Object.keys(input).map(key => input[key]);
var getValues = function getValues(input) {
return Array.isArray(input) ? input : Object.keys(input).map(function (key) {
return input[key];
});
};
const filterEmpty = ([, foundItem, deletedItem]) => foundItem && !deletedItem;
var filterEmpty = function filterEmpty(_ref) {
var foundItem = _ref[1],
deletedItem = _ref[2];
return foundItem && !deletedItem;
};
const normalize = (schema, input, parent, key, visit, addEntity, visitedEntities) => {
var normalize = function normalize(schema, input, parent, key, visit, addEntity, visitedEntities) {
schema = validateSchema(schema);
const values = getValues(input); // Special case: Arrays pass *their* parent on to their children, since there
var values = getValues(input); // Special case: Arrays pass *their* parent on to their children, since there
// is not any special information that can be gathered from themselves directly
return values.map((value, index) => visit(value, parent, key, schema, addEntity, visitedEntities));
return values.map(function (value, index) {
return visit(value, parent, key, schema, addEntity, visitedEntities);
});
};
const denormalize = (schema, input, unvisit) => {
var denormalize = function denormalize(schema, input, unvisit) {
schema = validateSchema(schema);
let deleted = false;
let found = true;
var deleted = false;
var found = true;
if (input === undefined && schema) {
[, found, deleted] = unvisit(undefined, schema);
var _unvisit = unvisit(undefined, schema);
found = _unvisit[1];
deleted = _unvisit[2];
}
return [input && input.map ? input.map(entityOrId => unvisit(entityOrId, schema)).filter(filterEmpty).map(([value]) => value) : input, found, deleted];
return [input && input.map ? input.map(function (entityOrId) {
return unvisit(entityOrId, schema);
}).filter(filterEmpty).map(function (_ref2) {
var value = _ref2[0];
return value;
}) : input, found, deleted];
};
class ArraySchema extends PolymorphicSchema {
normalize(input, parent, key, visit, addEntity, visitedEntities) {
const values = getValues(input);
return values.map((value, index) => this.normalizeValue(value, parent, key, visit, addEntity, visitedEntities)).filter(value => value !== undefined && value !== null);
var ArraySchema = /*#__PURE__*/function (_PolymorphicSchema) {
_inheritsLoose(ArraySchema, _PolymorphicSchema);
function ArraySchema() {
return _PolymorphicSchema.apply(this, arguments) || this;
}
denormalize(input, unvisit) {
let deleted = false;
let found = true;
var _proto = ArraySchema.prototype;
_proto.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {
var _this = this;
var values = getValues(input);
return values.map(function (value, index) {
return _this.normalizeValue(value, parent, key, visit, addEntity, visitedEntities);
}).filter(function (value) {
return value !== undefined && value !== null;
});
};
_proto.denormalize = function denormalize(input, unvisit) {
var _this2 = this;
var deleted = false;
var found = true;
if (input === undefined && this.schema) {
[, found, deleted] = unvisit(undefined, this.schema);
var _unvisit2 = unvisit(undefined, this.schema);
found = _unvisit2[1];
deleted = _unvisit2[2];
}
return [input && input.map ? input.map(entityOrId => this.denormalizeValue(entityOrId, unvisit)).filter(filterEmpty).map(([value]) => value) : input, found, deleted];
}
return [input && input.map ? input.map(function (entityOrId) {
return _this2.denormalizeValue(entityOrId, unvisit);
}).filter(filterEmpty).map(function (_ref3) {
var value = _ref3[0];
return value;
}) : input, found, deleted];
};
}
return ArraySchema;
}(PolymorphicSchema);
const normalize$1 = (schema, input, parent, key, visit, addEntity, visitedEntities) => {
const object = { ...input
};
Object.keys(schema).forEach(key => {
const localSchema = schema[key];
const value = visit(input[key], input, key, localSchema, addEntity, visitedEntities);
var _normalize = function normalize(schema, input, parent, key, visit, addEntity, visitedEntities) {
var object = Object.assign({}, input);
Object.keys(schema).forEach(function (key) {
var localSchema = schema[key];
var value = visit(input[key], input, key, localSchema, addEntity, visitedEntities);

@@ -192,3 +269,4 @@ if (value === undefined || value === null) {

};
const denormalize$1 = (schema, input, unvisit) => {
var _denormalize = function denormalize(schema, input, unvisit) {
if (isImmutable(input)) {

@@ -198,8 +276,10 @@ return denormalizeImmutable(schema, input, unvisit);

const object = { ...input
};
let found = true;
let deleted = false;
Object.keys(schema).forEach(key => {
const [item, foundItem, deletedItem] = unvisit(object[key], schema[key]);
var object = Object.assign({}, input);
var found = true;
var deleted = false;
Object.keys(schema).forEach(function (key) {
var _unvisit = unvisit(object[key], schema[key]),
item = _unvisit[0],
foundItem = _unvisit[1],
deletedItem = _unvisit[2];

@@ -220,38 +300,97 @@ if (object[key] !== undefined) {

};
class ObjectSchema {
constructor(definition) {
var ObjectSchema = /*#__PURE__*/function () {
function ObjectSchema(definition) {
this.define(definition);
}
define(definition) {
this.schema = Object.keys(definition).reduce((entitySchema, key) => {
const schema = definition[key];
return { ...entitySchema,
[key]: schema
};
var _proto = ObjectSchema.prototype;
_proto.define = function define(definition) {
this.schema = Object.keys(definition).reduce(function (entitySchema, key) {
var _Object$assign;
var schema = definition[key];
return Object.assign({}, entitySchema, (_Object$assign = {}, _Object$assign[key] = schema, _Object$assign));
}, this.schema || {});
}
};
normalize(...args) {
return normalize$1(this.schema, ...args);
_proto.normalize = function normalize() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _normalize.apply(void 0, [this.schema].concat(args));
};
_proto.denormalize = function denormalize() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return _denormalize.apply(void 0, [this.schema].concat(args));
};
return ObjectSchema;
}();
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) {
arr2[i] = arr[i];
}
denormalize(...args) {
return denormalize$1(this.schema, ...args);
return arr2;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
var it;
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
if (it) o = it;
var i = 0;
return function () {
if (i >= o.length) return {
done: true
};
return {
done: false,
value: o[i++]
};
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
it = o[Symbol.iterator]();
return it.next.bind(it);
}
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
const DefinedMembersKey = Symbol('Defined Members');
const UniqueIdentifierKey = Symbol('unq');
var DefinedMembersKey = Symbol('Defined Members');
var UniqueIdentifierKey = Symbol('unq');
/** Immutable record that keeps track of which members are defined vs defaults. */
class SimpleRecord {
toString() {
var SimpleRecord = /*#__PURE__*/function () {
function SimpleRecord() {}
var _proto = SimpleRecord.prototype;
_proto.toString = function toString() {
// we don't make _unq a member so it doesn't play a role in type compatibility
return this[UniqueIdentifierKey];
}
};
static toJSON() {
SimpleRecord.toJSON = function toJSON() {
return {

@@ -263,4 +402,4 @@ name: this.name,

/** Defines nested entities */
;
/** Factory method to convert from Plain JS Objects.

@@ -272,6 +411,10 @@ *

*/
static fromJS( // TODO: this should only accept members that are not functions
props = {}, parent, key) {
SimpleRecord.fromJS = function fromJS( // TODO: this should only accept members that are not functions
props, parent, key) {
if (props === void 0) {
props = {};
}
// we type guarded abstract case above, so ok to force typescript to allow constructor call
const instance = new this(props);
var instance = new this(props);

@@ -289,3 +432,3 @@ if (props instanceof SimpleRecord) {

Object.defineProperty(instance, UniqueIdentifierKey, {
value: `${Math.random()}`,
value: "" + Math.random(),
writable: false

@@ -296,21 +439,22 @@ });

/** Creates new instance copying over defined values of arguments */
;
static merge(existing, incoming) {
const props = Object.assign(this.toObjectDefined(existing), this.toObjectDefined(incoming));
SimpleRecord.merge = function merge(existing, incoming) {
var props = Object.assign(this.toObjectDefined(existing), this.toObjectDefined(incoming));
return this.fromJS(props);
}
/** Whether key is non-default */
;
static hasDefined(instance, key) {
SimpleRecord.hasDefined = function hasDefined(instance, key) {
return instance[DefinedMembersKey].includes(key);
}
/** Returns simple object with all the non-default members */
;
SimpleRecord.toObjectDefined = function toObjectDefined(instance) {
var defined = {};
static toObjectDefined(instance) {
const defined = {};
for (const member of instance[DefinedMembersKey]) {
for (var _iterator = _createForOfIteratorHelperLoose(instance[DefinedMembersKey]), _step; !(_step = _iterator()).done;) {
var member = _step.value;
defined[member] = instance[member];

@@ -322,21 +466,29 @@ }

/** Returns array of all keys that have values defined in instance */
;
static keysDefined(instance) {
SimpleRecord.keysDefined = function keysDefined(instance) {
return instance[DefinedMembersKey];
}
};
static normalize(...args) {
return normalize$1(this.schema, ...args);
}
SimpleRecord.normalize = function normalize() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
static denormalize(input, unvisit) {
return _normalize.apply(void 0, [this.schema].concat(args));
};
SimpleRecord.denormalize = function denormalize(input, unvisit) {
var _this = this;
// TODO: This creates unneeded memory pressure
const instance = new this();
const object = { ...input
};
let deleted = false;
let found = true;
Object.keys(this.schema).forEach(key => {
const [item, foundItem, deletedItem] = unvisit(object[key], this.schema[key]);
var instance = new this();
var object = Object.assign({}, input);
var deleted = false;
var found = true;
Object.keys(this.schema).forEach(function (key) {
var _unvisit = unvisit(object[key], _this.schema[key]),
item = _unvisit[0],
foundItem = _unvisit[1],
deletedItem = _unvisit[2];

@@ -361,5 +513,5 @@ if (object[key] !== undefined) {

/* istanbul ignore next */
;
static asSchema() {
SimpleRecord.asSchema = function asSchema() {
/* istanbul ignore next */

@@ -373,15 +525,21 @@ if (process.env.NODE_ENV === 'development') {

return this;
}
};
}
return SimpleRecord;
}();
SimpleRecord.schema = {};
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/** Represents data that should be deduped by specifying a primary key. */
var Entity = /*#__PURE__*/function (_SimpleRecord) {
_inheritsLoose(Entity, _SimpleRecord);
/** Represents data that should be deduped by specifying a primary key. */
class Entity extends SimpleRecord {
static toJSON() {
return { ...super.toJSON(),
function Entity() {
return _SimpleRecord.apply(this, arguments) || this;
}
Entity.toJSON = function toJSON() {
return Object.assign({}, _SimpleRecord.toJSON.call(this), {
key: this.key
};
});
}

@@ -394,13 +552,4 @@ /**

*/
;
/** Returns the globally unique identifier for the static Entity */
static get key() {
/* istanbul ignore next */
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;
}
/** Defines indexes to enable lookup by */
/**

@@ -413,20 +562,27 @@ * A unique identifier for each Entity

*/
static pk(value, parent, key) {
Entity.pk = function pk(value, parent, key) {
return this.prototype.pk.call(value, parent, key) || key;
}
};
static normalize(input, parent, key, visit, addEntity, visitedEntities) {
Entity.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {
var _this = this;
// 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);
var processedEntity = this.fromJS(input, parent, key);
/* istanbul ignore else */
if (process.env.NODE_ENV !== 'production') {
const instanceSample = new this();
const keysOfRecord = new Set(Object.keys(instanceSample));
const keysOfProps = this.keysDefined(processedEntity);
const [found, missing, unexpected] = [[], [], []];
var instanceSample = new this();
var keysOfRecord = new Set(Object.keys(instanceSample));
var keysOfProps = this.keysDefined(processedEntity);
var _ref = [[], [], []],
found = _ref[0],
missing = _ref[1],
unexpected = _ref[2];
for (const keyOfProps of keysOfProps) {
for (var _iterator = _createForOfIteratorHelperLoose(keysOfProps), _step; !(_step = _iterator()).done;) {
var keyOfProps = _step.value;
if (keysOfRecord.has(keyOfProps)) {

@@ -439,3 +595,5 @@ found.push(keyOfProps);

for (const keyOfRecord of keysOfRecord) {
for (var _iterator2 = _createForOfIteratorHelperLoose(keysOfRecord), _step2; !(_step2 = _iterator2()).done;) {
var keyOfRecord = _step2.value;
if (!found.includes(keyOfRecord)) {

@@ -448,12 +606,3 @@ missing.push(keyOfRecord);

if ((Math.max(keysOfProps.length / 2, 1) <= unexpected.length && keysOfRecord.size > Math.max(unexpected.length, 2) || found.length < Math.min(1, keysOfRecord.size / 2)) && keysOfRecord.size) {
const error = new Error(`Attempted to initialize ${this.name} with substantially different than expected keys
This is likely due to a malformed response.
Try inspecting the network response or fetch() return value.
Expected keys:
Found: ${found}
Missing: ${missing}
Unexpected keys: ${unexpected}
Value: ${JSON.stringify(this.toObjectDefined(processedEntity), null, 2)}`);
var error = 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: " + found + "\n Missing: " + missing + "\n Unexpected keys: " + unexpected + "\n Value: " + JSON.stringify(this.toObjectDefined(processedEntity), null, 2));
error.status = 400;

@@ -464,16 +613,10 @@ throw error;

const id = processedEntity.pk(parent, key);
var id = processedEntity.pk(parent, key);
if (id === undefined || id === '') {
if (process.env.NODE_ENV !== 'production') {
const error = new Error(`Missing usable resource key when normalizing response.
var _error = 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: " + (input && JSON.stringify(input, null, 2)) + "\n ");
This is likely due to a malformed response.
Try inspecting the network response or fetch() return value.
Entity: ${this.name}
Value: ${input && JSON.stringify(input, null, 2)}
`);
error.status = 400;
throw error;
_error.status = 400;
throw _error;
} else {

@@ -485,3 +628,3 @@ // these make the keys get deleted

const entityType = this.key;
var entityType = this.key;

@@ -496,3 +639,5 @@ if (!(entityType in visitedEntities)) {

if (visitedEntities[entityType][id].some(entity => entity === input)) {
if (visitedEntities[entityType][id].some(function (entity) {
return entity === input;
})) {
return id;

@@ -502,6 +647,6 @@ }

visitedEntities[entityType][id].push(input);
Object.keys(this.schema).forEach(key => {
Object.keys(this.schema).forEach(function (key) {
if (Object.hasOwnProperty.call(processedEntity, key)) {
const schema = this.schema[key];
processedEntity[key] = visit(processedEntity[key], processedEntity, key, schema, addEntity, visitedEntities);
var _schema = _this.schema[key];
processedEntity[key] = visit(processedEntity[key], processedEntity, key, _schema, addEntity, visitedEntities);
}

@@ -511,23 +656,34 @@ });

return id;
}
};
static denormalize(entity, unvisit) {
Entity.denormalize = function denormalize(entity, unvisit) {
var _this2 = this;
// 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, deleted] = denormalizeImmutable(this.schema, entity, unvisit);
return [this.fromJS(denormEntity.toObject()), found, deleted];
var _denormalizeImmutable = denormalizeImmutable(this.schema, entity, unvisit),
_denormEntity = _denormalizeImmutable[0],
_found = _denormalizeImmutable[1],
_deleted = _denormalizeImmutable[2];
return [this.fromJS(_denormEntity.toObject()), _found, _deleted];
} // TODO: This creates unneeded memory pressure
const instance = new this();
let deleted = false;
let found = true;
const denormEntity = entity;
Object.keys(this.schema).forEach(key => {
const schema = this.schema[key];
const input = this.hasDefined(entity, key) ? entity[key] : undefined;
const [value, foundItem, deletedItem] = unvisit(input, schema); // members who default to falsy values are considered 'optional'
var instance = new this();
var deleted = false;
var found = true;
var denormEntity = entity;
Object.keys(this.schema).forEach(function (key) {
var schema = _this2.schema[key];
var input = _this2.hasDefined(entity, key) ? entity[key] : undefined;
var _unvisit = unvisit(input, schema),
value = _unvisit[0],
foundItem = _unvisit[1],
deletedItem = _unvisit[2]; // 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])) {

@@ -541,3 +697,3 @@ found = false;

if (this.hasDefined(entity, key) && denormEntity[key] !== value) {
if (_this2.hasDefined(entity, key) && denormEntity[key] !== value) {
denormEntity[key] = value;

@@ -547,6 +703,20 @@ }

return [denormEntity, found, deleted];
}
};
}
_createClass(Entity, null, [{
key: "key",
/** Returns the globally unique identifier for the static Entity */
get: function get() {
/* istanbul ignore next */
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;
}
/** Defines indexes to enable lookup by */
}]);
return Entity;
}(SimpleRecord);
if (process.env.NODE_ENV !== 'production') {

@@ -565,12 +735,19 @@ // for those not using TypeScript this is a good catch to ensure they are defining

class FlatEntity extends Entity {
static denormalize(entity, unvisit) {
return [entity, true, false];
var FlatEntity = /*#__PURE__*/function (_Entity) {
_inheritsLoose(FlatEntity, _Entity);
function FlatEntity() {
return _Entity.apply(this, arguments) || this;
}
}
FlatEntity.denormalize = function denormalize(entity, unvisit) {
return [entity, true, false];
};
const unvisitEntity = (id, schema, unvisit, getEntity, cache) => {
const entity = getEntity(id, schema);
return FlatEntity;
}(Entity);
var unvisitEntity = function unvisitEntity(id, schema, unvisit, getEntity, cache) {
var entity = getEntity(id, schema);
if (entity === DELETED) {

@@ -588,12 +765,17 @@ return [undefined, true, true];

let found = true;
let deleted = false;
var found = true;
var deleted = false;
if (!cache[schema.key][id]) {
// Ensure we don't mutate it non-immutable objects
const entityCopy = isImmutable(entity) || entity instanceof FlatEntity ? entity : schema.fromJS(entity); // Need to set this first so that if it is referenced further within the
var entityCopy = isImmutable(entity) || entity instanceof FlatEntity ? entity : schema.fromJS(entity); // Need to set this first so that if it is referenced further within the
// denormalization the reference will already exist.
cache[schema.key][id] = entityCopy;
[cache[schema.key][id], found, deleted] = schema.denormalize(entityCopy, unvisit);
var _schema$denormalize = schema.denormalize(entityCopy, unvisit);
cache[schema.key][id] = _schema$denormalize[0];
found = _schema$denormalize[1];
deleted = _schema$denormalize[2];
}

@@ -604,5 +786,5 @@

const getUnvisit = entities => {
const cache = {};
const getEntity = getEntities(entities);
var getUnvisit = function getUnvisit(entities) {
var cache = {};
var getEntity = getEntities(entities);
return [function unvisit(input, schema) {

@@ -616,3 +798,3 @@ if (!schema) return [input, true, false];

} else if (typeof schema === 'object') {
const method = Array.isArray(schema) ? denormalize : denormalize$1;
var method = Array.isArray(schema) ? denormalize : _denormalize;
return method(schema, input, unvisit);

@@ -644,6 +826,6 @@ }

const getEntities = entities => {
const isImmutable$1 = isImmutable(entities);
return (entityOrId, schema) => {
const schemaKey = schema.key;
var getEntities = function getEntities(entities) {
var isImmutable$1 = isImmutable(entities);
return function (entityOrId, schema) {
var schemaKey = schema.key;

@@ -663,3 +845,3 @@ if (typeof entityOrId === 'object') {

const denormalize$2 = (input, schema, entities) => {
var denormalize$1 = function denormalize(input, schema, entities) {
/* istanbul ignore next */

@@ -669,4 +851,7 @@ if (process.env.NODE_ENV !== 'production' && schema === undefined) throw new Error('schema needed');

if (typeof input !== 'undefined') {
const [unvisit, cache] = getUnvisit(entities);
return [...unvisit(input, schema), cache];
var _getUnvisit = getUnvisit(entities),
unvisit = _getUnvisit[0],
cache = _getUnvisit[1];
return [].concat(unvisit(input, schema), [cache]);
}

@@ -677,3 +862,3 @@

const visit = (value, parent, key, schema, addEntity, visitedEntities) => {
var visit = function visit(value, parent, key, schema, addEntity, visitedEntities) {
if (!value || !schema || !['function', 'object'].includes(typeof schema)) {

@@ -689,3 +874,3 @@ return value;

const method = Array.isArray(schema) ? normalize : normalize$1;
var method = Array.isArray(schema) ? normalize : _normalize;
return method(schema, value, parent, key, visit, addEntity, visitedEntities);

@@ -697,49 +882,51 @@ }

const addEntities = (entities, indexes) => (schema, processedEntity, value, parent, key) => {
const schemaKey = schema.key;
const id = schema.pk(value, parent, key);
var addEntities = function addEntities(entities, indexes) {
return function (schema, processedEntity, value, parent, key) {
var schemaKey = schema.key;
var id = schema.pk(value, parent, key);
if (!(schemaKey in entities)) {
entities[schemaKey] = {};
}
if (!(schemaKey in entities)) {
entities[schemaKey] = {};
}
const existingEntity = entities[schemaKey][id];
var existingEntity = entities[schemaKey][id];
if (existingEntity) {
entities[schemaKey][id] = schema.merge(existingEntity, processedEntity);
} else {
entities[schemaKey][id] = processedEntity;
} // update index
if (existingEntity) {
entities[schemaKey][id] = schema.merge(existingEntity, processedEntity);
} else {
entities[schemaKey][id] = processedEntity;
} // update index
if (Array.isArray(schema.indexes)) {
const entity = entities[schemaKey][id];
if (Array.isArray(schema.indexes)) {
var entity = entities[schemaKey][id];
if (!(schemaKey in indexes)) {
indexes[schemaKey] = {};
}
for (const index of schema.indexes) {
if (!(index in indexes[schemaKey])) {
indexes[schemaKey][index] = {};
if (!(schemaKey in indexes)) {
indexes[schemaKey] = {};
}
const indexMap = indexes[schemaKey][index];
for (var _iterator = _createForOfIteratorHelperLoose(schema.indexes), _step; !(_step = _iterator()).done;) {
var index = _step.value;
if (existingEntity) {
delete indexMap[existingEntity[index]];
}
if (!(index in indexes[schemaKey])) {
indexes[schemaKey][index] = {};
}
if (index in entity) {
indexMap[entity[index]] = id;
var indexMap = indexes[schemaKey][index];
if (existingEntity) {
delete indexMap[existingEntity[index]];
}
if (index in entity) {
indexMap[entity[index]] = id;
}
/* istanbul ignore next */
else if ( // eslint-disable-next-line no-undef
process.env.NODE_ENV !== 'production') {
console.warn("Index not found in entity. Indexes must be top-level members of your entity.\nIndex: " + index + "\nEntity: " + JSON.stringify(entity, undefined, 2));
}
}
/* istanbul ignore next */
else if ( // eslint-disable-next-line no-undef
process.env.NODE_ENV !== 'production') {
console.warn(`Index not found in entity. Indexes must be top-level members of your entity.
Index: ${index}
Entity: ${JSON.stringify(entity, undefined, 2)}`);
}
}
}
};
};

@@ -752,4 +939,4 @@

const normalize$2 = (input, schema) => {
const schemaType = expectedSchemaType(schema);
var normalize$1 = function normalize(input, schema) {
var schemaType = expectedSchemaType(schema);

@@ -759,3 +946,3 @@ if (input === null || typeof input !== schemaType) {

if (process.env.NODE_ENV !== 'production') {
const parseWorks = input => {
var parseWorks = function parseWorks(input) {
try {

@@ -769,35 +956,27 @@ return typeof JSON.parse(input) !== 'string';

if (typeof input === 'string' && parseWorks(input)) {
throw new Error(`Normalizing a string, but this does match schema.
Parsing this input string as JSON worked. This likely indicates fetch function did not parse
the JSON. By default, this only happens if "content-type" header includes "json".
See https://resthooks.io/docs/guides/custom-networking for more information
Schema: ${JSON.stringify(schema, undefined, 2)}
Input: "${input}"`);
throw 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(schema, undefined, 2) + "\n Input: \"" + input + "\"");
} else {
throw new Error(`Unexpected input given to normalize. Expected type to be "${schemaType}", found "${input === null ? 'null' : typeof input}".
Schema: ${JSON.stringify(schema, undefined, 2)}
Input: "${input}"`);
throw new Error("Unexpected input given to normalize. Expected type to be \"" + schemaType + "\", found \"" + (input === null ? 'null' : typeof input) + "\".\n\n Schema: " + JSON.stringify(schema, undefined, 2) + "\n Input: \"" + input + "\"");
}
} else {
throw new Error(`Unexpected input given to normalize. Expected type to be "${schemaType}", found "${input === null ? 'null' : typeof input}".`);
throw new Error("Unexpected input given to normalize. Expected type to be \"" + schemaType + "\", found \"" + (input === null ? 'null' : typeof input) + "\".");
}
}
const entities = {};
const indexes = {};
const addEntity = addEntities(entities, indexes);
const visitedEntities = {};
const result = visit(input, input, undefined, schema, addEntity, visitedEntities);
var entities = {};
var indexes = {};
var addEntity = addEntities(entities, indexes);
var visitedEntities = {};
var result = visit(input, input, undefined, schema, addEntity, visitedEntities);
return {
entities,
indexes,
result
entities: entities,
indexes: indexes,
result: result
};
};
class UnionSchema extends PolymorphicSchema {
constructor(definition, schemaAttribute) {
var UnionSchema = /*#__PURE__*/function (_PolymorphicSchema) {
_inheritsLoose(UnionSchema, _PolymorphicSchema);
function UnionSchema(definition, schemaAttribute) {
if (!schemaAttribute) {

@@ -807,32 +986,53 @@ throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');

super(definition, schemaAttribute);
return _PolymorphicSchema.call(this, definition, schemaAttribute) || this;
}
normalize(input, parent, key, visit, addEntity, visitedEntities) {
var _proto = UnionSchema.prototype;
_proto.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {
return this.normalizeValue(input, parent, key, visit, addEntity, visitedEntities);
}
};
denormalize(input, unvisit) {
_proto.denormalize = function denormalize(input, unvisit) {
return this.denormalizeValue(input, unvisit);
};
return UnionSchema;
}(PolymorphicSchema);
var ValuesSchema = /*#__PURE__*/function (_PolymorphicSchema) {
_inheritsLoose(ValuesSchema, _PolymorphicSchema);
function ValuesSchema() {
return _PolymorphicSchema.apply(this, arguments) || this;
}
}
var _proto = ValuesSchema.prototype;
class ValuesSchema extends PolymorphicSchema {
normalize(input, parent, key, visit, addEntity, visitedEntities) {
return Object.keys(input).reduce((output, key, index) => {
const value = input[key];
return value !== undefined && value !== null ? { ...output,
[key]: this.normalizeValue(value, input, key, visit, addEntity, visitedEntities)
} : output;
_proto.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {
var _this = this;
return Object.keys(input).reduce(function (output, key, index) {
var _Object$assign;
var value = input[key];
return value !== undefined && value !== null ? Object.assign({}, output, (_Object$assign = {}, _Object$assign[key] = _this.normalizeValue(value, input, key, visit, addEntity, visitedEntities), _Object$assign)) : output;
}, {});
}
};
denormalize(input, unvisit) {
let found = true;
let deleted = false;
return [Object.keys(input).reduce((output, key) => {
const entityOrId = input[key];
const [value, foundItem, deletedItem] = this.denormalizeValue(entityOrId, unvisit);
_proto.denormalize = function denormalize(input, unvisit) {
var _this2 = this;
var found = true;
var deleted = false;
return [Object.keys(input).reduce(function (output, key) {
var _Object$assign2;
var entityOrId = input[key];
var _this2$denormalizeVal = _this2.denormalizeValue(entityOrId, unvisit),
value = _this2$denormalizeVal[0],
foundItem = _this2$denormalizeVal[1],
deletedItem = _this2$denormalizeVal[2];
if (!foundItem) {

@@ -847,13 +1047,13 @@ found = false;

if (!foundItem || deletedItem) return output;
return { ...output,
[key]: value
};
return Object.assign({}, output, (_Object$assign2 = {}, _Object$assign2[key] = value, _Object$assign2));
}, {}), found, deleted];
}
};
}
return ValuesSchema;
}(PolymorphicSchema);
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
class Delete {
constructor(entity) {
var Delete = /*#__PURE__*/function () {
function Delete(entity) {
if (process.env.NODE_ENV !== 'production' && !entity) {

@@ -866,36 +1066,39 @@ throw new Error('Expected option "entity" not found on DeleteSchema.');

normalize(input, parent, key, visit, addEntity, visitedEntities) {
var _proto = Delete.prototype;
_proto.normalize = function normalize(input, parent, key, visit, addEntity, visitedEntities) {
// 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._entity.fromJS(input, parent, key);
var processedEntity = this._entity.fromJS(input, parent, key);
const id = processedEntity.pk(parent, key);
var id = processedEntity.pk(parent, key);
addEntity(this._entity, DELETED, processedEntity, parent, key);
return id;
}
};
denormalize(id, unvisit) {
_proto.denormalize = function denormalize(id, unvisit) {
return unvisit(id, this._entity);
}
/* istanbul ignore next */
;
_denormalizeNullable() {
_proto._denormalizeNullable = function _denormalizeNullable() {
return [];
}
/* istanbul ignore next */
;
_normalizeNullable() {
_proto._normalizeNullable = function _normalizeNullable() {
return [];
}
/* istanbul ignore next */
;
merge(existing, incoming) {
_proto.merge = function merge(existing, incoming) {
return incoming;
}
};
}
return Delete;
}();

@@ -917,5 +1120,5 @@ /* istanbul ignore file */

exports.SimpleRecord = SimpleRecord;
exports.denormalize = denormalize$2;
exports.denormalize = denormalize$1;
exports.isEntity = isEntity;
exports.normalize = normalize$2;
exports.normalize = normalize$1;
exports.schema = schema;

@@ -922,0 +1125,0 @@

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

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

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

"build": "run-p build:js:*",
"build:js:development": "NODE_ENV=development rollup -c",
"build:js:production": "NODE_ENV=production rollup -c",
"build:js:development": "BROWSERSLIST_ENV=legacy NODE_ENV=development rollup -c",
"build:js:production": "BROWSERSLIST_ENV=legacy NODE_ENV=production rollup -c",
"build:js:es_development": "BROWSERSLIST_ENV=production NODE_ENV=development rollup -c",

@@ -50,2 +50,5 @@ "build:js:bundle": "BROWSERSLIST_ENV=production NODE_ENV=production rollup -c",

},
"browserslist": [
"extends @anansi/browserslist-config"
],
"author": "Nathaniel Tucker",

@@ -64,3 +67,3 @@ "contributors": [

},
"gitHead": "796bad7931b65611c4c4c1532e851e67ea6ad97b"
"gitHead": "9f1c93016d32dbb9c93e33b14e225debf1febe56"
}
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