Comparing version 1.0.7 to 1.0.8
{ | ||
"name": "manyfest", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "JSON Object Manifest for Data Description and Parsing", | ||
@@ -5,0 +5,0 @@ "main": "source/Manyfest.js", |
@@ -6,6 +6,9 @@ /** | ||
let libSimpleLog = require('./Manyfest-LogToConsole.js'); | ||
let libHashTranslation = require('./Manyfest-HashTranslation.js'); | ||
let libObjectAddressResolver = require('./Manyfest-ObjectAddressResolver.js'); | ||
let libHashTranslation = require('./Manyfest-HashTranslation.js'); | ||
let libObjectAddressGeneration = require('./Manyfest-ObjectAddressGeneration.js'); | ||
let libSchemaManipulation = require('./Manyfest-SchemaManipulation.js'); | ||
/** | ||
@@ -58,2 +61,3 @@ * Manyfest object address-based descriptions and manipulations. | ||
this.schemaManipulations = new libSchemaManipulation(this.logInfo, this.logError); | ||
this.objectAddressGeneration = new libObjectAddressGeneration(this.logInfo, this.logError); | ||
@@ -261,3 +265,11 @@ this.hashTranslations = new libHashTranslation(this.logInfo, this.logError); | ||
{ | ||
return this.getValueAtAddress(pObject, this.resolveHashAddress(pHash)); | ||
let tmpValue = this.getValueAtAddress(pObject, this.resolveHashAddress(pHash)); | ||
if (typeof(tmpValue) == 'undefined') | ||
{ | ||
// Try to get a default if it exists | ||
tmpValue = this.getDefaultValue(this.getDescriptorByHash(pHash)); | ||
} | ||
return tmpValue; | ||
} | ||
@@ -268,3 +280,11 @@ | ||
{ | ||
return this.objectAddressResolver.getValueAtAddress(pObject, pAddress); | ||
let tmpValue = this.objectAddressResolver.getValueAtAddress(pObject, pAddress); | ||
if (typeof(tmpValue) == 'undefined') | ||
{ | ||
// Try to get a default if it exists | ||
tmpValue = this.getDefaultValue(this.getDescriptor(pAddress)); | ||
} | ||
return tmpValue; | ||
} | ||
@@ -311,5 +331,6 @@ | ||
let tmpDescriptor = this.getDescriptor(this.elementAddresses[i]); | ||
let tmpValueExists = this.checkAddressExists(pObject, tmpDescriptor.Address); | ||
let tmpValue = this.getValueAtAddress(pObject, tmpDescriptor.Address); | ||
if (typeof(tmpValue) == 'undefined') | ||
if ((typeof(tmpValue) == 'undefined') || !tmpValueExists) | ||
{ | ||
@@ -393,2 +414,7 @@ // This will technically mean that `Object.Some.Value = undefined` will end up showing as "missing" | ||
{ | ||
if (typeof(pDescriptor) != 'object') | ||
{ | ||
return undefined; | ||
} | ||
if (pDescriptor.hasOwnProperty('Default')) | ||
@@ -395,0 +421,0 @@ { |
@@ -60,3 +60,3 @@ /** | ||
( | ||
'Exercise more hash accesss scenarios..', | ||
'Return default values when none are supplied.', | ||
(fTestComplete)=> | ||
@@ -83,3 +83,4 @@ { | ||
"Hash":"ComfET", | ||
"Description":"The most comfortable temperature for this animal to survive in." | ||
"Description":"The most comfortable temperature for this animal to survive in.", | ||
"Default": "96.8" | ||
} | ||
@@ -89,5 +90,10 @@ } | ||
Expect(animalManyfest.getValueByHash({MedicalStats: { Temps: { CET:200 }},Name:'Froggy'}, 'ComfET')) | ||
.to.equal(200); | ||
Expect(animalManyfest.getValueByHash({MedicalStats: { Temps: { CET:200 }},Name:'Froggy'}, 'ComfET')).to.equal(200); | ||
Expect(animalManyfest.getValueByHash({MedicalStats: { Temps: { MinET:200 }},Name:'Froggy'}, 'ComfET')).to.equal('96.8'); | ||
Expect(animalManyfest.getValueByHash({MedicalStats: { Temps: { MinET:200 }},Name:'Froggy'}, 'CurrentTemperature')).to.equal(undefined); | ||
Expect(animalManyfest.getValueAtAddress({MedicalStats: { Temps: { CET:200 }},Name:'Froggy'}, 'MedicalStats.Temps.CET')).to.equal(200); | ||
Expect(animalManyfest.getValueAtAddress({MedicalStats: { Temps: { MinET:200 }},Name:'Froggy'}, 'MedicalStats.Temps.CET')).to.equal('96.8'); | ||
Expect(animalManyfest.getValueAtAddress({MedicalStats: { Temps: { MinET:200 }},Name:'Froggy'}, 'MedicalStats.Temps.HighET')).to.equal(undefined); | ||
fTestComplete(); | ||
@@ -94,0 +100,0 @@ } |
@@ -200,2 +200,48 @@ /** | ||
); | ||
test | ||
( | ||
'Schema definition prototypes should be able to be generated from any JSON object shape.', | ||
(fTestComplete)=> | ||
{ | ||
let tmpSchemaDescriptors = ( | ||
{ | ||
"a": { "Hash": "a", "Type": "Number" }, | ||
"b": { "Hash": "b", "Type": "Number" }, | ||
"TranslationTable": | ||
{ | ||
"a": "CarrotCost", | ||
"b": "AppleCost" | ||
} | ||
}); | ||
let _Manyfest = new libManyfest(); | ||
// Now remap the schema (in-place) | ||
let tmpSchemaPrototype = _Manyfest.objectAddressGeneration.generateAddressses(tmpSchemaDescriptors); | ||
// The schema should be fundamentally altered to point these addresses to the old hashes | ||
Expect(tmpSchemaPrototype).to.be.an('object'); | ||
Expect(tmpSchemaPrototype['TranslationTable.a'].DataType).to.equal('String'); | ||
fTestComplete(); | ||
} | ||
); | ||
test | ||
( | ||
'Make a much bigger schema prototype.', | ||
(fTestComplete)=> | ||
{ | ||
let _Manyfest = new libManyfest(); | ||
// Now remap the schema (in-place) | ||
let tmpSchemaPrototype = _Manyfest.objectAddressGeneration.generateAddressses(_SampleDataArchiveOrgFrankenberry); | ||
// The schema should be fundamentally altered to point these addresses to the old hashes | ||
Expect(tmpSchemaPrototype).to.be.an('object'); | ||
Expect(tmpSchemaPrototype['files_count'].Default).to.equal(17); | ||
Expect(tmpSchemaPrototype['files_count'].DataType).to.equal('Number'); | ||
fTestComplete(); | ||
} | ||
); | ||
} | ||
@@ -202,0 +248,0 @@ ); |
Sorry, the diff of this file is not supported yet
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
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
241103
42
3986