@f5devcentral/f5-fast-core
Advanced tools
Comparing version 0.5.1 to 0.6.0
@@ -0,1 +1,17 @@ | ||
# v0.6.0 | ||
## Added | ||
* Expose Template mergeStrategies in index.js | ||
* Cache GET requests to AS3 declare endpoint | ||
* Add "responses" information from AS3 tasks to FAST tasks | ||
* Add operation information (e.g., update vs delete) to FAST tasks | ||
* Merge definitions and default parameters from base templates | ||
* Save additional, top-level properties found on YAML templates | ||
## Fixed | ||
* Missing type schema when merging templates | ||
## Changed | ||
* Move empty-string checks out of template merge strategies | ||
* Remove AS3Driver | ||
# v0.5.1 | ||
@@ -2,0 +18,0 @@ ## Fixed |
@@ -7,5 +7,4 @@ 'use strict'; | ||
const { FsTemplateProvider, DataStoreTemplateProvider } = require('./lib/template_provider'); | ||
const Template = require('./lib/template').Template; | ||
const { Template, mergeStrategies } = require('./lib/template'); | ||
const httpUtils = require('./lib/http_utils'); | ||
const { NullDriver, AS3Driver, AS3DriverConstantsKey } = require('./lib/drivers'); | ||
const guiUtils = require('./lib/gui_utils'); | ||
@@ -19,6 +18,4 @@ const TransactionLogger = require('./lib/transaction_logger'); | ||
Template, | ||
mergeStrategies, | ||
httpUtils, | ||
NullDriver, | ||
AS3Driver, | ||
AS3DriverConstantsKey, | ||
guiUtils, | ||
@@ -25,0 +22,0 @@ dataStores, |
@@ -54,10 +54,2 @@ 'use strict'; | ||
function PlainTextMergeStrategy(acc, curr) { | ||
if (curr.length === 0) { | ||
return acc; | ||
} | ||
if (acc.length === 0) { | ||
return curr; | ||
} | ||
return `${acc}\n${curr}`; | ||
@@ -67,13 +59,5 @@ } | ||
function JsonMergeStrategy(acc, curr) { | ||
if (curr.length === 0) { | ||
return acc; | ||
} | ||
if (acc.length === 0) { | ||
return curr; | ||
} | ||
return JSON.stringify(deepmerge( | ||
JSON.parse(acc), | ||
JSON.parse(curr) | ||
yaml.safeLoad(acc), | ||
yaml.safeLoad(curr) | ||
), null, 2); | ||
@@ -386,2 +370,10 @@ } | ||
_parametersSchemaFromTemplate(typeSchemas) { | ||
['oneOf', 'allOf', 'anyOf'].forEach((xOf) => { | ||
this[`_${xOf}`].forEach((tmpl) => { | ||
this.definitions = deepmerge( | ||
this.definitions, | ||
tmpl.definitions | ||
); | ||
}); | ||
}); | ||
Object.entries(this.definitions).forEach(([name, def]) => { | ||
@@ -471,9 +463,11 @@ if (def.template) { | ||
tmpl._recordSource('YAML', yamltext); | ||
tmpl.templateText = yamldata.template; | ||
if (yamldata.title) tmpl.title = yamldata.title; | ||
if (yamldata.description) tmpl.description = yamldata.description; | ||
if (yamldata.definitions) tmpl.definitions = yamldata.definitions; | ||
if (yamldata.parameters) tmpl.defaultParameters = yamldata.parameters; | ||
if (yamldata.contentType) tmpl.contentType = yamldata.contentType; | ||
Object.assign(tmpl, yamldata); | ||
tmpl.templateText = tmpl.template || tmpl.templateText; | ||
delete tmpl.template; | ||
tmpl.defaultParameters = tmpl.parameters || tmpl.defaultParameters; | ||
delete tmpl.parameters; | ||
delete tmpl.anyOf; | ||
delete tmpl.oneOf; | ||
delete tmpl.anyOf; | ||
@@ -497,5 +491,4 @@ const oneOf = yamldata.oneOf || []; | ||
return Promise.all([ | ||
tmpl._loadTypeSchemas(schemaProvider), | ||
Promise.resolve() | ||
return Promise.resolve() | ||
.then(() => Promise.resolve() | ||
.then(() => { | ||
@@ -520,20 +513,19 @@ if (rootDir) { | ||
`Parsing references failed:\n${e.stack}` | ||
))) | ||
]) | ||
.then(([typeSchemas, bundled]) => { | ||
tmpl.definitions = bundled.definitions || tmpl.definitions; | ||
tmpl._parametersSchemaFromTemplate(typeSchemas); | ||
}) | ||
.then(() => Promise.all(oneOf.map(x => Template.loadYaml(JSON.stringify(x))))) | ||
)))) | ||
.then(() => Promise.all(oneOf.map(x => Template.loadYaml(JSON.stringify(x), schemaProvider)))) | ||
.then((tmplList) => { | ||
tmpl._oneOf = tmplList; | ||
}) | ||
.then(() => Promise.all(allOf.map(x => Template.loadYaml(JSON.stringify(x))))) | ||
.then(() => Promise.all(allOf.map(x => Template.loadYaml(JSON.stringify(x), schemaProvider)))) | ||
.then((tmplList) => { | ||
tmpl._allOf = tmplList; | ||
}) | ||
.then(() => Promise.all(anyOf.map(x => Template.loadYaml(JSON.stringify(x))))) | ||
.then(() => Promise.all(anyOf.map(x => Template.loadYaml(JSON.stringify(x), schemaProvider)))) | ||
.then((tmplList) => { | ||
tmpl._anyOf = tmplList; | ||
}) | ||
.then(() => tmpl._loadTypeSchemas(schemaProvider)) | ||
.then((typeSchemas) => { | ||
tmpl._parametersSchemaFromTemplate(typeSchemas); | ||
}) | ||
.then(() => tmpl._createParametersValidator()) | ||
@@ -550,11 +542,11 @@ .then(() => tmpl); | ||
return Promise.resolve() | ||
.then(() => Promise.all(tmpl._oneOf.map(x => Template.loadYaml(JSON.stringify(x))))) | ||
.then(() => Promise.all(tmpl._oneOf.map(x => Template.fromJson(x)))) | ||
.then((tmplList) => { | ||
tmpl._oneOf = tmplList; | ||
}) | ||
.then(() => Promise.all(tmpl._allOf.map(x => Template.loadYaml(JSON.stringify(x))))) | ||
.then(() => Promise.all(tmpl._allOf.map(x => Template.fromJson(x)))) | ||
.then((tmplList) => { | ||
tmpl._allOf = tmplList; | ||
}) | ||
.then(() => Promise.all(tmpl._anyOf.map(x => Template.loadYaml(JSON.stringify(x))))) | ||
.then(() => Promise.all(tmpl._anyOf.map(x => Template.fromJson(x)))) | ||
.then((tmplList) => { | ||
@@ -607,3 +599,13 @@ tmpl._anyOf = tmplList; | ||
}, {}); | ||
return Object.assign({}, typeDefaults || {}, this.defaultParameters, parameters || {}); | ||
let mergedDefaults = {}; | ||
['oneOf', 'allOf', 'anyOf'].forEach((xOf) => { | ||
this[`_${xOf}`].forEach((tmpl) => { | ||
mergedDefaults = deepmerge( | ||
mergedDefaults, | ||
tmpl.defaultParameters | ||
); | ||
}); | ||
}); | ||
return Object.assign({}, typeDefaults || {}, mergedDefaults, this.defaultParameters, parameters || {}); | ||
} | ||
@@ -661,10 +663,10 @@ | ||
const mergeStrategy = mergeStrategies[this.contentType] || PlainTextMergeStrategy; | ||
let result = ''; | ||
const templateTexts = []; | ||
this._allOf.forEach((tmpl) => { | ||
result = mergeStrategy(result, tmpl.render(parameters)); | ||
templateTexts.push(tmpl.render(parameters)); | ||
}); | ||
this._anyOf.forEach((tmpl) => { | ||
try { | ||
result = mergeStrategy(result, tmpl.render(parameters)); | ||
templateTexts.push(tmpl.render(parameters)); | ||
} catch (e) { | ||
@@ -678,3 +680,3 @@ if (!e.message.match(/failed validation/)) { | ||
try { | ||
result = mergeStrategy(result, tmpl.render(parameters)); | ||
templateTexts.push(tmpl.render(parameters)); | ||
} catch (e) { | ||
@@ -686,5 +688,17 @@ if (!e.message.match(/failed validation/)) { | ||
}); | ||
result = mergeStrategy(result, Mustache.render(templateText, xfparams, partials)); | ||
return result; | ||
templateTexts.push(Mustache.render(templateText, xfparams, partials)); | ||
return templateTexts.reduce((acc, curr) => { | ||
if (curr.length === 0) { | ||
return acc; | ||
} | ||
if (acc.length === 0) { | ||
return curr; | ||
} | ||
acc = mergeStrategy(acc, curr); | ||
return acc; | ||
}); | ||
} | ||
@@ -691,0 +705,0 @@ } |
{ | ||
"name": "@f5devcentral/f5-fast-core", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"author": "F5 Networks", | ||
@@ -30,4 +30,4 @@ "license": "Apache-2.0", | ||
"nock": "^12.0.3", | ||
"nyc": "^15.0.1", | ||
"pkg": "^4.4.8" | ||
"nyc": "^15.1.0", | ||
"pkg": "^4.4.9" | ||
}, | ||
@@ -53,6 +53,6 @@ "eslintConfig": { | ||
"dependencies": { | ||
"@apidevtools/json-schema-ref-parser": "^9.0.1", | ||
"@apidevtools/json-schema-ref-parser": "^9.0.3", | ||
"@f5devcentral/atg-storage": "^0.1.0", | ||
"ajv": "^6.12.2", | ||
"archiver": "^4.0.1", | ||
"ajv": "^6.12.3", | ||
"archiver": "^4.0.2", | ||
"deepmerge": "^4.2.2", | ||
@@ -62,4 +62,4 @@ "js-yaml": "^3.14.0", | ||
"uuid": "^7.0.3", | ||
"yargs": "^15.3.1" | ||
"yargs": "^15.4.1" | ||
} | ||
} |
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
317993
17
1597
Updatedajv@^6.12.3
Updatedarchiver@^4.0.2
Updatedyargs@^15.4.1