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

braph

v0.0.3-alpha

Published

The official NodeJS client for Braph

Downloads

3

Readme

node-braph

The NodeJS client for Braph. With this module you can create and save your back-end entities on an on-line braph, it's intended to be used with ES6. Take this as a database as a service empowered with a braph capabilities.

Install with:

npm install braph

Usage example

You need to create an account on Braph, currently on experimental stage, then create a braph and get the credentials along with the id. After that, you will be able to create instances from your back-end project as follows:

Braph.js

var Braph  = require('braph').Braph;

module.exports.Braph = new Braph({
  id : 'braph_id',
  client_id : 'client_id',
  client_secret : 'client_secret',
  api_url : 'https://api.braph.com/alpha/v1'
});

models/Post.js


var Instance    = require('braph').Instance;
var Braph       = require("./../Braph");

class Post extends Instance {

    constructor(data){
        super();
        this.title = data.title;
        this.content = data.content;
        this.date = data.date;
    }

}

// Required
Post.braph = Braph;

// Optional
Post.schema = {
    title : 'string',
    content : 'string',
    date :  'date'
}

module.exports = Post;

The properties that will be associated with this Instance are the ones that will be returned with the Object.getOwnPropertyNames method such as title or date in the example.

If you are used to work with getters as the property name using inner properties named as _title or _date then you have to implement the getProperties() method else you will have objects with properties named as the inner ones.

var Instance    = require('braph').Instance;
var Braph       = require("./../Braph");

class Post extends Instance {

    constructor() {
        super();
    }

    // Getters and setters.

    get name(){
        return this._name;
    }

    set name(value){
        this._name = value;
    }

    get date(){
        return this._date;
    }

    set date(value){
        this._date = value;
    }

    // getProperties() implementation

    getProperties() {
        return {
            name : this.name,
            date : this.date
        }
    }
}

// Required
Post.braph = Braph;

// Optional
Post.schema = {
    title : 'string',
    content : 'string',
    date :  'date'
}

module.exports = Post;

Now you are able to work with instances of this Post pre-configured class and save or query them on Braph as follows:

Create instances


var Post = require('./models/Post.js');

var post = new Post({
    title : 'hello world',
    content : 'again',
    date : new Date()
});

post.save(function(err){
    //...
});

List instances


var Post = require('./models/Post.js');

var page = 1;
var itemsPerPage = 10;

Post.list(page, itemsPerPage, function(err, posts){
    //...
});

Read instances


var Post = require('./models/Post.js');

var post_id = 25;

Post.read(post_id, function(err, post){
    //...
});

Controllers and Middlewares

The NodeJS client for Braph provide you with the option to implement direct controllers and Braph scoped authentication to your API. It's really helpful when you want to avoid coding that controller layer that many times follows the same CRUD pattern.

To implement the B_Auth_Token you need to use a Login with Braph flow in your application where the Authentication middleware is required.


var express = require('express');
var cors = require('cors');

var Braph = require('./../Braph');
var Post = require("./../models/Post"); 

const cors_options = {
	origin: new RegExp(/(project\.com)$/)
};

var v1 = express.Router();

module.exports = function (server) {

	server.use(cors(cors_options));

	server.options('*', cors(cors_options))

	v1.post('/auth/login',	Braph.Authentication.login);

	v1.post("/posts",       Braph.Middleware.B_Auth_Token, Post.Controller.create.bind(Post.Controller));

	v1.get("/posts",        Post.Controller.list.bind(Post.Controller));

	v1.get("/posts/:id",	Post.Controller.read.bind(Post.Controller));

	server.use('/v1', v1);

	return server;

}

NOTE : This module was created with the npm-module-boilerplate.