New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

kamboja

Package Overview
Dependencies
Maintainers
1
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kamboja

MVC Framework powered by TypeScript

  • 0.0.1-1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

KambojaJs

Build Status Coverage Status

NodeJS MVC Framework powered by TypeScript

API Convention

You don't need to decorate your classes or method to get clean API below:

GET    /user/page/<offset>/<take>
GET    /user/<id>
POST   /user  
       {<payload body>}
PUT    /user/<id>
       {<payload body>}
DELETE /user/<id>

what you need todo is:

export class UserController : ApiController{
    getByPage(offset, page){ /* your code */ }
    get(id){ /* your code */ }
    add(body){ /* your code */ }
    modify(id, body){ /* your code */ }
    delete(id){ /* your code */ }
}

Remember you are free to name your parameter KambojaJs will detect it for you.

Default Convention

For non API controller your method name will be the route

export class CarController : Controller{
    getList(index, take){
        return this.view()
    }
}

With code above KambojaJs will generate

GET /car/getlist/:index/:take

Http Decorator

By default all action will be translated as HTTP GET, if you need other method you need to add decorators

export class CarController : Controller{
    @http.post()
    save(body){
        return this.json({success:true})
    }
}

Code above will generate

POST /car/save
     {<payload body>}

If you not happy with the generated route or you want a custom route you can provide parameter on the http decorator

export class CarController : Controller{
    @http.post("/garage/save")
    save(body){
        return this.json({success:true})
    }
}

Code above will generate

POST /garage/save
     {<payload body>}

You are free to assigned multiple http decorators into an action, this behavior will make the action accessible from many routes.

export class CarController : Controller{
    @http.post("/dashboard")
    @http.post("/dashboard/property")
    @http.post("/dashboard/property/car")
    @http.post("/dashboard/property/car/list")
    list(){
        return this.json({success:true})
    }
}

Internal Decorator

TypeScript's generated javascript doesn't leave information about private method so KambojaJs will guess all of your method as public. You can mark a method as @internal if you want KambojaJs exclude the method from route generation.

export class CarController : Controller{
    @internal()
    private thisIsPrivate(){
        return "sssttt.."
    }

    list(){
        return this.json(this.thisIsPrivate())
    }
}

Async/Await support

With TypeScript 2.1 support async/await on ES5, we can use it also inside the controller

export class CarController : Controller{
    @internal()
    private slowLoadingAsync(): Promise<string>{ }

    async list(){
        let result = await this.slowLoadingAsync()
        return this.json(result)
    }
}

Error handling using try-catch

Another TypeScript 2.1 feature we also can do try-catch error inside controller. The error will nicely passed through the error handler.

export class CarController : Controller{
    async list(){
        try{
            let result = await this.slowLoadingAsync()
            return this.json(result)
        }
        catch(e){
            throw new Error("Something bad happened")
        }
    }
}

Flexible Engine

KambojaJs not totally created from scratch instead it designed so it can sits on top of another framework such as ExpressJs(implemented), Koa(in progress). This is good so we can reuse any great existing library like BodyParser and some middleware

Smart Analysis

KambojaJs comes with smart analytic engine, it will identify common mistakes that hard to trace.

  • Detect non exported controller
  • Detect if there is controller not inherited from ApiController or Controller
  • Detect if @internal decorator combined with @http.() decorator
  • Detect if an Api Naming convention in an action fail caused by lack of parameters
  • Detect un match parameter between route and action when using custom route
  • Detect if Controller method accidentally overridden such as json, redirect, file, view
  • Detect if there are duplicate route happened.

FAQs

Package last updated on 03 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc