The big picture - kristianmandrup/racer-mw GitHub Wiki
The middleware project contains the main base classes for BaseMw and BaseRunner. It also contains the Middleware factory class to help assemple a full pipeline with runner and Mw-components. You should start here to get the "big picture".
A Runner can run one or more Mw-components in a "pipeline" (chain). The result of each Mw-component that has been run is stored by the Runner in a results object. Each Mw-component thus has access to results of previous Mw-components that have been run in the same pipeline. Each Mw-component also has the option to report errors or abort further execution.
Now look at the model-mw project. It contains a ModelMw and ModelRunner, the base classes for all the other Mw-components (such as AuthorizeMw). These base classes provide the basic "model functionality" for the middleware.
Example middleware config:
model-middleware = new Middleware('model', data: person).use(authorizer).use(validator)
model-middleware.run!
ModelRunner ('model') should be used to run validation-mw on the data object: person The following is also valid (for reuse of same middleware with new/different data): model-middleware.run person
You can thus combine or create your own ModelMw components and insert them into the pipeline as you like. This infrastructure is intended for use with Racer (and Derby)
Check here https://github.com/kristianmandrup/racer-mw/blob/master/lib/crud/
Example: https://github.com/kristianmandrup/racer-mw/blob/master/lib/crud/crud_set.ls
Which extends https://github.com/kristianmandrup/racer-mw/blob/master/lib/crud/racer_sync.ls
CrudSet = ...
mw-stack: ->
@create-stack 'authorize-mw', 'validate-mw', 'marshal-mw', 'racer-mw'
one: ->
@perform 'set', @item
Notice the mw-stack. Each Crud function has its own pipeline. For Create/Update (Set) operations it makes sense to validate, but not for Delete f.ex
Check @perform
method in RacerSync and follow the rabbit down the hole... this is where the real "magic" is
It should end up working something like this: https://github.com/kristianmandrup/racer-mw/blob/master/test/racer-mw/crud_test.ls
crud = (collection) ->
new Crud collection
crud('users').get(id).one
users = crud('users')
users.get().one(id)
users.get().by(name: name).first
users.get().by(name: name).all
users.set().one(id, name: name)
users.set().many(persons)
Then the next step would be to encapsulate this Crud API in a nice Resource API, similar to Angular $resource
f.ex:
class models.Person extends Resource {
}
# Perhaps sth like this
person = new models.Person
person.get-by(name: name)
person.set(name: new-name)
person.delete()
Of course you should be able to do various customisations, like configuring the path for the collection of documents etc. Also enable subscribing event listeners for changes. But much of the underlying infra is mostly ready now...
Hope that helps. Would love some assistance on the documentation too ;) Cheers!