it does some serious shit™
setup a new thumos build given options:
mongo
db info with auth if needed. see mongo connection stringspath
path: output destination for the build filespages
array: of objects specifying build pages:title
title for pageview
path: of thumos view modulesurl
path: of page destination relative to build root
paths
object: bilt path specific configs, see https://github.com/satchelspencer/bilt#configuration-optionsapp
express app: express app to build model API routes onroute
: base route for thumos (defaults to '/')auth
: authentication function used by the authentication module. called with params:cred
arbitrary credentials parameter, passed fromauth.get
callback
callback on completeion witherror, uid, [userdata]
user data will be passed as thedata
property in access query/middleware context.
view objects have the following properties:
html
: html string for dom to be inserted at renderinit(view, options)
fn: init callback called with view domview
and any options passed into the constructor
once required views return a function that must be called to initialize a new instance of the view
example definition:
define([
'css!./index.css', //css dep
], {
html : require('html!./index.html'),
init : function(options){
// setup your view
}
})
sets are a queryable, updateable collection of multiple models. they sync with the client and the server.
name
set name (usually plural of model name) used in url routingcollection
mongo collection (defaults toname
)properties
: object of properties, or validator. properties each may have the following options:optional
: true if property is not required in modelreadonly
: true if client should not be able to modify the propertyplural
: true if property should expect array- validation through set middleware. key is the middleware name, value is the function.
access
access module default access controls for entire setqueries
object of set queriesroutes
object with keys being route names and values being middleware for that route. default method isget
. more options can be included in the value with the followig format:route
path for express routemethod
http method for route get, post, etcmiddleware
express middleware function
set middleware are functions that are passed a model at various stages in thumos. middleware functions always have 3 parameters:
input
the value of a model's property (or the entire model)callback
a function with 2 argumentserror
andvalue
. error will stop the current function and if supplied, value will replace theinput
to the middlewarecontext
the unique identifier for of the acting party. derived from thumos' authentication contains the properties:uid
user's unique iddata
any data saved by the authentication module the available middleware bindings arevalid, send, store, remove
. they are called in the following order:
add/update
- client calls
set.add
orset.update
send
is called on each modelvalid
is called on each model- the browser sends the models to the server
valid
is called on each model (on the server)store
is called on each model (on the server)- the model is saved to the database
- client calls
delete
- client calls
set.delete
- request is sent to server
remove
is called on each model (on the server)- the models are removed from the database
- client calls
you may also provide typestrings string
, number
, object
, and bool
as shorthand validators. a reference to a set will validate that peoprety represents an object ID accessible by the user
thumos allows custom access control mechanisms defined by the following object:
read
: query function that is passed the id of the requester, selects models that are eligible to be accessedwrite
: same but for modifiable models
queries are defined by function that takes an object of parameters and returns a mongodb query object example:
minAge : function(age){
return {age : {$gt : age}}
}
thumos' authentication is controlled through the global module auth
with the following api:
auth.get(cred, callback)
pass credentials parameter to server side for validation defined byconfig.auth
. calls back witherror, uid
auth.revoke(callback)
revokes authentication, calls back with success statusauth.bind(callback)
add callback to authentication events, calls back with uid or nullauth.uid
property, set to authenticated id (id authenticated)
requireing a view with view!
gives you a constructor whose arguments will be passed to the view's init
. the constructor returns the dom of the view.
set.get(ids, callback)
retrieves models by id, calls back with array of modelsset.getOne(id, callback)
retrieves model by id, calls back single modelset.update(data, callback)
updates set, returns array of changed modelsset.remove(ids, callback)
removes models by id, returns list of removed idsset.insert(data, callback)
adds array of model data, calls back with added array of modelsset.find(query, callback)
gets array of models who match queryset.findOne(query, callback)
gets first model that matches query
browser only methods
set.load(ids, callback)
ignores cache and retrieves models from serverset.group(options_or_query)
creates a group object for all models matching providedquery
or options:query
query object to define groupinclude : function(model, callback)
optional function to modify model to be included in groupexclude : function(model, callback)
optional function to modify model to be excluded from group
set.subset(ids)
creates a subset object for the models inids
-
group.get(ids, callback)
same asset.get
but models must be in group -
group.getOne(id, callback)
get a single model in the group -
group.load(ids, callback)
load models in group from server -
group.find(query, callback)
query for models in group -
group.findOne(query, callback)
calls back with first model in group that matches query -
group.insert(models, callback)
include function required inserts models, and makes sure they are included in group -
group.update(models, callback)
same asset.update
but models must be in group. update can exclude models from group -
group.include(models, callback)
include function required updates provided models to ensure they are in group. -
group.exclude(models, callback)
exclude function required updates provided models to ensure they are no longer in group. -
group.group(options)
creates a subgroup (with group api) that conforms to current group and its own querys. subgroups:- only contain models that are in their parent groups
- include (or insert) includes the model in subgroup and all parent groups
- exclude from group does not exclude it from any parent or subgroups (for now)
- removal from a parent group implies removal from all subgroups
-
group.bind(options)
updates groupquery, include and exclude
using the same constructor and retriggering events as needed -
group.order(predicate, reverse)
set the ordering function of the set. predicate may be a function that takes in a model and returs the value to be sorted from, or a string naming the property to be sorted on. reverse (optional) reverses the sort order. Calls toinclude
andupdate
events have a second parameter (the index in the sorted order) -
group.on(event, callback)
add a listener for one of the following events:include
when a new model enters the groupexclude
when a model leaves the group calls back with ID onlyupdate
when a model in the group changes valuechange
calls back with full list of models on any change
-
group.off(event)
disable callbacks for event -
underscore funtions
(collection functions excludingfind
only) proxy to their underscore equivalents. a call to one of these functions returns a function to which you may pass a callback to catch the return value of the underscore function (if any). see example:mygroup.pluck('name')(function(names){ console.log(names) });
subset.bind(ids)
updates subset to be equal to the provided idssubset.include(ids, callback)
adds models to subsetsubset.exclude(ids, callback)
removes models from subsetsubset.insert(models, callback)
inserts models into set then appends them to the subsetsubset.on(event, callback)
add a listener for one of the following events:include
when a new model enters the subsetexclude
when a model leaves the subset calls back with ID onlyupdate
when a model in the subset changes valuechange
calls back with full list of models in subset
subset.off(event)
disable callbacks for eventsubset.prop(propName, callback)
add a listener for changed properties within the group. calls back with paremeterscallback(propValue, whichModel)
where propValue is the value, and whichModel is the id of the model in question- same underscore functions as a group
css!
client side only: parses with less, minifies and appends css to pagedatauri!
uses datauri, defines as string of dataurifile!
includes a copy of the file (or directory) in the build directoryhtml!
minifies and includes html file. accessible as jquery elementset!
includes a set definition, handles server side setup and gives youset api
text!
includes a file as a utf-8 stringview!
includes a view definition, providesview api
browserify!
includes a file and its dependencies using browserify!
- async async control flow
- autoprefixer handles browser prefixes at build time
- bcrypt password hash
- bilt module loader
- browserify commonjs module loader bult tool
- cheerio server side dom management
- crc-32 crc32 checksumming for detecting when to fire
change
events - csso css optimizer
- datauri get data uri from file
- derequire sanitize require calls
- express server side routing goodness
- fs-extra extended node file library
- get-installed-path finds path of npm package
- html-minifier self-explanatory
- jquery
- less css extention
- memcached memcached for node
- mongo-parse test mongodb querys in javascript
- mongojs mongo api in node
- postcss css processor
- sqwish css compressor
- through transformation streams
- underscore functional javascript shit