A node module that implements the behaviour-driven design and map-queue algorithm
Package Exports
backend-js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (backend-js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
backend-js
Made for code generation, designed to understand user requirements.
Usually, code generators always focus on performing functions or do specific jobs based on some requirements, but they are missing the important part what if I want to continue developing what shall I do? start from the beginning that's insane! from the other side when developing code on your own from scratch you are obliged to follow a lot of standards and checklists to achieve that clean code.
That's the idea of our backend.js engine "continuing development using that generated code" by making it standardized, reusable, readable and maintainable as if you coded it by yourself.
Continuing development on same code is depending heavily on the relationship between user requirements and the code. This relation always exists in documentation or just in the developer mind. Domain Driven Design had put rules to strengthen this relationship by naming the code units based on the domain you're working on.
For example; in a banking system, the domain contains terminologies like Account, Transaction, etc... so you should use this for naming your code units (variables, classes, functions, etc... ).
And much more other practices to strengthen this relation but despite that, there is no strong relationship between user requirements and the code that is where our goal "lead to continuing" came from.
Our new pattern Behavior-first Design that is inspired by Behavior Driven Development, solves this by many ways like defining a standard interface to deal with databases regardless its type also defining a language to write the higher level logic breaking that gap between code and user requirements.
Installation
npm install backend-js
Usage
backend
var backend =require('backend-js');var App = backend.app(__dirname +'/behaviours',{path:'/api/v1',parser:'json',port:8383,origins:'*'});
var App = app(path, options)
parameter
type
description
path
string
path of behaviours directory.
options
object
app configurations object.
options.path
string
prefix path appended to the beginning of routes.
options.parser
string
if json, text, raw or urlencoded is used, the body of the request will be parse accordingly also the body of the response will be serialized accordingly.
var backend =require('backend-js');var model = backend.model();var User =model({name:'User'},{username: String,password: String
});
var ModelEntity = model(options, attributes, plugins)
parameter
type
description
options
string | object
either model name for lazy loading or object for model configuration.
options.name
string
model name.
options.features
object
object contains special functionalities of the model. It is passed to data access layer.
options.query
array
array of QueryExpression repressing the query to be executed by default.
attributes
object
object describes the model schema. it contains key-value pairs where the key is a model attribute/field name and the value is the data type of this attribute/field. Data types are native javascript data types String, Number and Date. Data type could be javascript array of single object annotation [{}] or just an object annotation {} containing other key-value pairs expressing nested model schema.
plugins
array
array of mongoose plugins to define additional functionalities to the model.
return
type
description
ModelEntity
function
model constructor function prototyped as ModelEntity.
object contains key-value pairs where the key is a unique id for an operator and the value is a corresponding database engine operator. It is passed to data access layer.
var expression = new QueryExpression(options)
parameter
type
description
options
object
object describes a condition in a where clause of a query.
options.fieldName
string
attribute/field name of the model to be part of the condition.
options.comparisonOperator
string
a value represents comparison operation to be manipulated by database engine.
options.fieldValue
any
the value to be compared to the attribute/field of the model.
options.logicalOperator
string
a value represents logical operation to be manipulated by database to combine multiple conditions.
options.contextualLevel
number
starts with 0 represents the depth of the logical operation in the conditions tree. It is used to indicate brackets.
return
type
description
expression
object
object represents a condition expression combined with other expressions to represent a query. It is adapted by data access layer..
entity
var ModelEntity = backend.ModelEntity;var entity =newModelEntity({});var model = entity.getObjectConstructor();var schema = entity.getObjectAttributes();var features = entity.getObjectFeatures();var query = entity.getObjectQuery();
var entity = new ModelEntity(features)
parameter
type
description
features
object
object contains special functionalities of the model. It is passed to data access layer.
return
type
description
entity
object
object contains all specifications and meta data of the model.
entity.getObjectConstructor
function
function returns the model constructor depending on the data access layer.
entity.getObjectAttributes
function
function returns the model schema key-value pairs.
entity.getObjectFeatures
function
function returns the model features.
entity.getObjectQuery
function
function returns the model query an array of QueryExpression to be executed by default.
api configuration (name, version, path, method, parameters, returns)
constructor
function
logic function works by registering on methods to do functions regardless its orders, like (database processor query, insert, delete or update), data mapping to map returns of data to specific format or server error handling
data access
you should define your own data access layer like following
var backend =require('backend-js');varModelController=function(){
self.removeObjects=function(queryExprs, entity, callback){// do remove};
self.newObjects=function(objsAttributes, entity, callback){// do add new};
self.getObjects=function(queryExprs, entity, callback){// do select};
self.save=function(callback, oldSession){// do select};};
ModelController.defineEntity=function(name, attributes){// define entityreturn entity;};ModelController.prototype.constructor = ModelController;
backend.setModelController(newModelController());
Starter project
A sample project that you can learn from examples how to use BackendJS.