@rest-hooks/normalizr
Advanced tools
Comparing version 4.0.0-beta.0 to 4.0.0-beta.1
@@ -85,11 +85,11 @@ define(['exports'], function (exports) { 'use strict'; | ||
if (object.has(stringKey)) { | ||
var _unvisit = unvisit(object.get(stringKey), schema[stringKey]), | ||
item = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
var _unvisit = unvisit(object.get(stringKey), schema[stringKey]), | ||
item = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
if (object.has(stringKey)) { | ||
return object.set(stringKey, item); | ||
@@ -221,14 +221,14 @@ } else { | ||
Object.keys(this.schema).forEach(function (key) { | ||
if (entity.hasOwnProperty(key)) { | ||
var schema = _this2.schema[key]; | ||
var schema = _this2.schema[key]; | ||
var _unvisit = unvisit(entity[key], schema), | ||
value = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
var _unvisit = unvisit(entity[key], schema), | ||
value = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
if (entity.hasOwnProperty(key)) { | ||
entity[key] = value; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
} | ||
@@ -428,5 +428,5 @@ }); | ||
var found = true; | ||
return [input && input.map ? input.map(function (entityOrId) { | ||
var _unvisit = unvisit(entityOrId, schema), | ||
value = _unvisit[0], | ||
if (input === undefined && schema) { | ||
var _unvisit = unvisit(undefined, schema), | ||
foundItem = _unvisit[1]; | ||
@@ -437,3 +437,13 @@ | ||
} | ||
} | ||
return [input && input.map ? input.map(function (entityOrId) { | ||
var _unvisit2 = unvisit(entityOrId, schema), | ||
value = _unvisit2[0], | ||
foundItem = _unvisit2[1]; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
return value; | ||
@@ -471,2 +481,12 @@ }).filter(function (entityOrUndefined) { | ||
var found = true; | ||
if (input === undefined && this.schema) { | ||
var _unvisit3 = unvisit(undefined, this.schema), | ||
foundItem = _unvisit3[1]; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
} | ||
return [input && input.map ? input.map(function (entityOrId) { | ||
@@ -515,12 +535,12 @@ var _this2$denormalizeVal = _this2.denormalizeValue(entityOrId, unvisit), | ||
Object.keys(schema).forEach(function (key) { | ||
var _unvisit = unvisit(object[key], schema[key]), | ||
item = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
if (object[key] != null) { | ||
var _unvisit = unvisit(object[key], schema[key]), | ||
item = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
object[key] = item; | ||
} | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
@@ -658,5 +678,6 @@ }); | ||
return method(schema, input, unvisit); | ||
} | ||
} // null is considered intentional, thus always 'found' as true | ||
if (input === undefined || input === null) { | ||
if (input === null) { | ||
return [input, true]; | ||
@@ -666,2 +687,7 @@ } | ||
if (schema instanceof EntitySchema) { | ||
// unvisitEntity just can't handle undefined | ||
if (input === undefined) { | ||
return [input, false]; | ||
} | ||
return unvisitEntity(input, schema, unvisit, getEntity, cache); | ||
@@ -668,0 +694,0 @@ } |
@@ -1,1 +0,1 @@ | ||
define(["exports"],(function(e){"use strict";function t(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function n(e){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?r(i,!0).forEach((function(r){t(e,r,i[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):r(i).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function i(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(e.hasOwnProperty("__ownerID")||e._map&&e._map.hasOwnProperty("__ownerID")))}function o(e,t,r){var n=!0;return[Object.keys(e).reduce((function(t,i){var o=""+i;if(t.has(o)){var u=r(t.get(o),e[o]),c=u[0];return u[1]||(n=!1),t.set(o,c)}return t}),t),n]}function u(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function c(e,t,r){return t&&u(e.prototype,t),r&&u(e,r),e}var a=function(e){return function(t){return i(t)?t.get(e):t[e]}},f=function(){function e(e,t,r){if(void 0===t&&(t={}),void 0===r&&(r={}),!e||"string"!=typeof e)throw new Error("Expected a string key for Entity, but found "+e+".");var i=r,o=i.idAttribute,u=void 0===o?"id":o,c=i.mergeStrategy,f=void 0===c?function(e,t){return n({},e,{},t)}:c,s=i.processStrategy,h=void 0===s?function(e){return n({},e)}:s;this._key=e,this._getId="function"==typeof u?u:a(u),this._idAttribute=u,this._mergeStrategy=f,this._processStrategy=h,this.define(t)}var t=e.prototype;return t.define=function(e){this.schema=Object.keys(e).reduce((function(t,r){var i,o=e[r];return n({},t,((i={})[r]=o,i))}),this.schema||{})},t.getId=function(e,t,r){return this._getId(e,t,r)},t.merge=function(e,t){return this._mergeStrategy(e,t)},t.normalize=function(e,t,r,n,i,o){var u=this,c=this.getId(e,t,r),a=this.key;if(a in o||(o[a]={}),c in o[a]||(o[a][c]=[]),o[a][c].some((function(t){return t===e})))return c;o[a][c].push(e);var f=this._processStrategy(e,t,r);return Object.keys(this.schema).forEach((function(e){if(f.hasOwnProperty(e)&&"object"==typeof f[e]){var t=u.schema[e];f[e]=n(f[e],f,e,t,i,o)}})),i(this,f,e,t,r),c},t.denormalize=function(e,t){var r=this;if(i(e))return o(this.schema,e,t);var n=!0;return Object.keys(this.schema).forEach((function(i){if(e.hasOwnProperty(i)){var o=r.schema[i],u=t(e[i],o),c=u[0],a=u[1];e[i]=c,a||(n=!1)}})),[e,n]},c(e,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),e}();function s(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var h=function(){function e(e,t){t&&(this._schemaAttribute="string"==typeof t?function(e){return e[t]}:t),this.define(e)}var t=e.prototype;return t.define=function(e){this.schema=e},t.getSchemaAttribute=function(e,t,r){return!this.isSingleSchema&&this._schemaAttribute(e,t,r)},t.inferSchema=function(e,t,r){if(this.isSingleSchema)return this.schema;var n=this.getSchemaAttribute(e,t,r);return this.schema[n]},t.normalizeValue=function(e,t,r,n,i,o){var u=this.inferSchema(e,t,r);if(!u)return e;var c=n(e,t,r,u,i,o);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,r)}},t.denormalizeValue=function(e,t){var r=i(e)?e.get("schema"):e.schema;return this.isSingleSchema||r?t((i(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[r]):[e,!0]},c(e,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),e}(),l=function(e){function t(t,r){if(!r)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return e.call(this,t,r)||this}s(t,e);var r=t.prototype;return r.normalize=function(e,t,r,n,i,o){return this.normalizeValue(e,t,r,n,i,o)},r.denormalize=function(e,t){return this.denormalizeValue(e,t)},t}(h),y=function(e){function t(){return e.apply(this,arguments)||this}s(t,e);var r=t.prototype;return r.normalize=function(e,t,r,i,o,u){var c=this;return Object.keys(e).reduce((function(t,r,a){var f,s=e[r];return null!=s?n({},t,((f={})[r]=c.normalizeValue(s,e,r,i,o,u),f)):t}),{})},r.denormalize=function(e,t){var r=this,i=!0;return[Object.keys(e).reduce((function(o,u){var c,a=e[u],f=r.denormalizeValue(a,t),s=f[0];return f[1]||(i=!1),n({},o,((c={})[u]=s,c))}),{}),i]},t}(h),p=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]},m=function(e){return Array.isArray(e)?e:Object.keys(e).map((function(t){return e[t]}))},v=function(e,t,r,n,i,o,u){return e=p(e),m(t).map((function(t,c){return i(t,r,n,e,o,u)}))},d=function(e,t,r){e=p(e);var n=!0;return[t&&t.map?t.map((function(t){var i=r(t,e),o=i[0];return i[1]||(n=!1),o})).filter((function(e){return e})):t,n]},b=function(e){function t(){return e.apply(this,arguments)||this}s(t,e);var r=t.prototype;return r.normalize=function(e,t,r,n,i,o){var u=this;return m(e).map((function(e,c){return u.normalizeValue(e,t,r,n,i,o)})).filter((function(e){return null!=e}))},r.denormalize=function(e,t){var r=this,n=!0;return[e&&e.map?e.map((function(e){var i=r.denormalizeValue(e,t),o=i[0];return i[1]||(n=!1),o})).filter((function(e){return e})):e,n]},t}(h),g=function(e,t,r,i,o,u,c){var a=n({},t);return Object.keys(e).forEach((function(r){var n=e[r],i=o(t[r],t,r,n,u,c);null==i?delete a[r]:a[r]=i})),a},O=function(e,t,r){if(i(t))return o(e,t,r);var u=n({},t),c=!0;return Object.keys(e).forEach((function(t){if(null!=u[t]){var n=r(u[t],e[t]),i=n[0],o=n[1];u[t]=i,o||(c=!1)}})),[u,c]},j=function e(t,r,n,i,o,u){return"object"==typeof t&&t?"object"!=typeof i||i.normalize&&"function"==typeof i.normalize?i.normalize(t,r,n,e,o,u):(Array.isArray(i)?v:g)(i,t,r,n,e,o,u):t},z={Array:b,Entity:f,Object:function(){function e(e){this.define(e)}var t=e.prototype;return t.define=function(e){this.schema=Object.keys(e).reduce((function(t,r){var i,o=e[r];return n({},t,((i={})[r]=o,i))}),this.schema||{})},t.normalize=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return g.apply(void 0,[this.schema].concat(t))},t.denormalize=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return O.apply(void 0,[this.schema].concat(t))},e}(),Union:l,Values:y},k=function(e){var t={},r=S(e);return function e(o,u){return"object"!=typeof u||u.denormalize&&"function"==typeof u.denormalize?null==o?[o,!0]:u instanceof f?function(e,t,r,o,u){var c=o(e,t);if("object"!=typeof c||null===c)return[c,!1];u[t.key]||(u[t.key]={});var a=!0;if(!u[t.key][e]){var f=i(c)?c:n({},c);u[t.key][e]=f;var s=t.denormalize(f,r);u[t.key][e]=s[0],a=s[1]}return[u[t.key][e],a]}(o,u,e,r,t):"function"==typeof u.denormalize?u.denormalize(o,e):[o,!0]:(Array.isArray(u)?d:O)(u,o,e)}},S=function(e){var t=i(e);return function(r,n){var i=n.key;return"object"==typeof r?r:t?e.getIn([i,r.toString()]):e[i]&&e[i][r]}};e.denormalize=function(e,t,r){return void 0!==e?k(r)(e,t):[void 0,!1]},e.normalize=function(e,t){if(!e||"object"!=typeof e)throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+(null===e?"null":typeof e)+'".');var r={},n=function(e){return function(t,r,n,i,o){var u=t.key,c=t.getId(n,i,o);u in e||(e[u]={});var a=e[u][c];e[u][c]=a?t.merge(a,r):r}}(r);return{entities:r,result:j(e,e,null,t,n,{})}},e.schema=z,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
define(["exports"],(function(e){"use strict";function t(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function n(e){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?r(i,!0).forEach((function(r){t(e,r,i[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):r(i).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function i(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(e.hasOwnProperty("__ownerID")||e._map&&e._map.hasOwnProperty("__ownerID")))}function o(e,t,r){var n=!0;return[Object.keys(e).reduce((function(t,i){var o=""+i,u=r(t.get(o),e[o]),c=u[0];return u[1]||(n=!1),t.has(o)?t.set(o,c):t}),t),n]}function u(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function c(e,t,r){return t&&u(e.prototype,t),r&&u(e,r),e}var a=function(e){return function(t){return i(t)?t.get(e):t[e]}},f=function(){function e(e,t,r){if(void 0===t&&(t={}),void 0===r&&(r={}),!e||"string"!=typeof e)throw new Error("Expected a string key for Entity, but found "+e+".");var i=r,o=i.idAttribute,u=void 0===o?"id":o,c=i.mergeStrategy,f=void 0===c?function(e,t){return n({},e,{},t)}:c,s=i.processStrategy,h=void 0===s?function(e){return n({},e)}:s;this._key=e,this._getId="function"==typeof u?u:a(u),this._idAttribute=u,this._mergeStrategy=f,this._processStrategy=h,this.define(t)}var t=e.prototype;return t.define=function(e){this.schema=Object.keys(e).reduce((function(t,r){var i,o=e[r];return n({},t,((i={})[r]=o,i))}),this.schema||{})},t.getId=function(e,t,r){return this._getId(e,t,r)},t.merge=function(e,t){return this._mergeStrategy(e,t)},t.normalize=function(e,t,r,n,i,o){var u=this,c=this.getId(e,t,r),a=this.key;if(a in o||(o[a]={}),c in o[a]||(o[a][c]=[]),o[a][c].some((function(t){return t===e})))return c;o[a][c].push(e);var f=this._processStrategy(e,t,r);return Object.keys(this.schema).forEach((function(e){if(f.hasOwnProperty(e)&&"object"==typeof f[e]){var t=u.schema[e];f[e]=n(f[e],f,e,t,i,o)}})),i(this,f,e,t,r),c},t.denormalize=function(e,t){var r=this;if(i(e))return o(this.schema,e,t);var n=!0;return Object.keys(this.schema).forEach((function(i){var o=r.schema[i],u=t(e[i],o),c=u[0];u[1]||(n=!1),e.hasOwnProperty(i)&&(e[i]=c)})),[e,n]},c(e,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),e}();function s(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var h=function(){function e(e,t){t&&(this._schemaAttribute="string"==typeof t?function(e){return e[t]}:t),this.define(e)}var t=e.prototype;return t.define=function(e){this.schema=e},t.getSchemaAttribute=function(e,t,r){return!this.isSingleSchema&&this._schemaAttribute(e,t,r)},t.inferSchema=function(e,t,r){if(this.isSingleSchema)return this.schema;var n=this.getSchemaAttribute(e,t,r);return this.schema[n]},t.normalizeValue=function(e,t,r,n,i,o){var u=this.inferSchema(e,t,r);if(!u)return e;var c=n(e,t,r,u,i,o);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,r)}},t.denormalizeValue=function(e,t){var r=i(e)?e.get("schema"):e.schema;return this.isSingleSchema||r?t((i(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[r]):[e,!0]},c(e,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),e}(),l=function(e){function t(t,r){if(!r)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return e.call(this,t,r)||this}s(t,e);var r=t.prototype;return r.normalize=function(e,t,r,n,i,o){return this.normalizeValue(e,t,r,n,i,o)},r.denormalize=function(e,t){return this.denormalizeValue(e,t)},t}(h),y=function(e){function t(){return e.apply(this,arguments)||this}s(t,e);var r=t.prototype;return r.normalize=function(e,t,r,i,o,u){var c=this;return Object.keys(e).reduce((function(t,r,a){var f,s=e[r];return null!=s?n({},t,((f={})[r]=c.normalizeValue(s,e,r,i,o,u),f)):t}),{})},r.denormalize=function(e,t){var r=this,i=!0;return[Object.keys(e).reduce((function(o,u){var c,a=e[u],f=r.denormalizeValue(a,t),s=f[0];return f[1]||(i=!1),n({},o,((c={})[u]=s,c))}),{}),i]},t}(h),m=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]},p=function(e){return Array.isArray(e)?e:Object.keys(e).map((function(t){return e[t]}))},v=function(e,t,r,n,i,o,u){return e=m(e),p(t).map((function(t,c){return i(t,r,n,e,o,u)}))},d=function(e,t,r){e=m(e);var n=!0;void 0===t&&e&&(r(void 0,e)[1]||(n=!1));return[t&&t.map?t.map((function(t){var i=r(t,e),o=i[0];return i[1]||(n=!1),o})).filter((function(e){return e})):t,n]},b=function(e){function t(){return e.apply(this,arguments)||this}s(t,e);var r=t.prototype;return r.normalize=function(e,t,r,n,i,o){var u=this;return p(e).map((function(e,c){return u.normalizeValue(e,t,r,n,i,o)})).filter((function(e){return null!=e}))},r.denormalize=function(e,t){var r=this,n=!0;void 0===e&&this.schema&&(t(void 0,this.schema)[1]||(n=!1));return[e&&e.map?e.map((function(e){var i=r.denormalizeValue(e,t),o=i[0];return i[1]||(n=!1),o})).filter((function(e){return e})):e,n]},t}(h),g=function(e,t,r,i,o,u,c){var a=n({},t);return Object.keys(e).forEach((function(r){var n=e[r],i=o(t[r],t,r,n,u,c);null==i?delete a[r]:a[r]=i})),a},O=function(e,t,r){if(i(t))return o(e,t,r);var u=n({},t),c=!0;return Object.keys(e).forEach((function(t){var n=r(u[t],e[t]),i=n[0],o=n[1];null!=u[t]&&(u[t]=i),o||(c=!1)})),[u,c]},j=function e(t,r,n,i,o,u){return"object"==typeof t&&t?"object"!=typeof i||i.normalize&&"function"==typeof i.normalize?i.normalize(t,r,n,e,o,u):(Array.isArray(i)?v:g)(i,t,r,n,e,o,u):t},z={Array:b,Entity:f,Object:function(){function e(e){this.define(e)}var t=e.prototype;return t.define=function(e){this.schema=Object.keys(e).reduce((function(t,r){var i,o=e[r];return n({},t,((i={})[r]=o,i))}),this.schema||{})},t.normalize=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return g.apply(void 0,[this.schema].concat(t))},t.denormalize=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return O.apply(void 0,[this.schema].concat(t))},e}(),Union:l,Values:y},k=function(e){var t={},r=S(e);return function e(o,u){return"object"!=typeof u||u.denormalize&&"function"==typeof u.denormalize?null===o?[o,!0]:u instanceof f?void 0===o?[o,!1]:function(e,t,r,o,u){var c=o(e,t);if("object"!=typeof c||null===c)return[c,!1];u[t.key]||(u[t.key]={});var a=!0;if(!u[t.key][e]){var f=i(c)?c:n({},c);u[t.key][e]=f;var s=t.denormalize(f,r);u[t.key][e]=s[0],a=s[1]}return[u[t.key][e],a]}(o,u,e,r,t):"function"==typeof u.denormalize?u.denormalize(o,e):[o,!0]:(Array.isArray(u)?d:O)(u,o,e)}},S=function(e){var t=i(e);return function(r,n){var i=n.key;return"object"==typeof r?r:t?e.getIn([i,r.toString()]):e[i]&&e[i][r]}};e.denormalize=function(e,t,r){return void 0!==e?k(r)(e,t):[void 0,!1]},e.normalize=function(e,t){if(!e||"object"!=typeof e)throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+(null===e?"null":typeof e)+'".');var r={},n=function(e){return function(t,r,n,i,o){var u=t.key,c=t.getId(n,i,o);u in e||(e[u]={});var a=e[u][c];e[u][c]=a?t.merge(a,r):r}}(r);return{entities:r,result:j(e,e,null,t,n,{})}},e.schema=z,Object.defineProperty(e,"__esModule",{value:!0})})); |
@@ -86,11 +86,11 @@ var rest_hooks_normalizr = (function (exports) { | ||
if (object.has(stringKey)) { | ||
var _unvisit = unvisit(object.get(stringKey), schema[stringKey]), | ||
item = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
var _unvisit = unvisit(object.get(stringKey), schema[stringKey]), | ||
item = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
if (object.has(stringKey)) { | ||
return object.set(stringKey, item); | ||
@@ -222,14 +222,14 @@ } else { | ||
Object.keys(this.schema).forEach(function (key) { | ||
if (entity.hasOwnProperty(key)) { | ||
var schema = _this2.schema[key]; | ||
var schema = _this2.schema[key]; | ||
var _unvisit = unvisit(entity[key], schema), | ||
value = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
var _unvisit = unvisit(entity[key], schema), | ||
value = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
if (entity.hasOwnProperty(key)) { | ||
entity[key] = value; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
} | ||
@@ -429,5 +429,5 @@ }); | ||
var found = true; | ||
return [input && input.map ? input.map(function (entityOrId) { | ||
var _unvisit = unvisit(entityOrId, schema), | ||
value = _unvisit[0], | ||
if (input === undefined && schema) { | ||
var _unvisit = unvisit(undefined, schema), | ||
foundItem = _unvisit[1]; | ||
@@ -438,3 +438,13 @@ | ||
} | ||
} | ||
return [input && input.map ? input.map(function (entityOrId) { | ||
var _unvisit2 = unvisit(entityOrId, schema), | ||
value = _unvisit2[0], | ||
foundItem = _unvisit2[1]; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
return value; | ||
@@ -472,2 +482,12 @@ }).filter(function (entityOrUndefined) { | ||
var found = true; | ||
if (input === undefined && this.schema) { | ||
var _unvisit3 = unvisit(undefined, this.schema), | ||
foundItem = _unvisit3[1]; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
} | ||
return [input && input.map ? input.map(function (entityOrId) { | ||
@@ -516,12 +536,12 @@ var _this2$denormalizeVal = _this2.denormalizeValue(entityOrId, unvisit), | ||
Object.keys(schema).forEach(function (key) { | ||
var _unvisit = unvisit(object[key], schema[key]), | ||
item = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
if (object[key] != null) { | ||
var _unvisit = unvisit(object[key], schema[key]), | ||
item = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
object[key] = item; | ||
} | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
@@ -659,5 +679,6 @@ }); | ||
return method(schema, input, unvisit); | ||
} | ||
} // null is considered intentional, thus always 'found' as true | ||
if (input === undefined || input === null) { | ||
if (input === null) { | ||
return [input, true]; | ||
@@ -667,2 +688,7 @@ } | ||
if (schema instanceof EntitySchema) { | ||
// unvisitEntity just can't handle undefined | ||
if (input === undefined) { | ||
return [input, false]; | ||
} | ||
return unvisitEntity(input, schema, unvisit, getEntity, cache); | ||
@@ -669,0 +695,0 @@ } |
@@ -1,1 +0,1 @@ | ||
var rest_hooks_normalizr=function(t){"use strict";function e(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function r(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function n(t){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?r(i,!0).forEach((function(r){e(t,r,i[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):r(i).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function i(t){return!(!t||"function"!=typeof t.hasOwnProperty||!(t.hasOwnProperty("__ownerID")||t._map&&t._map.hasOwnProperty("__ownerID")))}function o(t,e,r){var n=!0;return[Object.keys(t).reduce((function(e,i){var o=""+i;if(e.has(o)){var u=r(e.get(o),t[o]),c=u[0];return u[1]||(n=!1),e.set(o,c)}return e}),e),n]}function u(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function c(t,e,r){return e&&u(t.prototype,e),r&&u(t,r),t}var a=function(t){return function(e){return i(e)?e.get(t):e[t]}},f=function(){function t(t,e,r){if(void 0===e&&(e={}),void 0===r&&(r={}),!t||"string"!=typeof t)throw new Error("Expected a string key for Entity, but found "+t+".");var i=r,o=i.idAttribute,u=void 0===o?"id":o,c=i.mergeStrategy,f=void 0===c?function(t,e){return n({},t,{},e)}:c,s=i.processStrategy,h=void 0===s?function(t){return n({},t)}:s;this._key=t,this._getId="function"==typeof u?u:a(u),this._idAttribute=u,this._mergeStrategy=f,this._processStrategy=h,this.define(e)}var e=t.prototype;return e.define=function(t){this.schema=Object.keys(t).reduce((function(e,r){var i,o=t[r];return n({},e,((i={})[r]=o,i))}),this.schema||{})},e.getId=function(t,e,r){return this._getId(t,e,r)},e.merge=function(t,e){return this._mergeStrategy(t,e)},e.normalize=function(t,e,r,n,i,o){var u=this,c=this.getId(t,e,r),a=this.key;if(a in o||(o[a]={}),c in o[a]||(o[a][c]=[]),o[a][c].some((function(e){return e===t})))return c;o[a][c].push(t);var f=this._processStrategy(t,e,r);return Object.keys(this.schema).forEach((function(t){if(f.hasOwnProperty(t)&&"object"==typeof f[t]){var e=u.schema[t];f[t]=n(f[t],f,t,e,i,o)}})),i(this,f,t,e,r),c},e.denormalize=function(t,e){var r=this;if(i(t))return o(this.schema,t,e);var n=!0;return Object.keys(this.schema).forEach((function(i){if(t.hasOwnProperty(i)){var o=r.schema[i],u=e(t[i],o),c=u[0],a=u[1];t[i]=c,a||(n=!1)}})),[t,n]},c(t,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),t}();function s(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}var h=function(){function t(t,e){e&&(this._schemaAttribute="string"==typeof e?function(t){return t[e]}:e),this.define(t)}var e=t.prototype;return e.define=function(t){this.schema=t},e.getSchemaAttribute=function(t,e,r){return!this.isSingleSchema&&this._schemaAttribute(t,e,r)},e.inferSchema=function(t,e,r){if(this.isSingleSchema)return this.schema;var n=this.getSchemaAttribute(t,e,r);return this.schema[n]},e.normalizeValue=function(t,e,r,n,i,o){var u=this.inferSchema(t,e,r);if(!u)return t;var c=n(t,e,r,u,i,o);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(t,e,r)}},e.denormalizeValue=function(t,e){var r=i(t)?t.get("schema"):t.schema;return this.isSingleSchema||r?e((i(t)?t.get("id"):t.id)||t,this.isSingleSchema?this.schema:this.schema[r]):[t,!0]},c(t,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),t}(),l=function(t){function e(e,r){if(!r)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return t.call(this,e,r)||this}s(e,t);var r=e.prototype;return r.normalize=function(t,e,r,n,i,o){return this.normalizeValue(t,e,r,n,i,o)},r.denormalize=function(t,e){return this.denormalizeValue(t,e)},e}(h),y=function(t){function e(){return t.apply(this,arguments)||this}s(e,t);var r=e.prototype;return r.normalize=function(t,e,r,i,o,u){var c=this;return Object.keys(t).reduce((function(e,r,a){var f,s=t[r];return null!=s?n({},e,((f={})[r]=c.normalizeValue(s,t,r,i,o,u),f)):e}),{})},r.denormalize=function(t,e){var r=this,i=!0;return[Object.keys(t).reduce((function(o,u){var c,a=t[u],f=r.denormalizeValue(a,e),s=f[0];return f[1]||(i=!1),n({},o,((c={})[u]=s,c))}),{}),i]},e}(h),m=function(t){if(Array.isArray(t)&&t.length>1)throw new Error("Expected schema definition to be a single schema, but found "+t.length+".");return t[0]},p=function(t){return Array.isArray(t)?t:Object.keys(t).map((function(e){return t[e]}))},v=function(t,e,r,n,i,o,u){return t=m(t),p(e).map((function(e,c){return i(e,r,n,t,o,u)}))},d=function(t,e,r){t=m(t);var n=!0;return[e&&e.map?e.map((function(e){var i=r(e,t),o=i[0];return i[1]||(n=!1),o})).filter((function(t){return t})):e,n]},b=function(t){function e(){return t.apply(this,arguments)||this}s(e,t);var r=e.prototype;return r.normalize=function(t,e,r,n,i,o){var u=this;return p(t).map((function(t,c){return u.normalizeValue(t,e,r,n,i,o)})).filter((function(t){return null!=t}))},r.denormalize=function(t,e){var r=this,n=!0;return[t&&t.map?t.map((function(t){var i=r.denormalizeValue(t,e),o=i[0];return i[1]||(n=!1),o})).filter((function(t){return t})):t,n]},e}(h),g=function(t,e,r,i,o,u,c){var a=n({},e);return Object.keys(t).forEach((function(r){var n=t[r],i=o(e[r],e,r,n,u,c);null==i?delete a[r]:a[r]=i})),a},O=function(t,e,r){if(i(e))return o(t,e,r);var u=n({},e),c=!0;return Object.keys(t).forEach((function(e){if(null!=u[e]){var n=r(u[e],t[e]),i=n[0],o=n[1];u[e]=i,o||(c=!1)}})),[u,c]},j=function t(e,r,n,i,o,u){return"object"==typeof e&&e?"object"!=typeof i||i.normalize&&"function"==typeof i.normalize?i.normalize(e,r,n,t,o,u):(Array.isArray(i)?v:g)(i,e,r,n,t,o,u):e},z={Array:b,Entity:f,Object:function(){function t(t){this.define(t)}var e=t.prototype;return e.define=function(t){this.schema=Object.keys(t).reduce((function(e,r){var i,o=t[r];return n({},e,((i={})[r]=o,i))}),this.schema||{})},e.normalize=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return g.apply(void 0,[this.schema].concat(e))},e.denormalize=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return O.apply(void 0,[this.schema].concat(e))},t}(),Union:l,Values:y},k=function(t){var e={},r=S(t);return function t(o,u){return"object"!=typeof u||u.denormalize&&"function"==typeof u.denormalize?null==o?[o,!0]:u instanceof f?function(t,e,r,o,u){var c=o(t,e);if("object"!=typeof c||null===c)return[c,!1];u[e.key]||(u[e.key]={});var a=!0;if(!u[e.key][t]){var f=i(c)?c:n({},c);u[e.key][t]=f;var s=e.denormalize(f,r);u[e.key][t]=s[0],a=s[1]}return[u[e.key][t],a]}(o,u,t,r,e):"function"==typeof u.denormalize?u.denormalize(o,t):[o,!0]:(Array.isArray(u)?d:O)(u,o,t)}},S=function(t){var e=i(t);return function(r,n){var i=n.key;return"object"==typeof r?r:e?t.getIn([i,r.toString()]):t[i]&&t[i][r]}};return t.denormalize=function(t,e,r){return void 0!==t?k(r)(t,e):[void 0,!1]},t.normalize=function(t,e){if(!t||"object"!=typeof t)throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+(null===t?"null":typeof t)+'".');var r={},n=function(t){return function(e,r,n,i,o){var u=e.key,c=e.getId(n,i,o);u in t||(t[u]={});var a=t[u][c];t[u][c]=a?e.merge(a,r):r}}(r);return{entities:r,result:j(t,t,null,e,n,{})}},t.schema=z,t}({}); | ||
var rest_hooks_normalizr=function(t){"use strict";function e(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function r(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function n(t){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?r(i,!0).forEach((function(r){e(t,r,i[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):r(i).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function i(t){return!(!t||"function"!=typeof t.hasOwnProperty||!(t.hasOwnProperty("__ownerID")||t._map&&t._map.hasOwnProperty("__ownerID")))}function o(t,e,r){var n=!0;return[Object.keys(t).reduce((function(e,i){var o=""+i,u=r(e.get(o),t[o]),c=u[0];return u[1]||(n=!1),e.has(o)?e.set(o,c):e}),e),n]}function u(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function c(t,e,r){return e&&u(t.prototype,e),r&&u(t,r),t}var a=function(t){return function(e){return i(e)?e.get(t):e[t]}},f=function(){function t(t,e,r){if(void 0===e&&(e={}),void 0===r&&(r={}),!t||"string"!=typeof t)throw new Error("Expected a string key for Entity, but found "+t+".");var i=r,o=i.idAttribute,u=void 0===o?"id":o,c=i.mergeStrategy,f=void 0===c?function(t,e){return n({},t,{},e)}:c,s=i.processStrategy,h=void 0===s?function(t){return n({},t)}:s;this._key=t,this._getId="function"==typeof u?u:a(u),this._idAttribute=u,this._mergeStrategy=f,this._processStrategy=h,this.define(e)}var e=t.prototype;return e.define=function(t){this.schema=Object.keys(t).reduce((function(e,r){var i,o=t[r];return n({},e,((i={})[r]=o,i))}),this.schema||{})},e.getId=function(t,e,r){return this._getId(t,e,r)},e.merge=function(t,e){return this._mergeStrategy(t,e)},e.normalize=function(t,e,r,n,i,o){var u=this,c=this.getId(t,e,r),a=this.key;if(a in o||(o[a]={}),c in o[a]||(o[a][c]=[]),o[a][c].some((function(e){return e===t})))return c;o[a][c].push(t);var f=this._processStrategy(t,e,r);return Object.keys(this.schema).forEach((function(t){if(f.hasOwnProperty(t)&&"object"==typeof f[t]){var e=u.schema[t];f[t]=n(f[t],f,t,e,i,o)}})),i(this,f,t,e,r),c},e.denormalize=function(t,e){var r=this;if(i(t))return o(this.schema,t,e);var n=!0;return Object.keys(this.schema).forEach((function(i){var o=r.schema[i],u=e(t[i],o),c=u[0];u[1]||(n=!1),t.hasOwnProperty(i)&&(t[i]=c)})),[t,n]},c(t,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),t}();function s(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}var h=function(){function t(t,e){e&&(this._schemaAttribute="string"==typeof e?function(t){return t[e]}:e),this.define(t)}var e=t.prototype;return e.define=function(t){this.schema=t},e.getSchemaAttribute=function(t,e,r){return!this.isSingleSchema&&this._schemaAttribute(t,e,r)},e.inferSchema=function(t,e,r){if(this.isSingleSchema)return this.schema;var n=this.getSchemaAttribute(t,e,r);return this.schema[n]},e.normalizeValue=function(t,e,r,n,i,o){var u=this.inferSchema(t,e,r);if(!u)return t;var c=n(t,e,r,u,i,o);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(t,e,r)}},e.denormalizeValue=function(t,e){var r=i(t)?t.get("schema"):t.schema;return this.isSingleSchema||r?e((i(t)?t.get("id"):t.id)||t,this.isSingleSchema?this.schema:this.schema[r]):[t,!0]},c(t,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),t}(),l=function(t){function e(e,r){if(!r)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return t.call(this,e,r)||this}s(e,t);var r=e.prototype;return r.normalize=function(t,e,r,n,i,o){return this.normalizeValue(t,e,r,n,i,o)},r.denormalize=function(t,e){return this.denormalizeValue(t,e)},e}(h),y=function(t){function e(){return t.apply(this,arguments)||this}s(e,t);var r=e.prototype;return r.normalize=function(t,e,r,i,o,u){var c=this;return Object.keys(t).reduce((function(e,r,a){var f,s=t[r];return null!=s?n({},e,((f={})[r]=c.normalizeValue(s,t,r,i,o,u),f)):e}),{})},r.denormalize=function(t,e){var r=this,i=!0;return[Object.keys(t).reduce((function(o,u){var c,a=t[u],f=r.denormalizeValue(a,e),s=f[0];return f[1]||(i=!1),n({},o,((c={})[u]=s,c))}),{}),i]},e}(h),m=function(t){if(Array.isArray(t)&&t.length>1)throw new Error("Expected schema definition to be a single schema, but found "+t.length+".");return t[0]},p=function(t){return Array.isArray(t)?t:Object.keys(t).map((function(e){return t[e]}))},v=function(t,e,r,n,i,o,u){return t=m(t),p(e).map((function(e,c){return i(e,r,n,t,o,u)}))},d=function(t,e,r){t=m(t);var n=!0;void 0===e&&t&&(r(void 0,t)[1]||(n=!1));return[e&&e.map?e.map((function(e){var i=r(e,t),o=i[0];return i[1]||(n=!1),o})).filter((function(t){return t})):e,n]},b=function(t){function e(){return t.apply(this,arguments)||this}s(e,t);var r=e.prototype;return r.normalize=function(t,e,r,n,i,o){var u=this;return p(t).map((function(t,c){return u.normalizeValue(t,e,r,n,i,o)})).filter((function(t){return null!=t}))},r.denormalize=function(t,e){var r=this,n=!0;void 0===t&&this.schema&&(e(void 0,this.schema)[1]||(n=!1));return[t&&t.map?t.map((function(t){var i=r.denormalizeValue(t,e),o=i[0];return i[1]||(n=!1),o})).filter((function(t){return t})):t,n]},e}(h),g=function(t,e,r,i,o,u,c){var a=n({},e);return Object.keys(t).forEach((function(r){var n=t[r],i=o(e[r],e,r,n,u,c);null==i?delete a[r]:a[r]=i})),a},O=function(t,e,r){if(i(e))return o(t,e,r);var u=n({},e),c=!0;return Object.keys(t).forEach((function(e){var n=r(u[e],t[e]),i=n[0],o=n[1];null!=u[e]&&(u[e]=i),o||(c=!1)})),[u,c]},j=function t(e,r,n,i,o,u){return"object"==typeof e&&e?"object"!=typeof i||i.normalize&&"function"==typeof i.normalize?i.normalize(e,r,n,t,o,u):(Array.isArray(i)?v:g)(i,e,r,n,t,o,u):e},z={Array:b,Entity:f,Object:function(){function t(t){this.define(t)}var e=t.prototype;return e.define=function(t){this.schema=Object.keys(t).reduce((function(e,r){var i,o=t[r];return n({},e,((i={})[r]=o,i))}),this.schema||{})},e.normalize=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return g.apply(void 0,[this.schema].concat(e))},e.denormalize=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return O.apply(void 0,[this.schema].concat(e))},t}(),Union:l,Values:y},k=function(t){var e={},r=S(t);return function t(o,u){return"object"!=typeof u||u.denormalize&&"function"==typeof u.denormalize?null===o?[o,!0]:u instanceof f?void 0===o?[o,!1]:function(t,e,r,o,u){var c=o(t,e);if("object"!=typeof c||null===c)return[c,!1];u[e.key]||(u[e.key]={});var a=!0;if(!u[e.key][t]){var f=i(c)?c:n({},c);u[e.key][t]=f;var s=e.denormalize(f,r);u[e.key][t]=s[0],a=s[1]}return[u[e.key][t],a]}(o,u,t,r,e):"function"==typeof u.denormalize?u.denormalize(o,t):[o,!0]:(Array.isArray(u)?d:O)(u,o,t)}},S=function(t){var e=i(t);return function(r,n){var i=n.key;return"object"==typeof r?r:e?t.getIn([i,r.toString()]):t[i]&&t[i][r]}};return t.denormalize=function(t,e,r){return void 0!==t?k(r)(t,e):[void 0,!1]},t.normalize=function(t,e){if(!t||"object"!=typeof t)throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+(null===t?"null":typeof t)+'".');var r={},n=function(t){return function(e,r,n,i,o){var u=e.key,c=e.getId(n,i,o);u in t||(t[u]={});var a=t[u][c];t[u][c]=a?e.merge(a,r):r}}(r);return{entities:r,result:j(t,t,null,e,n,{})}},t.schema=z,t}({}); |
@@ -38,11 +38,11 @@ import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2'; | ||
if (object.has(stringKey)) { | ||
var _unvisit = unvisit(object.get(stringKey), schema[stringKey]), | ||
item = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
var _unvisit = unvisit(object.get(stringKey), schema[stringKey]), | ||
item = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
if (object.has(stringKey)) { | ||
return object.set(stringKey, item); | ||
@@ -158,14 +158,14 @@ } else { | ||
Object.keys(this.schema).forEach(function (key) { | ||
if (entity.hasOwnProperty(key)) { | ||
var schema = _this2.schema[key]; | ||
var schema = _this2.schema[key]; | ||
var _unvisit = unvisit(entity[key], schema), | ||
value = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
var _unvisit = unvisit(entity[key], schema), | ||
value = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
if (entity.hasOwnProperty(key)) { | ||
entity[key] = value; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
} | ||
@@ -359,5 +359,5 @@ }); | ||
var found = true; | ||
return [input && input.map ? input.map(function (entityOrId) { | ||
var _unvisit = unvisit(entityOrId, schema), | ||
value = _unvisit[0], | ||
if (input === undefined && schema) { | ||
var _unvisit = unvisit(undefined, schema), | ||
foundItem = _unvisit[1]; | ||
@@ -368,3 +368,13 @@ | ||
} | ||
} | ||
return [input && input.map ? input.map(function (entityOrId) { | ||
var _unvisit2 = unvisit(entityOrId, schema), | ||
value = _unvisit2[0], | ||
foundItem = _unvisit2[1]; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
return value; | ||
@@ -402,2 +412,12 @@ }).filter(function (entityOrUndefined) { | ||
var found = true; | ||
if (input === undefined && this.schema) { | ||
var _unvisit3 = unvisit(undefined, this.schema), | ||
foundItem = _unvisit3[1]; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
} | ||
return [input && input.map ? input.map(function (entityOrId) { | ||
@@ -446,12 +466,12 @@ var _this2$denormalizeVal = _this2.denormalizeValue(entityOrId, unvisit), | ||
Object.keys(schema).forEach(function (key) { | ||
var _unvisit = unvisit(object[key], schema[key]), | ||
item = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
if (object[key] != null) { | ||
var _unvisit = unvisit(object[key], schema[key]), | ||
item = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
object[key] = item; | ||
} | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
@@ -589,5 +609,6 @@ }); | ||
return method(schema, input, unvisit); | ||
} | ||
} // null is considered intentional, thus always 'found' as true | ||
if (input === undefined || input === null) { | ||
if (input === null) { | ||
return [input, true]; | ||
@@ -597,2 +618,7 @@ } | ||
if (schema instanceof EntitySchema) { | ||
// unvisitEntity just can't handle undefined | ||
if (input === undefined) { | ||
return [input, false]; | ||
} | ||
return unvisitEntity(input, schema, unvisit, getEntity, cache); | ||
@@ -599,0 +625,0 @@ } |
@@ -1,1 +0,1 @@ | ||
import e from"@babel/runtime/helpers/esm/objectSpread2";import t from"@babel/runtime/helpers/esm/createClass";import r from"@babel/runtime/helpers/esm/inheritsLoose";function n(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(e.hasOwnProperty("__ownerID")||e._map&&e._map.hasOwnProperty("__ownerID")))}function i(e,t,r){var n=!0;return[Object.keys(e).reduce((function(t,i){var o=""+i;if(t.has(o)){var u=r(t.get(o),e[o]),a=u[0];return u[1]||(n=!1),t.set(o,a)}return t}),t),n]}var o=function(e){return function(t){return n(t)?t.get(e):t[e]}},u=function(){function r(t,r,n){if(void 0===r&&(r={}),void 0===n&&(n={}),!t||"string"!=typeof t)throw new Error("Expected a string key for Entity, but found "+t+".");var i=n,u=i.idAttribute,a=void 0===u?"id":u,c=i.mergeStrategy,f=void 0===c?function(t,r){return e({},t,{},r)}:c,s=i.processStrategy,h=void 0===s?function(t){return e({},t)}:s;this._key=t,this._getId="function"==typeof a?a:o(a),this._idAttribute=a,this._mergeStrategy=f,this._processStrategy=h,this.define(r)}var u=r.prototype;return u.define=function(t){this.schema=Object.keys(t).reduce((function(r,n){var i,o=t[n];return e({},r,((i={})[n]=o,i))}),this.schema||{})},u.getId=function(e,t,r){return this._getId(e,t,r)},u.merge=function(e,t){return this._mergeStrategy(e,t)},u.normalize=function(e,t,r,n,i,o){var u=this,a=this.getId(e,t,r),c=this.key;if(c in o||(o[c]={}),a in o[c]||(o[c][a]=[]),o[c][a].some((function(t){return t===e})))return a;o[c][a].push(e);var f=this._processStrategy(e,t,r);return Object.keys(this.schema).forEach((function(e){if(f.hasOwnProperty(e)&&"object"==typeof f[e]){var t=u.schema[e];f[e]=n(f[e],f,e,t,i,o)}})),i(this,f,e,t,r),a},u.denormalize=function(e,t){var r=this;if(n(e))return i(this.schema,e,t);var o=!0;return Object.keys(this.schema).forEach((function(n){if(e.hasOwnProperty(n)){var i=r.schema[n],u=t(e[n],i),a=u[0],c=u[1];e[n]=a,c||(o=!1)}})),[e,o]},t(r,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),r}(),a=function(){function e(e,t){t&&(this._schemaAttribute="string"==typeof t?function(e){return e[t]}:t),this.define(e)}var r=e.prototype;return r.define=function(e){this.schema=e},r.getSchemaAttribute=function(e,t,r){return!this.isSingleSchema&&this._schemaAttribute(e,t,r)},r.inferSchema=function(e,t,r){if(this.isSingleSchema)return this.schema;var n=this.getSchemaAttribute(e,t,r);return this.schema[n]},r.normalizeValue=function(e,t,r,n,i,o){var u=this.inferSchema(e,t,r);if(!u)return e;var a=n(e,t,r,u,i,o);return this.isSingleSchema||null==a?a:{id:a,schema:this.getSchemaAttribute(e,t,r)}},r.denormalizeValue=function(e,t){var r=n(e)?e.get("schema"):e.schema;return this.isSingleSchema||r?t((n(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[r]):[e,!0]},t(e,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),e}(),c=function(e){function t(t,r){if(!r)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return e.call(this,t,r)||this}r(t,e);var n=t.prototype;return n.normalize=function(e,t,r,n,i,o){return this.normalizeValue(e,t,r,n,i,o)},n.denormalize=function(e,t){return this.denormalizeValue(e,t)},t}(a),f=function(t){function n(){return t.apply(this,arguments)||this}r(n,t);var i=n.prototype;return i.normalize=function(t,r,n,i,o,u){var a=this;return Object.keys(t).reduce((function(r,n,c){var f,s=t[n];return null!=s?e({},r,((f={})[n]=a.normalizeValue(s,t,n,i,o,u),f)):r}),{})},i.denormalize=function(t,r){var n=this,i=!0;return[Object.keys(t).reduce((function(o,u){var a,c=t[u],f=n.denormalizeValue(c,r),s=f[0];return f[1]||(i=!1),e({},o,((a={})[u]=s,a))}),{}),i]},n}(a),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]},h=function(e){return Array.isArray(e)?e:Object.keys(e).map((function(t){return e[t]}))},m=function(e,t,r,n,i,o,u){return e=s(e),h(t).map((function(t,a){return i(t,r,n,e,o,u)}))},l=function(e,t,r){e=s(e);var n=!0;return[t&&t.map?t.map((function(t){var i=r(t,e),o=i[0];return i[1]||(n=!1),o})).filter((function(e){return e})):t,n]},y=function(e){function t(){return e.apply(this,arguments)||this}r(t,e);var n=t.prototype;return n.normalize=function(e,t,r,n,i,o){var u=this;return h(e).map((function(e,a){return u.normalizeValue(e,t,r,n,i,o)})).filter((function(e){return null!=e}))},n.denormalize=function(e,t){var r=this,n=!0;return[e&&e.map?e.map((function(e){var i=r.denormalizeValue(e,t),o=i[0];return i[1]||(n=!1),o})).filter((function(e){return e})):e,n]},t}(a),p=function(t,r,n,i,o,u,a){var c=e({},r);return Object.keys(t).forEach((function(e){var n=t[e],i=o(r[e],r,e,n,u,a);null==i?delete c[e]:c[e]=i})),c},d=function(t,r,o){if(n(r))return i(t,r,o);var u=e({},r),a=!0;return Object.keys(t).forEach((function(e){if(null!=u[e]){var r=o(u[e],t[e]),n=r[0],i=r[1];u[e]=n,i||(a=!1)}})),[u,a]},v=function e(t,r,n,i,o,u){return"object"==typeof t&&t?"object"!=typeof i||i.normalize&&"function"==typeof i.normalize?i.normalize(t,r,n,e,o,u):(Array.isArray(i)?m:p)(i,t,r,n,e,o,u):t},g={Array:y,Entity:u,Object:function(){function t(e){this.define(e)}var r=t.prototype;return r.define=function(t){this.schema=Object.keys(t).reduce((function(r,n){var i,o=t[n];return e({},r,((i={})[n]=o,i))}),this.schema||{})},r.normalize=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return p.apply(void 0,[this.schema].concat(t))},r.denormalize=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return d.apply(void 0,[this.schema].concat(t))},t}(),Union:c,Values:f},b=function(e,t){if(!e||"object"!=typeof e)throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+(null===e?"null":typeof e)+'".');var r={},n=function(e){return function(t,r,n,i,o){var u=t.key,a=t.getId(n,i,o);u in e||(e[u]={});var c=e[u][a];e[u][a]=c?t.merge(c,r):r}}(r);return{entities:r,result:v(e,e,null,t,n,{})}},z=function(t){var r={},i=k(t);return function t(o,a){return"object"!=typeof a||a.denormalize&&"function"==typeof a.denormalize?null==o?[o,!0]:a instanceof u?function(t,r,i,o,u){var a=o(t,r);if("object"!=typeof a||null===a)return[a,!1];u[r.key]||(u[r.key]={});var c=!0;if(!u[r.key][t]){var f=n(a)?a:e({},a);u[r.key][t]=f;var s=r.denormalize(f,i);u[r.key][t]=s[0],c=s[1]}return[u[r.key][t],c]}(o,a,t,i,r):"function"==typeof a.denormalize?a.denormalize(o,t):[o,!0]:(Array.isArray(a)?l:d)(a,o,t)}},k=function(e){var t=n(e);return function(r,n){var i=n.key;return"object"==typeof r?r:t?e.getIn([i,r.toString()]):e[i]&&e[i][r]}},S=function(e,t,r){return void 0!==e?z(r)(e,t):[void 0,!1]};export{S as denormalize,b as normalize,g as schema}; | ||
import e from"@babel/runtime/helpers/esm/objectSpread2";import t from"@babel/runtime/helpers/esm/createClass";import n from"@babel/runtime/helpers/esm/inheritsLoose";function r(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(e.hasOwnProperty("__ownerID")||e._map&&e._map.hasOwnProperty("__ownerID")))}function i(e,t,n){var r=!0;return[Object.keys(e).reduce((function(t,i){var o=""+i,u=n(t.get(o),e[o]),a=u[0];return u[1]||(r=!1),t.has(o)?t.set(o,a):t}),t),r]}var o=function(e){return function(t){return r(t)?t.get(e):t[e]}},u=function(){function n(t,n,r){if(void 0===n&&(n={}),void 0===r&&(r={}),!t||"string"!=typeof t)throw new Error("Expected a string key for Entity, but found "+t+".");var i=r,u=i.idAttribute,a=void 0===u?"id":u,c=i.mergeStrategy,s=void 0===c?function(t,n){return e({},t,{},n)}:c,f=i.processStrategy,h=void 0===f?function(t){return e({},t)}:f;this._key=t,this._getId="function"==typeof a?a:o(a),this._idAttribute=a,this._mergeStrategy=s,this._processStrategy=h,this.define(n)}var u=n.prototype;return u.define=function(t){this.schema=Object.keys(t).reduce((function(n,r){var i,o=t[r];return e({},n,((i={})[r]=o,i))}),this.schema||{})},u.getId=function(e,t,n){return this._getId(e,t,n)},u.merge=function(e,t){return this._mergeStrategy(e,t)},u.normalize=function(e,t,n,r,i,o){var u=this,a=this.getId(e,t,n),c=this.key;if(c in o||(o[c]={}),a in o[c]||(o[c][a]=[]),o[c][a].some((function(t){return t===e})))return a;o[c][a].push(e);var s=this._processStrategy(e,t,n);return Object.keys(this.schema).forEach((function(e){if(s.hasOwnProperty(e)&&"object"==typeof s[e]){var t=u.schema[e];s[e]=r(s[e],s,e,t,i,o)}})),i(this,s,e,t,n),a},u.denormalize=function(e,t){var n=this;if(r(e))return i(this.schema,e,t);var o=!0;return Object.keys(this.schema).forEach((function(r){var i=n.schema[r],u=t(e[r],i),a=u[0];u[1]||(o=!1),e.hasOwnProperty(r)&&(e[r]=a)})),[e,o]},t(n,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),n}(),a=function(){function e(e,t){t&&(this._schemaAttribute="string"==typeof t?function(e){return e[t]}:t),this.define(e)}var n=e.prototype;return n.define=function(e){this.schema=e},n.getSchemaAttribute=function(e,t,n){return!this.isSingleSchema&&this._schemaAttribute(e,t,n)},n.inferSchema=function(e,t,n){if(this.isSingleSchema)return this.schema;var r=this.getSchemaAttribute(e,t,n);return this.schema[r]},n.normalizeValue=function(e,t,n,r,i,o){var u=this.inferSchema(e,t,n);if(!u)return e;var a=r(e,t,n,u,i,o);return this.isSingleSchema||null==a?a:{id:a,schema:this.getSchemaAttribute(e,t,n)}},n.denormalizeValue=function(e,t){var n=r(e)?e.get("schema"):e.schema;return this.isSingleSchema||n?t((r(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[n]):[e,!0]},t(e,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),e}(),c=function(e){function t(t,n){if(!n)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return e.call(this,t,n)||this}n(t,e);var r=t.prototype;return r.normalize=function(e,t,n,r,i,o){return this.normalizeValue(e,t,n,r,i,o)},r.denormalize=function(e,t){return this.denormalizeValue(e,t)},t}(a),s=function(t){function r(){return t.apply(this,arguments)||this}n(r,t);var i=r.prototype;return i.normalize=function(t,n,r,i,o,u){var a=this;return Object.keys(t).reduce((function(n,r,c){var s,f=t[r];return null!=f?e({},n,((s={})[r]=a.normalizeValue(f,t,r,i,o,u),s)):n}),{})},i.denormalize=function(t,n){var r=this,i=!0;return[Object.keys(t).reduce((function(o,u){var a,c=t[u],s=r.denormalizeValue(c,n),f=s[0];return s[1]||(i=!1),e({},o,((a={})[u]=f,a))}),{}),i]},r}(a),f=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]},h=function(e){return Array.isArray(e)?e:Object.keys(e).map((function(t){return e[t]}))},m=function(e,t,n,r,i,o,u){return e=f(e),h(t).map((function(t,a){return i(t,n,r,e,o,u)}))},l=function(e,t,n){e=f(e);var r=!0;void 0===t&&e&&(n(void 0,e)[1]||(r=!1));return[t&&t.map?t.map((function(t){var i=n(t,e),o=i[0];return i[1]||(r=!1),o})).filter((function(e){return e})):t,r]},y=function(e){function t(){return e.apply(this,arguments)||this}n(t,e);var r=t.prototype;return r.normalize=function(e,t,n,r,i,o){var u=this;return h(e).map((function(e,a){return u.normalizeValue(e,t,n,r,i,o)})).filter((function(e){return null!=e}))},r.denormalize=function(e,t){var n=this,r=!0;void 0===e&&this.schema&&(t(void 0,this.schema)[1]||(r=!1));return[e&&e.map?e.map((function(e){var i=n.denormalizeValue(e,t),o=i[0];return i[1]||(r=!1),o})).filter((function(e){return e})):e,r]},t}(a),p=function(t,n,r,i,o,u,a){var c=e({},n);return Object.keys(t).forEach((function(e){var r=t[e],i=o(n[e],n,e,r,u,a);null==i?delete c[e]:c[e]=i})),c},d=function(t,n,o){if(r(n))return i(t,n,o);var u=e({},n),a=!0;return Object.keys(t).forEach((function(e){var n=o(u[e],t[e]),r=n[0],i=n[1];null!=u[e]&&(u[e]=r),i||(a=!1)})),[u,a]},v=function e(t,n,r,i,o,u){return"object"==typeof t&&t?"object"!=typeof i||i.normalize&&"function"==typeof i.normalize?i.normalize(t,n,r,e,o,u):(Array.isArray(i)?m:p)(i,t,n,r,e,o,u):t},g={Array:y,Entity:u,Object:function(){function t(e){this.define(e)}var n=t.prototype;return n.define=function(t){this.schema=Object.keys(t).reduce((function(n,r){var i,o=t[r];return e({},n,((i={})[r]=o,i))}),this.schema||{})},n.normalize=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return p.apply(void 0,[this.schema].concat(t))},n.denormalize=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return d.apply(void 0,[this.schema].concat(t))},t}(),Union:c,Values:s},b=function(e,t){if(!e||"object"!=typeof e)throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+(null===e?"null":typeof e)+'".');var n={},r=function(e){return function(t,n,r,i,o){var u=t.key,a=t.getId(r,i,o);u in e||(e[u]={});var c=e[u][a];e[u][a]=c?t.merge(c,n):n}}(n);return{entities:n,result:v(e,e,null,t,r,{})}},z=function(t){var n={},i=k(t);return function t(o,a){return"object"!=typeof a||a.denormalize&&"function"==typeof a.denormalize?null===o?[o,!0]:a instanceof u?void 0===o?[o,!1]:function(t,n,i,o,u){var a=o(t,n);if("object"!=typeof a||null===a)return[a,!1];u[n.key]||(u[n.key]={});var c=!0;if(!u[n.key][t]){var s=r(a)?a:e({},a);u[n.key][t]=s;var f=n.denormalize(s,i);u[n.key][t]=f[0],c=f[1]}return[u[n.key][t],c]}(o,a,t,i,n):"function"==typeof a.denormalize?a.denormalize(o,t):[o,!0]:(Array.isArray(a)?l:d)(a,o,t)}},k=function(e){var t=r(e);return function(n,r){var i=r.key;return"object"==typeof n?n:t?e.getIn([i,n.toString()]):e[i]&&e[i][n]}},S=function(e,t,n){return void 0!==e?z(n)(e,t):[void 0,!1]};export{S as denormalize,b as normalize,g as schema}; |
@@ -87,11 +87,11 @@ 'use strict'; | ||
if (object.has(stringKey)) { | ||
var _unvisit = unvisit(object.get(stringKey), schema[stringKey]), | ||
item = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
var _unvisit = unvisit(object.get(stringKey), schema[stringKey]), | ||
item = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
if (object.has(stringKey)) { | ||
return object.set(stringKey, item); | ||
@@ -223,14 +223,14 @@ } else { | ||
Object.keys(this.schema).forEach(function (key) { | ||
if (entity.hasOwnProperty(key)) { | ||
var schema = _this2.schema[key]; | ||
var schema = _this2.schema[key]; | ||
var _unvisit = unvisit(entity[key], schema), | ||
value = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
var _unvisit = unvisit(entity[key], schema), | ||
value = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
if (entity.hasOwnProperty(key)) { | ||
entity[key] = value; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
} | ||
@@ -430,5 +430,5 @@ }); | ||
var found = true; | ||
return [input && input.map ? input.map(function (entityOrId) { | ||
var _unvisit = unvisit(entityOrId, schema), | ||
value = _unvisit[0], | ||
if (input === undefined && schema) { | ||
var _unvisit = unvisit(undefined, schema), | ||
foundItem = _unvisit[1]; | ||
@@ -439,3 +439,13 @@ | ||
} | ||
} | ||
return [input && input.map ? input.map(function (entityOrId) { | ||
var _unvisit2 = unvisit(entityOrId, schema), | ||
value = _unvisit2[0], | ||
foundItem = _unvisit2[1]; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
return value; | ||
@@ -473,2 +483,12 @@ }).filter(function (entityOrUndefined) { | ||
var found = true; | ||
if (input === undefined && this.schema) { | ||
var _unvisit3 = unvisit(undefined, this.schema), | ||
foundItem = _unvisit3[1]; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
} | ||
return [input && input.map ? input.map(function (entityOrId) { | ||
@@ -517,12 +537,12 @@ var _this2$denormalizeVal = _this2.denormalizeValue(entityOrId, unvisit), | ||
Object.keys(schema).forEach(function (key) { | ||
var _unvisit = unvisit(object[key], schema[key]), | ||
item = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
if (object[key] != null) { | ||
var _unvisit = unvisit(object[key], schema[key]), | ||
item = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
object[key] = item; | ||
} | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
@@ -660,5 +680,6 @@ }); | ||
return method(schema, input, unvisit); | ||
} | ||
} // null is considered intentional, thus always 'found' as true | ||
if (input === undefined || input === null) { | ||
if (input === null) { | ||
return [input, true]; | ||
@@ -668,2 +689,7 @@ } | ||
if (schema instanceof EntitySchema) { | ||
// unvisitEntity just can't handle undefined | ||
if (input === undefined) { | ||
return [input, false]; | ||
} | ||
return unvisitEntity(input, schema, unvisit, getEntity, cache); | ||
@@ -670,0 +696,0 @@ } |
@@ -1,1 +0,1 @@ | ||
"use strict";function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function _objectSpread2(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(r,!0).forEach((function(t){_defineProperty(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(r).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function isImmutable(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(e.hasOwnProperty("__ownerID")||e._map&&e._map.hasOwnProperty("__ownerID")))}function denormalizeImmutable(e,t,r){var n=!0;return[Object.keys(e).reduce((function(t,i){var o=""+i;if(t.has(o)){var a=r(t.get(o),e[o]),u=a[0];return a[1]||(n=!1),t.set(o,u)}return t}),t),n]}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),e}Object.defineProperty(exports,"__esModule",{value:!0});var getDefaultGetId=function(e){return function(t){return isImmutable(t)?t.get(e):t[e]}},EntitySchema=function(){function e(e,t,r){if(void 0===t&&(t={}),void 0===r&&(r={}),!e||"string"!=typeof e)throw new Error("Expected a string key for Entity, but found "+e+".");var n=r,i=n.idAttribute,o=void 0===i?"id":i,a=n.mergeStrategy,u=void 0===a?function(e,t){return _objectSpread2({},e,{},t)}:a,c=n.processStrategy,s=void 0===c?function(e){return _objectSpread2({},e)}:c;this._key=e,this._getId="function"==typeof o?o:getDefaultGetId(o),this._idAttribute=o,this._mergeStrategy=u,this._processStrategy=s,this.define(t)}var t=e.prototype;return t.define=function(e){this.schema=Object.keys(e).reduce((function(t,r){var n,i=e[r];return _objectSpread2({},t,((n={})[r]=i,n))}),this.schema||{})},t.getId=function(e,t,r){return this._getId(e,t,r)},t.merge=function(e,t){return this._mergeStrategy(e,t)},t.normalize=function(e,t,r,n,i,o){var a=this,u=this.getId(e,t,r),c=this.key;if(c in o||(o[c]={}),u in o[c]||(o[c][u]=[]),o[c][u].some((function(t){return t===e})))return u;o[c][u].push(e);var s=this._processStrategy(e,t,r);return Object.keys(this.schema).forEach((function(e){if(s.hasOwnProperty(e)&&"object"==typeof s[e]){var t=a.schema[e];s[e]=n(s[e],s,e,t,i,o)}})),i(this,s,e,t,r),u},t.denormalize=function(e,t){var r=this;if(isImmutable(e))return denormalizeImmutable(this.schema,e,t);var n=!0;return Object.keys(this.schema).forEach((function(i){if(e.hasOwnProperty(i)){var o=r.schema[i],a=t(e[i],o),u=a[0],c=a[1];e[i]=u,c||(n=!1)}})),[e,n]},_createClass(e,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),e}();function _inheritsLoose(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var PolymorphicSchema=function(){function e(e,t){t&&(this._schemaAttribute="string"==typeof t?function(e){return e[t]}:t),this.define(e)}var t=e.prototype;return t.define=function(e){this.schema=e},t.getSchemaAttribute=function(e,t,r){return!this.isSingleSchema&&this._schemaAttribute(e,t,r)},t.inferSchema=function(e,t,r){if(this.isSingleSchema)return this.schema;var n=this.getSchemaAttribute(e,t,r);return this.schema[n]},t.normalizeValue=function(e,t,r,n,i,o){var a=this.inferSchema(e,t,r);if(!a)return e;var u=n(e,t,r,a,i,o);return this.isSingleSchema||null==u?u:{id:u,schema:this.getSchemaAttribute(e,t,r)}},t.denormalizeValue=function(e,t){var r=isImmutable(e)?e.get("schema"):e.schema;return this.isSingleSchema||r?t((isImmutable(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[r]):[e,!0]},_createClass(e,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),e}(),UnionSchema=function(e){function t(t,r){if(!r)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return e.call(this,t,r)||this}_inheritsLoose(t,e);var r=t.prototype;return r.normalize=function(e,t,r,n,i,o){return this.normalizeValue(e,t,r,n,i,o)},r.denormalize=function(e,t){return this.denormalizeValue(e,t)},t}(PolymorphicSchema),ValuesSchema=function(e){function t(){return e.apply(this,arguments)||this}_inheritsLoose(t,e);var r=t.prototype;return r.normalize=function(e,t,r,n,i,o){var a=this;return Object.keys(e).reduce((function(t,r,u){var c,s=e[r];return null!=s?_objectSpread2({},t,((c={})[r]=a.normalizeValue(s,e,r,n,i,o),c)):t}),{})},r.denormalize=function(e,t){var r=this,n=!0;return[Object.keys(e).reduce((function(i,o){var a,u=e[o],c=r.denormalizeValue(u,t),s=c[0];return c[1]||(n=!1),_objectSpread2({},i,((a={})[o]=s,a))}),{}),n]},t}(PolymorphicSchema),validateSchema=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]},getValues=function(e){return Array.isArray(e)?e:Object.keys(e).map((function(t){return e[t]}))},normalize=function(e,t,r,n,i,o,a){return e=validateSchema(e),getValues(t).map((function(t,u){return i(t,r,n,e,o,a)}))},denormalize=function(e,t,r){e=validateSchema(e);var n=!0;return[t&&t.map?t.map((function(t){var i=r(t,e),o=i[0];return i[1]||(n=!1),o})).filter((function(e){return e})):t,n]},ArraySchema=function(e){function t(){return e.apply(this,arguments)||this}_inheritsLoose(t,e);var r=t.prototype;return r.normalize=function(e,t,r,n,i,o){var a=this;return getValues(e).map((function(e,u){return a.normalizeValue(e,t,r,n,i,o)})).filter((function(e){return null!=e}))},r.denormalize=function(e,t){var r=this,n=!0;return[e&&e.map?e.map((function(e){var i=r.denormalizeValue(e,t),o=i[0];return i[1]||(n=!1),o})).filter((function(e){return e})):e,n]},t}(PolymorphicSchema),_normalize=function(e,t,r,n,i,o,a){var u=_objectSpread2({},t);return Object.keys(e).forEach((function(r){var n=e[r],c=i(t[r],t,r,n,o,a);null==c?delete u[r]:u[r]=c})),u},_denormalize=function(e,t,r){if(isImmutable(t))return denormalizeImmutable(e,t,r);var n=_objectSpread2({},t),i=!0;return Object.keys(e).forEach((function(t){if(null!=n[t]){var o=r(n[t],e[t]),a=o[0],u=o[1];n[t]=a,u||(i=!1)}})),[n,i]},ObjectSchema=function(){function e(e){this.define(e)}var t=e.prototype;return t.define=function(e){this.schema=Object.keys(e).reduce((function(t,r){var n,i=e[r];return _objectSpread2({},t,((n={})[r]=i,n))}),this.schema||{})},t.normalize=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return _normalize.apply(void 0,[this.schema].concat(t))},t.denormalize=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return _denormalize.apply(void 0,[this.schema].concat(t))},e}(),visit=function e(t,r,n,i,o,a){return"object"==typeof t&&t?"object"!=typeof i||i.normalize&&"function"==typeof i.normalize?i.normalize(t,r,n,e,o,a):(Array.isArray(i)?normalize:_normalize)(i,t,r,n,e,o,a):t},addEntities=function(e){return function(t,r,n,i,o){var a=t.key,u=t.getId(n,i,o);a in e||(e[a]={});var c=e[a][u];e[a][u]=c?t.merge(c,r):r}},schema={Array:ArraySchema,Entity:EntitySchema,Object:ObjectSchema,Union:UnionSchema,Values:ValuesSchema},normalize$1=function(e,t){if(!e||"object"!=typeof e)throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+(null===e?"null":typeof e)+'".');var r={},n=addEntities(r);return{entities:r,result:visit(e,e,null,t,n,{})}},unvisitEntity=function(e,t,r,n,i){var o=n(e,t);if("object"!=typeof o||null===o)return[o,!1];i[t.key]||(i[t.key]={});var a=!0;if(!i[t.key][e]){var u=isImmutable(o)?o:_objectSpread2({},o);i[t.key][e]=u;var c=t.denormalize(u,r);i[t.key][e]=c[0],a=c[1]}return[i[t.key][e],a]},getUnvisit=function(e){var t={},r=getEntities(e);return function e(n,i){return"object"!=typeof i||i.denormalize&&"function"==typeof i.denormalize?null==n?[n,!0]:i instanceof EntitySchema?unvisitEntity(n,i,e,r,t):"function"==typeof i.denormalize?i.denormalize(n,e):[n,!0]:(Array.isArray(i)?denormalize:_denormalize)(i,n,e)}},getEntities=function(e){var t=isImmutable(e);return function(r,n){var i=n.key;return"object"==typeof r?r:t?e.getIn([i,r.toString()]):e[i]&&e[i][r]}},denormalize$1=function(e,t,r){return void 0!==e?getUnvisit(r)(e,t):[void 0,!1]};exports.denormalize=denormalize$1,exports.normalize=normalize$1,exports.schema=schema; | ||
"use strict";function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function _objectSpread2(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(r,!0).forEach((function(t){_defineProperty(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(r).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function isImmutable(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(e.hasOwnProperty("__ownerID")||e._map&&e._map.hasOwnProperty("__ownerID")))}function denormalizeImmutable(e,t,r){var n=!0;return[Object.keys(e).reduce((function(t,i){var o=""+i,a=r(t.get(o),e[o]),u=a[0];return a[1]||(n=!1),t.has(o)?t.set(o,u):t}),t),n]}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),e}Object.defineProperty(exports,"__esModule",{value:!0});var getDefaultGetId=function(e){return function(t){return isImmutable(t)?t.get(e):t[e]}},EntitySchema=function(){function e(e,t,r){if(void 0===t&&(t={}),void 0===r&&(r={}),!e||"string"!=typeof e)throw new Error("Expected a string key for Entity, but found "+e+".");var n=r,i=n.idAttribute,o=void 0===i?"id":i,a=n.mergeStrategy,u=void 0===a?function(e,t){return _objectSpread2({},e,{},t)}:a,c=n.processStrategy,s=void 0===c?function(e){return _objectSpread2({},e)}:c;this._key=e,this._getId="function"==typeof o?o:getDefaultGetId(o),this._idAttribute=o,this._mergeStrategy=u,this._processStrategy=s,this.define(t)}var t=e.prototype;return t.define=function(e){this.schema=Object.keys(e).reduce((function(t,r){var n,i=e[r];return _objectSpread2({},t,((n={})[r]=i,n))}),this.schema||{})},t.getId=function(e,t,r){return this._getId(e,t,r)},t.merge=function(e,t){return this._mergeStrategy(e,t)},t.normalize=function(e,t,r,n,i,o){var a=this,u=this.getId(e,t,r),c=this.key;if(c in o||(o[c]={}),u in o[c]||(o[c][u]=[]),o[c][u].some((function(t){return t===e})))return u;o[c][u].push(e);var s=this._processStrategy(e,t,r);return Object.keys(this.schema).forEach((function(e){if(s.hasOwnProperty(e)&&"object"==typeof s[e]){var t=a.schema[e];s[e]=n(s[e],s,e,t,i,o)}})),i(this,s,e,t,r),u},t.denormalize=function(e,t){var r=this;if(isImmutable(e))return denormalizeImmutable(this.schema,e,t);var n=!0;return Object.keys(this.schema).forEach((function(i){var o=r.schema[i],a=t(e[i],o),u=a[0];a[1]||(n=!1),e.hasOwnProperty(i)&&(e[i]=u)})),[e,n]},_createClass(e,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),e}();function _inheritsLoose(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var PolymorphicSchema=function(){function e(e,t){t&&(this._schemaAttribute="string"==typeof t?function(e){return e[t]}:t),this.define(e)}var t=e.prototype;return t.define=function(e){this.schema=e},t.getSchemaAttribute=function(e,t,r){return!this.isSingleSchema&&this._schemaAttribute(e,t,r)},t.inferSchema=function(e,t,r){if(this.isSingleSchema)return this.schema;var n=this.getSchemaAttribute(e,t,r);return this.schema[n]},t.normalizeValue=function(e,t,r,n,i,o){var a=this.inferSchema(e,t,r);if(!a)return e;var u=n(e,t,r,a,i,o);return this.isSingleSchema||null==u?u:{id:u,schema:this.getSchemaAttribute(e,t,r)}},t.denormalizeValue=function(e,t){var r=isImmutable(e)?e.get("schema"):e.schema;return this.isSingleSchema||r?t((isImmutable(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[r]):[e,!0]},_createClass(e,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),e}(),UnionSchema=function(e){function t(t,r){if(!r)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return e.call(this,t,r)||this}_inheritsLoose(t,e);var r=t.prototype;return r.normalize=function(e,t,r,n,i,o){return this.normalizeValue(e,t,r,n,i,o)},r.denormalize=function(e,t){return this.denormalizeValue(e,t)},t}(PolymorphicSchema),ValuesSchema=function(e){function t(){return e.apply(this,arguments)||this}_inheritsLoose(t,e);var r=t.prototype;return r.normalize=function(e,t,r,n,i,o){var a=this;return Object.keys(e).reduce((function(t,r,u){var c,s=e[r];return null!=s?_objectSpread2({},t,((c={})[r]=a.normalizeValue(s,e,r,n,i,o),c)):t}),{})},r.denormalize=function(e,t){var r=this,n=!0;return[Object.keys(e).reduce((function(i,o){var a,u=e[o],c=r.denormalizeValue(u,t),s=c[0];return c[1]||(n=!1),_objectSpread2({},i,((a={})[o]=s,a))}),{}),n]},t}(PolymorphicSchema),validateSchema=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]},getValues=function(e){return Array.isArray(e)?e:Object.keys(e).map((function(t){return e[t]}))},normalize=function(e,t,r,n,i,o,a){return e=validateSchema(e),getValues(t).map((function(t,u){return i(t,r,n,e,o,a)}))},denormalize=function(e,t,r){e=validateSchema(e);var n=!0;void 0===t&&e&&(r(void 0,e)[1]||(n=!1));return[t&&t.map?t.map((function(t){var i=r(t,e),o=i[0];return i[1]||(n=!1),o})).filter((function(e){return e})):t,n]},ArraySchema=function(e){function t(){return e.apply(this,arguments)||this}_inheritsLoose(t,e);var r=t.prototype;return r.normalize=function(e,t,r,n,i,o){var a=this;return getValues(e).map((function(e,u){return a.normalizeValue(e,t,r,n,i,o)})).filter((function(e){return null!=e}))},r.denormalize=function(e,t){var r=this,n=!0;void 0===e&&this.schema&&(t(void 0,this.schema)[1]||(n=!1));return[e&&e.map?e.map((function(e){var i=r.denormalizeValue(e,t),o=i[0];return i[1]||(n=!1),o})).filter((function(e){return e})):e,n]},t}(PolymorphicSchema),_normalize=function(e,t,r,n,i,o,a){var u=_objectSpread2({},t);return Object.keys(e).forEach((function(r){var n=e[r],c=i(t[r],t,r,n,o,a);null==c?delete u[r]:u[r]=c})),u},_denormalize=function(e,t,r){if(isImmutable(t))return denormalizeImmutable(e,t,r);var n=_objectSpread2({},t),i=!0;return Object.keys(e).forEach((function(t){var o=r(n[t],e[t]),a=o[0],u=o[1];null!=n[t]&&(n[t]=a),u||(i=!1)})),[n,i]},ObjectSchema=function(){function e(e){this.define(e)}var t=e.prototype;return t.define=function(e){this.schema=Object.keys(e).reduce((function(t,r){var n,i=e[r];return _objectSpread2({},t,((n={})[r]=i,n))}),this.schema||{})},t.normalize=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return _normalize.apply(void 0,[this.schema].concat(t))},t.denormalize=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return _denormalize.apply(void 0,[this.schema].concat(t))},e}(),visit=function e(t,r,n,i,o,a){return"object"==typeof t&&t?"object"!=typeof i||i.normalize&&"function"==typeof i.normalize?i.normalize(t,r,n,e,o,a):(Array.isArray(i)?normalize:_normalize)(i,t,r,n,e,o,a):t},addEntities=function(e){return function(t,r,n,i,o){var a=t.key,u=t.getId(n,i,o);a in e||(e[a]={});var c=e[a][u];e[a][u]=c?t.merge(c,r):r}},schema={Array:ArraySchema,Entity:EntitySchema,Object:ObjectSchema,Union:UnionSchema,Values:ValuesSchema},normalize$1=function(e,t){if(!e||"object"!=typeof e)throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+(null===e?"null":typeof e)+'".');var r={},n=addEntities(r);return{entities:r,result:visit(e,e,null,t,n,{})}},unvisitEntity=function(e,t,r,n,i){var o=n(e,t);if("object"!=typeof o||null===o)return[o,!1];i[t.key]||(i[t.key]={});var a=!0;if(!i[t.key][e]){var u=isImmutable(o)?o:_objectSpread2({},o);i[t.key][e]=u;var c=t.denormalize(u,r);i[t.key][e]=c[0],a=c[1]}return[i[t.key][e],a]},getUnvisit=function(e){var t={},r=getEntities(e);return function e(n,i){return"object"!=typeof i||i.denormalize&&"function"==typeof i.denormalize?null===n?[n,!0]:i instanceof EntitySchema?void 0===n?[n,!1]:unvisitEntity(n,i,e,r,t):"function"==typeof i.denormalize?i.denormalize(n,e):[n,!0]:(Array.isArray(i)?denormalize:_denormalize)(i,n,e)}},getEntities=function(e){var t=isImmutable(e);return function(r,n){var i=n.key;return"object"==typeof r?r:t?e.getIn([i,r.toString()]):e[i]&&e[i][r]}},denormalize$1=function(e,t,r){return void 0!==e?getUnvisit(r)(e,t):[void 0,!1]};exports.denormalize=denormalize$1,exports.normalize=normalize$1,exports.schema=schema; |
@@ -89,11 +89,11 @@ (function (global, factory) { | ||
if (object.has(stringKey)) { | ||
var _unvisit = unvisit(object.get(stringKey), schema[stringKey]), | ||
item = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
var _unvisit = unvisit(object.get(stringKey), schema[stringKey]), | ||
item = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
if (object.has(stringKey)) { | ||
return object.set(stringKey, item); | ||
@@ -225,14 +225,14 @@ } else { | ||
Object.keys(this.schema).forEach(function (key) { | ||
if (entity.hasOwnProperty(key)) { | ||
var schema = _this2.schema[key]; | ||
var schema = _this2.schema[key]; | ||
var _unvisit = unvisit(entity[key], schema), | ||
value = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
var _unvisit = unvisit(entity[key], schema), | ||
value = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
if (entity.hasOwnProperty(key)) { | ||
entity[key] = value; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
} | ||
@@ -432,5 +432,5 @@ }); | ||
var found = true; | ||
return [input && input.map ? input.map(function (entityOrId) { | ||
var _unvisit = unvisit(entityOrId, schema), | ||
value = _unvisit[0], | ||
if (input === undefined && schema) { | ||
var _unvisit = unvisit(undefined, schema), | ||
foundItem = _unvisit[1]; | ||
@@ -441,3 +441,13 @@ | ||
} | ||
} | ||
return [input && input.map ? input.map(function (entityOrId) { | ||
var _unvisit2 = unvisit(entityOrId, schema), | ||
value = _unvisit2[0], | ||
foundItem = _unvisit2[1]; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
return value; | ||
@@ -475,2 +485,12 @@ }).filter(function (entityOrUndefined) { | ||
var found = true; | ||
if (input === undefined && this.schema) { | ||
var _unvisit3 = unvisit(undefined, this.schema), | ||
foundItem = _unvisit3[1]; | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
} | ||
return [input && input.map ? input.map(function (entityOrId) { | ||
@@ -519,12 +539,12 @@ var _this2$denormalizeVal = _this2.denormalizeValue(entityOrId, unvisit), | ||
Object.keys(schema).forEach(function (key) { | ||
var _unvisit = unvisit(object[key], schema[key]), | ||
item = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
if (object[key] != null) { | ||
var _unvisit = unvisit(object[key], schema[key]), | ||
item = _unvisit[0], | ||
foundItem = _unvisit[1]; | ||
object[key] = item; | ||
} | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
if (!foundItem) { | ||
found = false; | ||
} | ||
@@ -662,5 +682,6 @@ }); | ||
return method(schema, input, unvisit); | ||
} | ||
} // null is considered intentional, thus always 'found' as true | ||
if (input === undefined || input === null) { | ||
if (input === null) { | ||
return [input, true]; | ||
@@ -670,2 +691,7 @@ } | ||
if (schema instanceof EntitySchema) { | ||
// unvisitEntity just can't handle undefined | ||
if (input === undefined) { | ||
return [input, false]; | ||
} | ||
return unvisitEntity(input, schema, unvisit, getEntity, cache); | ||
@@ -672,0 +698,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,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function n(e){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?r(i,!0).forEach((function(r){t(e,r,i[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):r(i).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function i(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(e.hasOwnProperty("__ownerID")||e._map&&e._map.hasOwnProperty("__ownerID")))}function o(e,t,r){var n=!0;return[Object.keys(e).reduce((function(t,i){var o=""+i;if(t.has(o)){var u=r(t.get(o),e[o]),c=u[0];return u[1]||(n=!1),t.set(o,c)}return t}),t),n]}function u(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function c(e,t,r){return t&&u(e.prototype,t),r&&u(e,r),e}var a=function(e){return function(t){return i(t)?t.get(e):t[e]}},f=function(){function e(e,t,r){if(void 0===t&&(t={}),void 0===r&&(r={}),!e||"string"!=typeof e)throw new Error("Expected a string key for Entity, but found "+e+".");var i=r,o=i.idAttribute,u=void 0===o?"id":o,c=i.mergeStrategy,f=void 0===c?function(e,t){return n({},e,{},t)}:c,s=i.processStrategy,h=void 0===s?function(e){return n({},e)}:s;this._key=e,this._getId="function"==typeof u?u:a(u),this._idAttribute=u,this._mergeStrategy=f,this._processStrategy=h,this.define(t)}var t=e.prototype;return t.define=function(e){this.schema=Object.keys(e).reduce((function(t,r){var i,o=e[r];return n({},t,((i={})[r]=o,i))}),this.schema||{})},t.getId=function(e,t,r){return this._getId(e,t,r)},t.merge=function(e,t){return this._mergeStrategy(e,t)},t.normalize=function(e,t,r,n,i,o){var u=this,c=this.getId(e,t,r),a=this.key;if(a in o||(o[a]={}),c in o[a]||(o[a][c]=[]),o[a][c].some((function(t){return t===e})))return c;o[a][c].push(e);var f=this._processStrategy(e,t,r);return Object.keys(this.schema).forEach((function(e){if(f.hasOwnProperty(e)&&"object"==typeof f[e]){var t=u.schema[e];f[e]=n(f[e],f,e,t,i,o)}})),i(this,f,e,t,r),c},t.denormalize=function(e,t){var r=this;if(i(e))return o(this.schema,e,t);var n=!0;return Object.keys(this.schema).forEach((function(i){if(e.hasOwnProperty(i)){var o=r.schema[i],u=t(e[i],o),c=u[0],a=u[1];e[i]=c,a||(n=!1)}})),[e,n]},c(e,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),e}();function s(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var h=function(){function e(e,t){t&&(this._schemaAttribute="string"==typeof t?function(e){return e[t]}:t),this.define(e)}var t=e.prototype;return t.define=function(e){this.schema=e},t.getSchemaAttribute=function(e,t,r){return!this.isSingleSchema&&this._schemaAttribute(e,t,r)},t.inferSchema=function(e,t,r){if(this.isSingleSchema)return this.schema;var n=this.getSchemaAttribute(e,t,r);return this.schema[n]},t.normalizeValue=function(e,t,r,n,i,o){var u=this.inferSchema(e,t,r);if(!u)return e;var c=n(e,t,r,u,i,o);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,r)}},t.denormalizeValue=function(e,t){var r=i(e)?e.get("schema"):e.schema;return this.isSingleSchema||r?t((i(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[r]):[e,!0]},c(e,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),e}(),l=function(e){function t(t,r){if(!r)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return e.call(this,t,r)||this}s(t,e);var r=t.prototype;return r.normalize=function(e,t,r,n,i,o){return this.normalizeValue(e,t,r,n,i,o)},r.denormalize=function(e,t){return this.denormalizeValue(e,t)},t}(h),y=function(e){function t(){return e.apply(this,arguments)||this}s(t,e);var r=t.prototype;return r.normalize=function(e,t,r,i,o,u){var c=this;return Object.keys(e).reduce((function(t,r,a){var f,s=e[r];return null!=s?n({},t,((f={})[r]=c.normalizeValue(s,e,r,i,o,u),f)):t}),{})},r.denormalize=function(e,t){var r=this,i=!0;return[Object.keys(e).reduce((function(o,u){var c,a=e[u],f=r.denormalizeValue(a,t),s=f[0];return f[1]||(i=!1),n({},o,((c={})[u]=s,c))}),{}),i]},t}(h),p=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]},m=function(e){return Array.isArray(e)?e:Object.keys(e).map((function(t){return e[t]}))},d=function(e,t,r,n,i,o,u){return e=p(e),m(t).map((function(t,c){return i(t,r,n,e,o,u)}))},v=function(e,t,r){e=p(e);var n=!0;return[t&&t.map?t.map((function(t){var i=r(t,e),o=i[0];return i[1]||(n=!1),o})).filter((function(e){return e})):t,n]},b=function(e){function t(){return e.apply(this,arguments)||this}s(t,e);var r=t.prototype;return r.normalize=function(e,t,r,n,i,o){var u=this;return m(e).map((function(e,c){return u.normalizeValue(e,t,r,n,i,o)})).filter((function(e){return null!=e}))},r.denormalize=function(e,t){var r=this,n=!0;return[e&&e.map?e.map((function(e){var i=r.denormalizeValue(e,t),o=i[0];return i[1]||(n=!1),o})).filter((function(e){return e})):e,n]},t}(h),g=function(e,t,r,i,o,u,c){var a=n({},t);return Object.keys(e).forEach((function(r){var n=e[r],i=o(t[r],t,r,n,u,c);null==i?delete a[r]:a[r]=i})),a},O=function(e,t,r){if(i(t))return o(e,t,r);var u=n({},t),c=!0;return Object.keys(e).forEach((function(t){if(null!=u[t]){var n=r(u[t],e[t]),i=n[0],o=n[1];u[t]=i,o||(c=!1)}})),[u,c]},j=function e(t,r,n,i,o,u){return"object"==typeof t&&t?"object"!=typeof i||i.normalize&&"function"==typeof i.normalize?i.normalize(t,r,n,e,o,u):(Array.isArray(i)?d:g)(i,t,r,n,e,o,u):t},z={Array:b,Entity:f,Object:function(){function e(e){this.define(e)}var t=e.prototype;return t.define=function(e){this.schema=Object.keys(e).reduce((function(t,r){var i,o=e[r];return n({},t,((i={})[r]=o,i))}),this.schema||{})},t.normalize=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return g.apply(void 0,[this.schema].concat(t))},t.denormalize=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return O.apply(void 0,[this.schema].concat(t))},e}(),Union:l,Values:y},k=function(e){var t={},r=S(e);return function e(o,u){return"object"!=typeof u||u.denormalize&&"function"==typeof u.denormalize?null==o?[o,!0]:u instanceof f?function(e,t,r,o,u){var c=o(e,t);if("object"!=typeof c||null===c)return[c,!1];u[t.key]||(u[t.key]={});var a=!0;if(!u[t.key][e]){var f=i(c)?c:n({},c);u[t.key][e]=f;var s=t.denormalize(f,r);u[t.key][e]=s[0],a=s[1]}return[u[t.key][e],a]}(o,u,e,r,t):"function"==typeof u.denormalize?u.denormalize(o,e):[o,!0]:(Array.isArray(u)?v:O)(u,o,e)}},S=function(e){var t=i(e);return function(r,n){var i=n.key;return"object"==typeof r?r:t?e.getIn([i,r.toString()]):e[i]&&e[i][r]}};e.denormalize=function(e,t,r){return void 0!==e?k(r)(e,t):[void 0,!1]},e.normalize=function(e,t){if(!e||"object"!=typeof e)throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+(null===e?"null":typeof e)+'".');var r={},n=function(e){return function(t,r,n,i,o){var u=t.key,c=t.getId(n,i,o);u in e||(e[u]={});var a=e[u][c];e[u][c]=a?t.merge(a,r):r}}(r);return{entities:r,result:j(e,e,null,t,n,{})}},e.schema=z,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).rest_hooks_normalizr={})}(this,(function(e){"use strict";function t(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function n(e){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?r(i,!0).forEach((function(r){t(e,r,i[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):r(i).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function i(e){return!(!e||"function"!=typeof e.hasOwnProperty||!(e.hasOwnProperty("__ownerID")||e._map&&e._map.hasOwnProperty("__ownerID")))}function o(e,t,r){var n=!0;return[Object.keys(e).reduce((function(t,i){var o=""+i,u=r(t.get(o),e[o]),c=u[0];return u[1]||(n=!1),t.has(o)?t.set(o,c):t}),t),n]}function u(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function c(e,t,r){return t&&u(e.prototype,t),r&&u(e,r),e}var a=function(e){return function(t){return i(t)?t.get(e):t[e]}},f=function(){function e(e,t,r){if(void 0===t&&(t={}),void 0===r&&(r={}),!e||"string"!=typeof e)throw new Error("Expected a string key for Entity, but found "+e+".");var i=r,o=i.idAttribute,u=void 0===o?"id":o,c=i.mergeStrategy,f=void 0===c?function(e,t){return n({},e,{},t)}:c,s=i.processStrategy,h=void 0===s?function(e){return n({},e)}:s;this._key=e,this._getId="function"==typeof u?u:a(u),this._idAttribute=u,this._mergeStrategy=f,this._processStrategy=h,this.define(t)}var t=e.prototype;return t.define=function(e){this.schema=Object.keys(e).reduce((function(t,r){var i,o=e[r];return n({},t,((i={})[r]=o,i))}),this.schema||{})},t.getId=function(e,t,r){return this._getId(e,t,r)},t.merge=function(e,t){return this._mergeStrategy(e,t)},t.normalize=function(e,t,r,n,i,o){var u=this,c=this.getId(e,t,r),a=this.key;if(a in o||(o[a]={}),c in o[a]||(o[a][c]=[]),o[a][c].some((function(t){return t===e})))return c;o[a][c].push(e);var f=this._processStrategy(e,t,r);return Object.keys(this.schema).forEach((function(e){if(f.hasOwnProperty(e)&&"object"==typeof f[e]){var t=u.schema[e];f[e]=n(f[e],f,e,t,i,o)}})),i(this,f,e,t,r),c},t.denormalize=function(e,t){var r=this;if(i(e))return o(this.schema,e,t);var n=!0;return Object.keys(this.schema).forEach((function(i){var o=r.schema[i],u=t(e[i],o),c=u[0];u[1]||(n=!1),e.hasOwnProperty(i)&&(e[i]=c)})),[e,n]},c(e,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),e}();function s(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var h=function(){function e(e,t){t&&(this._schemaAttribute="string"==typeof t?function(e){return e[t]}:t),this.define(e)}var t=e.prototype;return t.define=function(e){this.schema=e},t.getSchemaAttribute=function(e,t,r){return!this.isSingleSchema&&this._schemaAttribute(e,t,r)},t.inferSchema=function(e,t,r){if(this.isSingleSchema)return this.schema;var n=this.getSchemaAttribute(e,t,r);return this.schema[n]},t.normalizeValue=function(e,t,r,n,i,o){var u=this.inferSchema(e,t,r);if(!u)return e;var c=n(e,t,r,u,i,o);return this.isSingleSchema||null==c?c:{id:c,schema:this.getSchemaAttribute(e,t,r)}},t.denormalizeValue=function(e,t){var r=i(e)?e.get("schema"):e.schema;return this.isSingleSchema||r?t((i(e)?e.get("id"):e.id)||e,this.isSingleSchema?this.schema:this.schema[r]):[e,!0]},c(e,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),e}(),l=function(e){function t(t,r){if(!r)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return e.call(this,t,r)||this}s(t,e);var r=t.prototype;return r.normalize=function(e,t,r,n,i,o){return this.normalizeValue(e,t,r,n,i,o)},r.denormalize=function(e,t){return this.denormalizeValue(e,t)},t}(h),y=function(e){function t(){return e.apply(this,arguments)||this}s(t,e);var r=t.prototype;return r.normalize=function(e,t,r,i,o,u){var c=this;return Object.keys(e).reduce((function(t,r,a){var f,s=e[r];return null!=s?n({},t,((f={})[r]=c.normalizeValue(s,e,r,i,o,u),f)):t}),{})},r.denormalize=function(e,t){var r=this,i=!0;return[Object.keys(e).reduce((function(o,u){var c,a=e[u],f=r.denormalizeValue(a,t),s=f[0];return f[1]||(i=!1),n({},o,((c={})[u]=s,c))}),{}),i]},t}(h),p=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]},m=function(e){return Array.isArray(e)?e:Object.keys(e).map((function(t){return e[t]}))},d=function(e,t,r,n,i,o,u){return e=p(e),m(t).map((function(t,c){return i(t,r,n,e,o,u)}))},v=function(e,t,r){e=p(e);var n=!0;void 0===t&&e&&(r(void 0,e)[1]||(n=!1));return[t&&t.map?t.map((function(t){var i=r(t,e),o=i[0];return i[1]||(n=!1),o})).filter((function(e){return e})):t,n]},b=function(e){function t(){return e.apply(this,arguments)||this}s(t,e);var r=t.prototype;return r.normalize=function(e,t,r,n,i,o){var u=this;return m(e).map((function(e,c){return u.normalizeValue(e,t,r,n,i,o)})).filter((function(e){return null!=e}))},r.denormalize=function(e,t){var r=this,n=!0;void 0===e&&this.schema&&(t(void 0,this.schema)[1]||(n=!1));return[e&&e.map?e.map((function(e){var i=r.denormalizeValue(e,t),o=i[0];return i[1]||(n=!1),o})).filter((function(e){return e})):e,n]},t}(h),g=function(e,t,r,i,o,u,c){var a=n({},t);return Object.keys(e).forEach((function(r){var n=e[r],i=o(t[r],t,r,n,u,c);null==i?delete a[r]:a[r]=i})),a},O=function(e,t,r){if(i(t))return o(e,t,r);var u=n({},t),c=!0;return Object.keys(e).forEach((function(t){var n=r(u[t],e[t]),i=n[0],o=n[1];null!=u[t]&&(u[t]=i),o||(c=!1)})),[u,c]},j=function e(t,r,n,i,o,u){return"object"==typeof t&&t?"object"!=typeof i||i.normalize&&"function"==typeof i.normalize?i.normalize(t,r,n,e,o,u):(Array.isArray(i)?d:g)(i,t,r,n,e,o,u):t},z={Array:b,Entity:f,Object:function(){function e(e){this.define(e)}var t=e.prototype;return t.define=function(e){this.schema=Object.keys(e).reduce((function(t,r){var i,o=e[r];return n({},t,((i={})[r]=o,i))}),this.schema||{})},t.normalize=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return g.apply(void 0,[this.schema].concat(t))},t.denormalize=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return O.apply(void 0,[this.schema].concat(t))},e}(),Union:l,Values:y},k=function(e){var t={},r=S(e);return function e(o,u){return"object"!=typeof u||u.denormalize&&"function"==typeof u.denormalize?null===o?[o,!0]:u instanceof f?void 0===o?[o,!1]:function(e,t,r,o,u){var c=o(e,t);if("object"!=typeof c||null===c)return[c,!1];u[t.key]||(u[t.key]={});var a=!0;if(!u[t.key][e]){var f=i(c)?c:n({},c);u[t.key][e]=f;var s=t.denormalize(f,r);u[t.key][e]=s[0],a=s[1]}return[u[t.key][e],a]}(o,u,e,r,t):"function"==typeof u.denormalize?u.denormalize(o,e):[o,!0]:(Array.isArray(u)?v:O)(u,o,e)}},S=function(e){var t=i(e);return function(r,n){var i=n.key;return"object"==typeof r?r:t?e.getIn([i,r.toString()]):e[i]&&e[i][r]}};e.denormalize=function(e,t,r){return void 0!==e?k(r)(e,t):[void 0,!1]},e.normalize=function(e,t){if(!e||"object"!=typeof e)throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+(null===e?"null":typeof e)+'".');var r={},n=function(e){return function(t,r,n,i,o){var u=t.key,c=t.getId(n,i,o);u in e||(e[u]={});var a=e[u][c];e[u][c]=a?t.merge(a,r):r}}(r);return{entities:r,result:j(e,e,null,t,n,{})}},e.schema=z,Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "@rest-hooks/normalizr", | ||
"version": "4.0.0-beta.0", | ||
"version": "4.0.0-beta.1", | ||
"description": "Normalizes and denormalizes JSON according to schema for Redux and Flux applications", | ||
@@ -5,0 +5,0 @@ "bugs": { |
154849
3015