Comparing version 1.3.0 to 1.4.0
{ | ||
"name": "yukon", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Self-discovering API-driven web components", | ||
@@ -5,0 +5,0 @@ "main": "yukon.js", |
@@ -8,2 +8,6 @@ # yukon API framework | ||
Note: The API behavior of yukon can be overriden by specifying your own config.middlewares.getData function. See Config section below for more details. | ||
__TODO: I'm working on making yukon data source agnostic and splitting off the API stuff into a plugin. In that way yukon can support any type or amount of eithr plugin or one-off data-gathering middleware. ETA: Jan 13th, 2015__ | ||
A really simple yukon component looks like this: | ||
@@ -10,0 +14,0 @@ ```js |
86
yukon.js
@@ -11,3 +11,10 @@ // add yukon default config to nodulejs default config | ||
debug('initializing'); | ||
yukonConfig.pluginMiddlewares = []; | ||
yukonConfig.dataSourcePlugins.forEach(function(pluginName) { | ||
usePlugin(pluginName); | ||
}); | ||
var getDataMiddleware = config.middlewares.getData || require('./middlewares/getDataParallel')(yukonConfig); | ||
// array of middleware functions to be executed on each request | ||
@@ -23,5 +30,3 @@ // splicing app-defined middleware in-between yukon system middlware | ||
// user can specify a different kind of data gathering | ||
// TODO: use doApi by default until that is split off into a plugin | ||
config.middlewares.getData || require('./middlewares/doApi')(app, yukonConfig), | ||
getDataMiddleware, // can be app-defined or use yukon parallel plugin caller by default | ||
@@ -39,2 +44,12 @@ config.middlewares.postData, // app-defined | ||
nodulejs(app, yukonConfig); | ||
return { | ||
usePlugin: usePlugin | ||
}; | ||
function usePlugin(pluginName) { | ||
var plugin = require('./plugins/' + pluginName)(app, yukonConfig); | ||
yukonConfig = plugin.mergedConfig; | ||
yukonConfig.pluginMiddlewares.push(plugin.middleware); | ||
} | ||
}; | ||
@@ -47,4 +62,8 @@ | ||
var defaultConfig = { | ||
// override in app config to use different data sources, parallel API by default | ||
dataSourcePlugins: ['parallel-api'], | ||
///////////////////////////////////////////////////////////////// | ||
/// APP-DEFINED EXPRESS MIDDLEWARE FUNCTIONS INVOKED BY YUKON /// | ||
/// OPTIONAL APP-DEFINED EXPRESS MIDDLEWARE FUNCTIONS /// | ||
///////////////////////////////////////////////////////////////// | ||
@@ -57,7 +76,6 @@ middlewares: { | ||
preData: passThrough, | ||
// middleware that gets all data (default = doApi, but can be replaced with app-defined data gathering) | ||
// TODO: split this off as a plugin for calling apis in parallel | ||
getData: null, | ||
// calls all dataSourcePlugins middleware in parallel, can be overridden for custom behavior | ||
getData: null, // (defined above) | ||
// called after API call(s), before nodule.postProcessor | ||
@@ -70,14 +88,2 @@ postData: passThrough, | ||
/////////////////////////////////////////////////// | ||
/// FUNCTIONS INVOKED PRE AND POST API BY YUKON /// | ||
/////////////////////////////////////////////////// | ||
// (OPTIONAL) synchronous function called at the start of every api call | ||
apiCallBefore: function(callArgs, req, res) { }, | ||
// (OPTIONAL) asynchronous function called after every api call | ||
// NOTE: must execute next() if defined | ||
apiCallback: function(callArgs, req, res, next) { next(callArgs.apiError); }, | ||
// default debug function | ||
@@ -122,41 +128,3 @@ customDebug: function(identifier) { | ||
error: null, | ||
// array of apiCalls to call in parallel | ||
// NOTE: global or semi-global calls like getProfile, getGlobalNav, etc. can be added to this array in the preData middleware | ||
apiCalls: [], | ||
}, | ||
/// API CALL PROPERTIES //////////////////////////////////////////////////////////////// | ||
/// there can be multiple api calls per nodule, all called in parallel | ||
apiDefaults: { | ||
// path to server, can be used to over-ride default | ||
host: null, | ||
// MAGIC ALERT: if api path ends with a slash(/), the framework automatically tries to append req.params.id from the express :id wildcard | ||
// as this is a very common REST paradigm | ||
path: null, | ||
// params to send to API server | ||
// if verb is 'post', this can be a deep json object (bodyType=json) or a shallow object of name value pairs (bodyType=form) | ||
params: {}, | ||
// valid values: get, post, put, del (express uses 'del' since delete is a reserved word) | ||
verb: 'get', | ||
// valid values: json, form | ||
bodyType: 'json', | ||
// custom headers to sent to API | ||
customHeaders: [], | ||
// (numeric) - max API return time in ms | ||
timeout: null, | ||
// set true to force api to use stub (IE - if API isn't ready yet) | ||
useStub: false, | ||
// can contain path or just name if in same folder | ||
// MAGIC ALERT: if not specified, app looks for [nodule name].stub.json in nodule folder | ||
stubPath: null, | ||
}, | ||
}; |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
57618
17
512
331
2
1