CompoSR Core
The core package for Corbel's Composr. NPM page
Usage
npm install --save composr-core
Read:
Setup for fetching remote data from Corbel
var composr = ; var options = credentials: clientId: 'demo' clientSecret: 'demo' scopes: 'demo' urlBase: 'https://remote-corbel.com' timeout: 3000; //Trigger the load of data from the "remote corbel"composr ;
Setup with local data
var composr = ; //Register phrases (Returns a promise)var phrasesLoaded = composrPhrase; //Register snippets (Returns a promise)var snippetsLoaded = composrSnippet; PromiseallphrasesLoaded snippetsLoaded ;
Suscribe to log events
//Suscribe to core log events (Optional)composrevents; composrevents; composrevents; composrevents;
Phrases execution
Standalone execution
It will use internal "mocked" req, res, next objects
var path = '/user/1231/test';var method = 'get'; //get, post, put, deletevar params = timeout: 10000; composrPhrase;
Tunneling "restify" req, res, next
var path = '/user/1231/test';var method = 'get'; //get, post, put, deletevar params = req: req res: res timeout: 10000; composrPhrase;
Phrase parameters
Using mocked handlers
You can send an object containing the request headers and other for the body.
Use params
if you don't want to extract the params from the url or if you are using composr.Phrase.runByID
var headers = 'Authorization' : 'Token'; var body = 'name' : 'test'; var params = 'user' : '123'; var query = 'foo' : 'bar'; var params = headers body query params
Using restify handlers
Whoa, just execute your dinamics endpoints.
var params = req res next
Injecting a custom corbel-js driver instance
var params = corbelDriver
Phrase execution timeout
var params = timeout: 10000 //miliseconds
Other parameters
var params = domain functionMode : false //In case you want to execute phrases inside vm contexts (memory intensive)
Restify example
router;
Debugging phrases
When registering some phrase models, pass the url to the "code" file in order to allow vm.Script
to find the reference:
phraseModeldebug = 'get' : '/myAbsolute/path/phrase.code.js'; composrPhrase;
Later on, from your project, you can launch node-inspector
debug and add breackpoints in the phrase.code.js
file.
API
composr.Phrase.validate
composr.Phrase.compile
composr.Phrase.register
composr.Phrase.unregister
composr.Phrase.runById
composr.Phrase.runByPath
composr.Phrase.getPhrases
composr.Phrase.getById
composr.Phrase.getByMatchingPath
composr.Snippet.validate
composr.Snippet.compile
composr.Snippet.register
composr.Snippet.unregister
composr.Snippet.runByName
composr.Snippet.getByName
composr.Snippet.getSnippets