@process-street/normalizr
Advanced tools
Comparing version 3.3.1 to 3.3.4
@@ -222,2 +222,14 @@ define(['exports'], function (exports) { 'use strict'; | ||
}, { | ||
key: "isValid", | ||
value: function isValid(entity, entityId) { | ||
var keys = Object.keys(entity); | ||
if (keys.length > 1) { | ||
return true; | ||
} // This is in order to support single value Entities | ||
return keys.length === 1 && Object.values(entity)[0] !== entityId; | ||
} | ||
}, { | ||
key: "normalize", | ||
@@ -243,4 +255,9 @@ value: function normalize(input, parent, key, visit, addEntity) { | ||
}); | ||
addEntity(this, processedEntity, input, parent, key); | ||
return this.getId(input, parent, key); | ||
var entityId = this.getId(input, parent, key); | ||
if (this.isValid(processedEntity, entityId)) { | ||
addEntity(this, processedEntity, input, parent, key); | ||
} | ||
return entityId; | ||
} | ||
@@ -494,13 +511,17 @@ }, { | ||
var localSchema = schema[referenceKey]; | ||
var value = visit(input[referenceKey], input, referenceKey, localSchema, addEntity); | ||
var referencedValue = input[referenceKey]; | ||
if (value === undefined || value === null) { | ||
delete object[referenceKey]; | ||
} else { | ||
if (Array.isArray(value) || localSchema._key === undefined || parent === input) { | ||
object[referenceKey] = value; | ||
if (referencedValue !== undefined) { | ||
var value = visit(referencedValue, input, referenceKey, localSchema, addEntity); | ||
if (value === undefined || value === null) { | ||
delete object[referenceKey]; | ||
} else { | ||
object[referenceKey] = { | ||
id: value | ||
}; | ||
if (Array.isArray(value) || localSchema._key === undefined || parent === input) { | ||
object[referenceKey] = value; | ||
} else { | ||
object[referenceKey] = { | ||
id: value | ||
}; | ||
} | ||
} | ||
@@ -521,3 +542,4 @@ } | ||
if (object[referenceKey]) { | ||
object[referenceKey] = unvisit(object[referenceKey], schema[referenceKey]); | ||
var referencedValue = unvisit(object[referenceKey], schema[referenceKey]); | ||
object[referenceKey] = referencedValue || object[referenceKey]; | ||
} | ||
@@ -675,3 +697,12 @@ }); | ||
return isImmutable$1 ? entities.getIn([schemaKey, entityOrId.toString()]) : entities[schemaKey][entityOrId]; | ||
if (isImmutable$1) { | ||
return entities.getIn([schemaKey, entityOrId.toString()]); | ||
} else if (entities[schemaKey]) { | ||
return entities[schemaKey][entityOrId]; | ||
} else { | ||
// TODO this ignores id attribute configuration | ||
return { | ||
id: entityOrId | ||
}; | ||
} | ||
}; | ||
@@ -678,0 +709,0 @@ }; |
@@ -222,2 +222,14 @@ define(['exports'], function (exports) { 'use strict'; | ||
}, { | ||
key: "isValid", | ||
value: function isValid(entity, entityId) { | ||
var keys = Object.keys(entity); | ||
if (keys.length > 1) { | ||
return true; | ||
} // This is in order to support single value Entities | ||
return keys.length === 1 && Object.values(entity)[0] !== entityId; | ||
} | ||
}, { | ||
key: "normalize", | ||
@@ -243,4 +255,9 @@ value: function normalize(input, parent, key, visit, addEntity) { | ||
}); | ||
addEntity(this, processedEntity, input, parent, key); | ||
return this.getId(input, parent, key); | ||
var entityId = this.getId(input, parent, key); | ||
if (this.isValid(processedEntity, entityId)) { | ||
addEntity(this, processedEntity, input, parent, key); | ||
} | ||
return entityId; | ||
} | ||
@@ -494,13 +511,17 @@ }, { | ||
var localSchema = schema[referenceKey]; | ||
var value = visit(input[referenceKey], input, referenceKey, localSchema, addEntity); | ||
var referencedValue = input[referenceKey]; | ||
if (value === undefined || value === null) { | ||
delete object[referenceKey]; | ||
} else { | ||
if (Array.isArray(value) || localSchema._key === undefined || parent === input) { | ||
object[referenceKey] = value; | ||
if (referencedValue !== undefined) { | ||
var value = visit(referencedValue, input, referenceKey, localSchema, addEntity); | ||
if (value === undefined || value === null) { | ||
delete object[referenceKey]; | ||
} else { | ||
object[referenceKey] = { | ||
id: value | ||
}; | ||
if (Array.isArray(value) || localSchema._key === undefined || parent === input) { | ||
object[referenceKey] = value; | ||
} else { | ||
object[referenceKey] = { | ||
id: value | ||
}; | ||
} | ||
} | ||
@@ -521,3 +542,4 @@ } | ||
if (object[referenceKey]) { | ||
object[referenceKey] = unvisit(object[referenceKey], schema[referenceKey]); | ||
var referencedValue = unvisit(object[referenceKey], schema[referenceKey]); | ||
object[referenceKey] = referencedValue || object[referenceKey]; | ||
} | ||
@@ -675,3 +697,12 @@ }); | ||
return isImmutable$1 ? entities.getIn([schemaKey, entityOrId.toString()]) : entities[schemaKey][entityOrId]; | ||
if (isImmutable$1) { | ||
return entities.getIn([schemaKey, entityOrId.toString()]); | ||
} else if (entities[schemaKey]) { | ||
return entities[schemaKey][entityOrId]; | ||
} else { | ||
// TODO this ignores id attribute configuration | ||
return { | ||
id: entityOrId | ||
}; | ||
} | ||
}; | ||
@@ -678,0 +709,0 @@ }; |
@@ -223,2 +223,14 @@ (function (exports) { | ||
}, { | ||
key: "isValid", | ||
value: function isValid(entity, entityId) { | ||
var keys = Object.keys(entity); | ||
if (keys.length > 1) { | ||
return true; | ||
} // This is in order to support single value Entities | ||
return keys.length === 1 && Object.values(entity)[0] !== entityId; | ||
} | ||
}, { | ||
key: "normalize", | ||
@@ -244,4 +256,9 @@ value: function normalize(input, parent, key, visit, addEntity) { | ||
}); | ||
addEntity(this, processedEntity, input, parent, key); | ||
return this.getId(input, parent, key); | ||
var entityId = this.getId(input, parent, key); | ||
if (this.isValid(processedEntity, entityId)) { | ||
addEntity(this, processedEntity, input, parent, key); | ||
} | ||
return entityId; | ||
} | ||
@@ -495,13 +512,17 @@ }, { | ||
var localSchema = schema[referenceKey]; | ||
var value = visit(input[referenceKey], input, referenceKey, localSchema, addEntity); | ||
var referencedValue = input[referenceKey]; | ||
if (value === undefined || value === null) { | ||
delete object[referenceKey]; | ||
} else { | ||
if (Array.isArray(value) || localSchema._key === undefined || parent === input) { | ||
object[referenceKey] = value; | ||
if (referencedValue !== undefined) { | ||
var value = visit(referencedValue, input, referenceKey, localSchema, addEntity); | ||
if (value === undefined || value === null) { | ||
delete object[referenceKey]; | ||
} else { | ||
object[referenceKey] = { | ||
id: value | ||
}; | ||
if (Array.isArray(value) || localSchema._key === undefined || parent === input) { | ||
object[referenceKey] = value; | ||
} else { | ||
object[referenceKey] = { | ||
id: value | ||
}; | ||
} | ||
} | ||
@@ -522,3 +543,4 @@ } | ||
if (object[referenceKey]) { | ||
object[referenceKey] = unvisit(object[referenceKey], schema[referenceKey]); | ||
var referencedValue = unvisit(object[referenceKey], schema[referenceKey]); | ||
object[referenceKey] = referencedValue || object[referenceKey]; | ||
} | ||
@@ -676,3 +698,12 @@ }); | ||
return isImmutable$1 ? entities.getIn([schemaKey, entityOrId.toString()]) : entities[schemaKey][entityOrId]; | ||
if (isImmutable$1) { | ||
return entities.getIn([schemaKey, entityOrId.toString()]); | ||
} else if (entities[schemaKey]) { | ||
return entities[schemaKey][entityOrId]; | ||
} else { | ||
// TODO this ignores id attribute configuration | ||
return { | ||
id: entityOrId | ||
}; | ||
} | ||
}; | ||
@@ -679,0 +710,0 @@ }; |
@@ -223,2 +223,14 @@ (function (exports) { | ||
}, { | ||
key: "isValid", | ||
value: function isValid(entity, entityId) { | ||
var keys = Object.keys(entity); | ||
if (keys.length > 1) { | ||
return true; | ||
} // This is in order to support single value Entities | ||
return keys.length === 1 && Object.values(entity)[0] !== entityId; | ||
} | ||
}, { | ||
key: "normalize", | ||
@@ -244,4 +256,9 @@ value: function normalize(input, parent, key, visit, addEntity) { | ||
}); | ||
addEntity(this, processedEntity, input, parent, key); | ||
return this.getId(input, parent, key); | ||
var entityId = this.getId(input, parent, key); | ||
if (this.isValid(processedEntity, entityId)) { | ||
addEntity(this, processedEntity, input, parent, key); | ||
} | ||
return entityId; | ||
} | ||
@@ -495,13 +512,17 @@ }, { | ||
var localSchema = schema[referenceKey]; | ||
var value = visit(input[referenceKey], input, referenceKey, localSchema, addEntity); | ||
var referencedValue = input[referenceKey]; | ||
if (value === undefined || value === null) { | ||
delete object[referenceKey]; | ||
} else { | ||
if (Array.isArray(value) || localSchema._key === undefined || parent === input) { | ||
object[referenceKey] = value; | ||
if (referencedValue !== undefined) { | ||
var value = visit(referencedValue, input, referenceKey, localSchema, addEntity); | ||
if (value === undefined || value === null) { | ||
delete object[referenceKey]; | ||
} else { | ||
object[referenceKey] = { | ||
id: value | ||
}; | ||
if (Array.isArray(value) || localSchema._key === undefined || parent === input) { | ||
object[referenceKey] = value; | ||
} else { | ||
object[referenceKey] = { | ||
id: value | ||
}; | ||
} | ||
} | ||
@@ -522,3 +543,4 @@ } | ||
if (object[referenceKey]) { | ||
object[referenceKey] = unvisit(object[referenceKey], schema[referenceKey]); | ||
var referencedValue = unvisit(object[referenceKey], schema[referenceKey]); | ||
object[referenceKey] = referencedValue || object[referenceKey]; | ||
} | ||
@@ -676,3 +698,12 @@ }); | ||
return isImmutable$1 ? entities.getIn([schemaKey, entityOrId.toString()]) : entities[schemaKey][entityOrId]; | ||
if (isImmutable$1) { | ||
return entities.getIn([schemaKey, entityOrId.toString()]); | ||
} else if (entities[schemaKey]) { | ||
return entities[schemaKey][entityOrId]; | ||
} else { | ||
// TODO this ignores id attribute configuration | ||
return { | ||
id: entityOrId | ||
}; | ||
} | ||
}; | ||
@@ -679,0 +710,0 @@ }; |
@@ -220,2 +220,14 @@ function _typeof(obj) { | ||
}, { | ||
key: "isValid", | ||
value: function isValid(entity, entityId) { | ||
var keys = Object.keys(entity); | ||
if (keys.length > 1) { | ||
return true; | ||
} // This is in order to support single value Entities | ||
return keys.length === 1 && Object.values(entity)[0] !== entityId; | ||
} | ||
}, { | ||
key: "normalize", | ||
@@ -241,4 +253,9 @@ value: function normalize(input, parent, key, visit, addEntity) { | ||
}); | ||
addEntity(this, processedEntity, input, parent, key); | ||
return this.getId(input, parent, key); | ||
var entityId = this.getId(input, parent, key); | ||
if (this.isValid(processedEntity, entityId)) { | ||
addEntity(this, processedEntity, input, parent, key); | ||
} | ||
return entityId; | ||
} | ||
@@ -492,13 +509,17 @@ }, { | ||
var localSchema = schema[referenceKey]; | ||
var value = visit(input[referenceKey], input, referenceKey, localSchema, addEntity); | ||
var referencedValue = input[referenceKey]; | ||
if (value === undefined || value === null) { | ||
delete object[referenceKey]; | ||
} else { | ||
if (Array.isArray(value) || localSchema._key === undefined || parent === input) { | ||
object[referenceKey] = value; | ||
if (referencedValue !== undefined) { | ||
var value = visit(referencedValue, input, referenceKey, localSchema, addEntity); | ||
if (value === undefined || value === null) { | ||
delete object[referenceKey]; | ||
} else { | ||
object[referenceKey] = { | ||
id: value | ||
}; | ||
if (Array.isArray(value) || localSchema._key === undefined || parent === input) { | ||
object[referenceKey] = value; | ||
} else { | ||
object[referenceKey] = { | ||
id: value | ||
}; | ||
} | ||
} | ||
@@ -519,3 +540,4 @@ } | ||
if (object[referenceKey]) { | ||
object[referenceKey] = unvisit(object[referenceKey], schema[referenceKey]); | ||
var referencedValue = unvisit(object[referenceKey], schema[referenceKey]); | ||
object[referenceKey] = referencedValue || object[referenceKey]; | ||
} | ||
@@ -673,3 +695,12 @@ }); | ||
return isImmutable$1 ? entities.getIn([schemaKey, entityOrId.toString()]) : entities[schemaKey][entityOrId]; | ||
if (isImmutable$1) { | ||
return entities.getIn([schemaKey, entityOrId.toString()]); | ||
} else if (entities[schemaKey]) { | ||
return entities[schemaKey][entityOrId]; | ||
} else { | ||
// TODO this ignores id attribute configuration | ||
return { | ||
id: entityOrId | ||
}; | ||
} | ||
}; | ||
@@ -676,0 +707,0 @@ }; |
@@ -220,2 +220,14 @@ function _typeof(obj) { | ||
}, { | ||
key: "isValid", | ||
value: function isValid(entity, entityId) { | ||
var keys = Object.keys(entity); | ||
if (keys.length > 1) { | ||
return true; | ||
} // This is in order to support single value Entities | ||
return keys.length === 1 && Object.values(entity)[0] !== entityId; | ||
} | ||
}, { | ||
key: "normalize", | ||
@@ -241,4 +253,9 @@ value: function normalize(input, parent, key, visit, addEntity) { | ||
}); | ||
addEntity(this, processedEntity, input, parent, key); | ||
return this.getId(input, parent, key); | ||
var entityId = this.getId(input, parent, key); | ||
if (this.isValid(processedEntity, entityId)) { | ||
addEntity(this, processedEntity, input, parent, key); | ||
} | ||
return entityId; | ||
} | ||
@@ -492,13 +509,17 @@ }, { | ||
var localSchema = schema[referenceKey]; | ||
var value = visit(input[referenceKey], input, referenceKey, localSchema, addEntity); | ||
var referencedValue = input[referenceKey]; | ||
if (value === undefined || value === null) { | ||
delete object[referenceKey]; | ||
} else { | ||
if (Array.isArray(value) || localSchema._key === undefined || parent === input) { | ||
object[referenceKey] = value; | ||
if (referencedValue !== undefined) { | ||
var value = visit(referencedValue, input, referenceKey, localSchema, addEntity); | ||
if (value === undefined || value === null) { | ||
delete object[referenceKey]; | ||
} else { | ||
object[referenceKey] = { | ||
id: value | ||
}; | ||
if (Array.isArray(value) || localSchema._key === undefined || parent === input) { | ||
object[referenceKey] = value; | ||
} else { | ||
object[referenceKey] = { | ||
id: value | ||
}; | ||
} | ||
} | ||
@@ -519,3 +540,4 @@ } | ||
if (object[referenceKey]) { | ||
object[referenceKey] = unvisit(object[referenceKey], schema[referenceKey]); | ||
var referencedValue = unvisit(object[referenceKey], schema[referenceKey]); | ||
object[referenceKey] = referencedValue || object[referenceKey]; | ||
} | ||
@@ -673,3 +695,12 @@ }); | ||
return isImmutable$1 ? entities.getIn([schemaKey, entityOrId.toString()]) : entities[schemaKey][entityOrId]; | ||
if (isImmutable$1) { | ||
return entities.getIn([schemaKey, entityOrId.toString()]); | ||
} else if (entities[schemaKey]) { | ||
return entities[schemaKey][entityOrId]; | ||
} else { | ||
// TODO this ignores id attribute configuration | ||
return { | ||
id: entityOrId | ||
}; | ||
} | ||
}; | ||
@@ -676,0 +707,0 @@ }; |
@@ -224,2 +224,14 @@ 'use strict'; | ||
}, { | ||
key: "isValid", | ||
value: function isValid(entity, entityId) { | ||
var keys = Object.keys(entity); | ||
if (keys.length > 1) { | ||
return true; | ||
} // This is in order to support single value Entities | ||
return keys.length === 1 && Object.values(entity)[0] !== entityId; | ||
} | ||
}, { | ||
key: "normalize", | ||
@@ -245,4 +257,9 @@ value: function normalize(input, parent, key, visit, addEntity) { | ||
}); | ||
addEntity(this, processedEntity, input, parent, key); | ||
return this.getId(input, parent, key); | ||
var entityId = this.getId(input, parent, key); | ||
if (this.isValid(processedEntity, entityId)) { | ||
addEntity(this, processedEntity, input, parent, key); | ||
} | ||
return entityId; | ||
} | ||
@@ -496,13 +513,17 @@ }, { | ||
var localSchema = schema[referenceKey]; | ||
var value = visit(input[referenceKey], input, referenceKey, localSchema, addEntity); | ||
var referencedValue = input[referenceKey]; | ||
if (value === undefined || value === null) { | ||
delete object[referenceKey]; | ||
} else { | ||
if (Array.isArray(value) || localSchema._key === undefined || parent === input) { | ||
object[referenceKey] = value; | ||
if (referencedValue !== undefined) { | ||
var value = visit(referencedValue, input, referenceKey, localSchema, addEntity); | ||
if (value === undefined || value === null) { | ||
delete object[referenceKey]; | ||
} else { | ||
object[referenceKey] = { | ||
id: value | ||
}; | ||
if (Array.isArray(value) || localSchema._key === undefined || parent === input) { | ||
object[referenceKey] = value; | ||
} else { | ||
object[referenceKey] = { | ||
id: value | ||
}; | ||
} | ||
} | ||
@@ -523,3 +544,4 @@ } | ||
if (object[referenceKey]) { | ||
object[referenceKey] = unvisit(object[referenceKey], schema[referenceKey]); | ||
var referencedValue = unvisit(object[referenceKey], schema[referenceKey]); | ||
object[referenceKey] = referencedValue || object[referenceKey]; | ||
} | ||
@@ -677,3 +699,12 @@ }); | ||
return isImmutable$1 ? entities.getIn([schemaKey, entityOrId.toString()]) : entities[schemaKey][entityOrId]; | ||
if (isImmutable$1) { | ||
return entities.getIn([schemaKey, entityOrId.toString()]); | ||
} else if (entities[schemaKey]) { | ||
return entities[schemaKey][entityOrId]; | ||
} else { | ||
// TODO this ignores id attribute configuration | ||
return { | ||
id: entityOrId | ||
}; | ||
} | ||
}; | ||
@@ -680,0 +711,0 @@ }; |
@@ -224,2 +224,14 @@ 'use strict'; | ||
}, { | ||
key: "isValid", | ||
value: function isValid(entity, entityId) { | ||
var keys = Object.keys(entity); | ||
if (keys.length > 1) { | ||
return true; | ||
} // This is in order to support single value Entities | ||
return keys.length === 1 && Object.values(entity)[0] !== entityId; | ||
} | ||
}, { | ||
key: "normalize", | ||
@@ -245,4 +257,9 @@ value: function normalize(input, parent, key, visit, addEntity) { | ||
}); | ||
addEntity(this, processedEntity, input, parent, key); | ||
return this.getId(input, parent, key); | ||
var entityId = this.getId(input, parent, key); | ||
if (this.isValid(processedEntity, entityId)) { | ||
addEntity(this, processedEntity, input, parent, key); | ||
} | ||
return entityId; | ||
} | ||
@@ -496,13 +513,17 @@ }, { | ||
var localSchema = schema[referenceKey]; | ||
var value = visit(input[referenceKey], input, referenceKey, localSchema, addEntity); | ||
var referencedValue = input[referenceKey]; | ||
if (value === undefined || value === null) { | ||
delete object[referenceKey]; | ||
} else { | ||
if (Array.isArray(value) || localSchema._key === undefined || parent === input) { | ||
object[referenceKey] = value; | ||
if (referencedValue !== undefined) { | ||
var value = visit(referencedValue, input, referenceKey, localSchema, addEntity); | ||
if (value === undefined || value === null) { | ||
delete object[referenceKey]; | ||
} else { | ||
object[referenceKey] = { | ||
id: value | ||
}; | ||
if (Array.isArray(value) || localSchema._key === undefined || parent === input) { | ||
object[referenceKey] = value; | ||
} else { | ||
object[referenceKey] = { | ||
id: value | ||
}; | ||
} | ||
} | ||
@@ -523,3 +544,4 @@ } | ||
if (object[referenceKey]) { | ||
object[referenceKey] = unvisit(object[referenceKey], schema[referenceKey]); | ||
var referencedValue = unvisit(object[referenceKey], schema[referenceKey]); | ||
object[referenceKey] = referencedValue || object[referenceKey]; | ||
} | ||
@@ -677,3 +699,12 @@ }); | ||
return isImmutable$1 ? entities.getIn([schemaKey, entityOrId.toString()]) : entities[schemaKey][entityOrId]; | ||
if (isImmutable$1) { | ||
return entities.getIn([schemaKey, entityOrId.toString()]); | ||
} else if (entities[schemaKey]) { | ||
return entities[schemaKey][entityOrId]; | ||
} else { | ||
// TODO this ignores id attribute configuration | ||
return { | ||
id: entityOrId | ||
}; | ||
} | ||
}; | ||
@@ -680,0 +711,0 @@ }; |
@@ -226,2 +226,14 @@ (function (global, factory) { | ||
}, { | ||
key: "isValid", | ||
value: function isValid(entity, entityId) { | ||
var keys = Object.keys(entity); | ||
if (keys.length > 1) { | ||
return true; | ||
} // This is in order to support single value Entities | ||
return keys.length === 1 && Object.values(entity)[0] !== entityId; | ||
} | ||
}, { | ||
key: "normalize", | ||
@@ -247,4 +259,9 @@ value: function normalize(input, parent, key, visit, addEntity) { | ||
}); | ||
addEntity(this, processedEntity, input, parent, key); | ||
return this.getId(input, parent, key); | ||
var entityId = this.getId(input, parent, key); | ||
if (this.isValid(processedEntity, entityId)) { | ||
addEntity(this, processedEntity, input, parent, key); | ||
} | ||
return entityId; | ||
} | ||
@@ -498,13 +515,17 @@ }, { | ||
var localSchema = schema[referenceKey]; | ||
var value = visit(input[referenceKey], input, referenceKey, localSchema, addEntity); | ||
var referencedValue = input[referenceKey]; | ||
if (value === undefined || value === null) { | ||
delete object[referenceKey]; | ||
} else { | ||
if (Array.isArray(value) || localSchema._key === undefined || parent === input) { | ||
object[referenceKey] = value; | ||
if (referencedValue !== undefined) { | ||
var value = visit(referencedValue, input, referenceKey, localSchema, addEntity); | ||
if (value === undefined || value === null) { | ||
delete object[referenceKey]; | ||
} else { | ||
object[referenceKey] = { | ||
id: value | ||
}; | ||
if (Array.isArray(value) || localSchema._key === undefined || parent === input) { | ||
object[referenceKey] = value; | ||
} else { | ||
object[referenceKey] = { | ||
id: value | ||
}; | ||
} | ||
} | ||
@@ -525,3 +546,4 @@ } | ||
if (object[referenceKey]) { | ||
object[referenceKey] = unvisit(object[referenceKey], schema[referenceKey]); | ||
var referencedValue = unvisit(object[referenceKey], schema[referenceKey]); | ||
object[referenceKey] = referencedValue || object[referenceKey]; | ||
} | ||
@@ -679,3 +701,12 @@ }); | ||
return isImmutable$1 ? entities.getIn([schemaKey, entityOrId.toString()]) : entities[schemaKey][entityOrId]; | ||
if (isImmutable$1) { | ||
return entities.getIn([schemaKey, entityOrId.toString()]); | ||
} else if (entities[schemaKey]) { | ||
return entities[schemaKey][entityOrId]; | ||
} else { | ||
// TODO this ignores id attribute configuration | ||
return { | ||
id: entityOrId | ||
}; | ||
} | ||
}; | ||
@@ -682,0 +713,0 @@ }; |
@@ -226,2 +226,14 @@ (function (global, factory) { | ||
}, { | ||
key: "isValid", | ||
value: function isValid(entity, entityId) { | ||
var keys = Object.keys(entity); | ||
if (keys.length > 1) { | ||
return true; | ||
} // This is in order to support single value Entities | ||
return keys.length === 1 && Object.values(entity)[0] !== entityId; | ||
} | ||
}, { | ||
key: "normalize", | ||
@@ -247,4 +259,9 @@ value: function normalize(input, parent, key, visit, addEntity) { | ||
}); | ||
addEntity(this, processedEntity, input, parent, key); | ||
return this.getId(input, parent, key); | ||
var entityId = this.getId(input, parent, key); | ||
if (this.isValid(processedEntity, entityId)) { | ||
addEntity(this, processedEntity, input, parent, key); | ||
} | ||
return entityId; | ||
} | ||
@@ -498,13 +515,17 @@ }, { | ||
var localSchema = schema[referenceKey]; | ||
var value = visit(input[referenceKey], input, referenceKey, localSchema, addEntity); | ||
var referencedValue = input[referenceKey]; | ||
if (value === undefined || value === null) { | ||
delete object[referenceKey]; | ||
} else { | ||
if (Array.isArray(value) || localSchema._key === undefined || parent === input) { | ||
object[referenceKey] = value; | ||
if (referencedValue !== undefined) { | ||
var value = visit(referencedValue, input, referenceKey, localSchema, addEntity); | ||
if (value === undefined || value === null) { | ||
delete object[referenceKey]; | ||
} else { | ||
object[referenceKey] = { | ||
id: value | ||
}; | ||
if (Array.isArray(value) || localSchema._key === undefined || parent === input) { | ||
object[referenceKey] = value; | ||
} else { | ||
object[referenceKey] = { | ||
id: value | ||
}; | ||
} | ||
} | ||
@@ -525,3 +546,4 @@ } | ||
if (object[referenceKey]) { | ||
object[referenceKey] = unvisit(object[referenceKey], schema[referenceKey]); | ||
var referencedValue = unvisit(object[referenceKey], schema[referenceKey]); | ||
object[referenceKey] = referencedValue || object[referenceKey]; | ||
} | ||
@@ -679,3 +701,12 @@ }); | ||
return isImmutable$1 ? entities.getIn([schemaKey, entityOrId.toString()]) : entities[schemaKey][entityOrId]; | ||
if (isImmutable$1) { | ||
return entities.getIn([schemaKey, entityOrId.toString()]); | ||
} else if (entities[schemaKey]) { | ||
return entities[schemaKey][entityOrId]; | ||
} else { | ||
// TODO this ignores id attribute configuration | ||
return { | ||
id: entityOrId | ||
}; | ||
} | ||
}; | ||
@@ -682,0 +713,0 @@ }; |
{ | ||
"name": "@process-street/normalizr", | ||
"version": "3.3.1", | ||
"version": "3.3.4", | ||
"description": "Normalizes and denormalizes JSON according to schema for Redux and Flux applications", | ||
"bugs": { | ||
"url": "https://github.com/mavarazy/normalizr/issues" | ||
"url": "https://github.com/process-street/normalizr/issues" | ||
}, | ||
"homepage": "https://github.com/mavarazy/normalizr", | ||
"homepage": "https://github.com/process-street/normalizr", | ||
"repository": { | ||
"url": "https://github.com/mavarazy/normalizr.git", | ||
"url": "https://github.com/process-street/normalizr.git", | ||
"type": "git" | ||
@@ -49,3 +49,4 @@ }, | ||
"contributors": [ | ||
"Dan Abramov" | ||
"Dan Abramov", | ||
"Anton Oparin" | ||
], | ||
@@ -55,7 +56,9 @@ "license": "MIT", | ||
"@babel/core": "^7.3.3", | ||
"@babel/preset-env": "^7.3.1", | ||
"babel-eslint": "^10.0.1", | ||
"@babel/plugin-external-helpers": "^7.2.0", | ||
"@babel/plugin-proposal-class-properties": "^7.3.3", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.3.2", | ||
"@babel/plugin-transform-modules-commonjs": "^7.2.0", | ||
"@babel/preset-env": "^7.3.1", | ||
"@process-street/subgrade": "^1.3.7", | ||
"babel-eslint": "^10.0.1", | ||
"babel-preset-env": "^1.6.1", | ||
@@ -68,7 +71,7 @@ "coveralls": "^3.0.3", | ||
"flow-bin": "^0.65.0", | ||
"husky": "^0.14.3", | ||
"husky": "^1.3.1", | ||
"immutable": "^3.8.1", | ||
"jest": "^24.1.0", | ||
"lint-staged": "^6.1.0", | ||
"npm-run-all": "^3.1.2", | ||
"lint-staged": "^8.1.4", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^1.12.1", | ||
@@ -90,2 +93,3 @@ "rimraf": "^2.6.3", | ||
], | ||
"testEnvironment": "node", | ||
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$", | ||
@@ -92,0 +96,0 @@ "coverageThreshold": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
232462
19
6071
30
2
1