npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

composr-core

v4.0.1

Published

CompoSR core functions

Downloads

168

Readme

#CompoSR Core

NPM Version Build Status Test Coverage Code Climate Dependency status Dev Dependency Status

js-standard-style

The core package for Corbel's Composr. NPM page

Usage

npm install --save composr-core

Read:

What are Phrases or Snippets?

Setup for fetching remote data from Corbel

var composr = require('composr-core');

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.init(options)
  .then(function() {
    //Ready to go
  });

Setup with local data

var composr = require('composr-core');

//Register phrases (Returns a promise)
var phrasesLoaded = composr.Phrase.register(domain, phrases);

//Register snippets (Returns a promise)
var snippetsLoaded = composr.Snippet.register(domain, snippets);

Promise.all([phrasesLoaded, snippetsLoaded])
  .then(function(){
    //Ready to go
  });

Suscribe to log events

//Suscribe to core log events (Optional)
composr.events.on('debug', 'myProject', function(){
    console.log.apply(console, arguments);
});

composr.events.on('info', 'myProject', function(){
    console.info.apply(console, arguments);
});

composr.events.on('warn', 'myProject', function(){
    console.warn.apply(console, arguments);
});

composr.events.on('warn', 'myProject', function(){
    console.warn.apply(console, arguments);
});

Phrases execution

Standalone execution

It will use internal "mocked" req, res, next objects

var path = '/user/1231/test';
var method = 'get'; //get, post, put, delete
var params = {
  timeout: 10000
};

composr.Phrase.runByPath(domain, url, method, params, function(err, response){
   //if err, phrase missing
   //response.status, response.body
  });

Tunneling "restify" req, res, next

var path = '/user/1231/test';
var method = 'get'; //get, post, put, delete
var params = {
  req: req,
  res: res,
  timeout: 10000
};

composr.Phrase.runByPath(domain, url, method, params, function(err, response){
   //if err, phrase missing
   //response.status, response.body
  });

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.get('/user/me', function(req, res, next) {
  var params = {
    req: req,
    res: res,
    next: next,
    timeout: 10000 
  };

  var uid = req.get('User-ID')//for example

  composr.Phrase.runByPath(domain, 'userdetail/' + uid, 'get', params, 
    function(err, response){
      //Executed and already sent to client.
    });
});

Debugging phrases

When registering some phrase models, pass the url to the "code" file in order to allow vm.Script to find the reference:

phraseModel.debug = {
  'get' : '/myAbsolute/path/phrase.code.js'
};

composr.Phrase.register(phraseModel);

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