This package has been deprecated

Author message:

Leverage has moved to @leverage/core!

leverage-js

1.3.1 • Public • Published

What is it?

👩‍💻 A super fast, super customizable library to orchestrate your next application.

What can you use it for?

  • A HTTP server
  • A chat bot
  • A realtime websocket server
  • An IRC server
  • A MIDI interface
  • 👩💭 Anything else you can imagine!

Install it

npm i -S leverage-js

Hello World

For a "Hello World", we'll create a simple http server that responds to requests with a "Hello World".

First, install the HTTP plugin:

npm i -S leverage-plugin-http

Now, we will write an HTTP component and load our component and the HTTP plugin:

import { manager, Component } from 'leverage-js'
import http from 'leverage-plugin-http'
 
const component = Component.of({
    config: {
        type: 'http',
        http: {
            path: '*',
            method: 'get'
        }
    },
    http (request, response) {
        response.send('Hello World')
    }
})
 
manager.add(component, http)
 
http.listen(3000)

Run the above and head over to localhost:3000 to see it in action!

Documentation and Tutorials

Please see the project's wiki 🚀.

API

Leverage.createComponent()

This is an alias for Component.of and allows you to create a component instance by passing this method a component definition.

Example:

import { createComponent } from 'leverage-js'
 
const component = createComponent({
    config: {
        type: 'http'
    }
})

Leverage.createMiddleware()

This is an alias for Middleware.of and allows you to create a middleware instance by passing this method a middleware definition.

Example:

import { createMiddleware } from 'leverage-js'
 
const middleware = createMiddleware({
    config: {
        type: 'http'
    }
})

Leverage.createService()

This is an alias for Service.of and allows you to create a service instance by passing this method a service definition.

Example:

import { createService } from 'leverage-js'
 
const service = createService({
    config: {
        type: 'http'
    }
})

Leverage.createPlugin()

This is an alias for Plugin.of and allows you to create a plugin instance by passing this method a plugin definition.

Example:

import { createPlugin } from 'leverage-js'
 
const plugin = createPlugin({
    config: {
        type: 'http'
    }
})

Leverage.Component

The Component class lets you create your own components. You can extend it using the class syntax or use Component.of to extend using a normal object.

Example (with class syntax):

import { Component } from 'leverage-js'
 
class MyComponent extends Component {
    constructor () {
        super()
 
        this.config = {
            type: 'http'
        }
    }
}
Component.config

The config object is a component's special configuration object and defines how the component should be used.

Component.of()

You can create a component instance by calling this method with component definition object.

Example:

import { Component } from 'leverage-js'
 
Component.of({
    config: {
        type: 'http'
    }
})

Leverage.Middleware

The Middleware class lets you create your own middleware. You can extend it using the class syntax or use Middleware.of to extend using a normal object.

Example (with class syntax):

import { Middleware } from 'leverage-js'
 
class MyComponent extends Middleware {
    constructor () {
        super()
 
        this.config = {
            type: 'http'
        }
    }
}
Middleware.config

The config object is a middleware's special configuration object and defines how the middleware should be used.

Middleware.of()

You can create a middleware instance by calling this method with middleware definition object.

Example:

import { Middleware } from 'leverage-js'
 
Middleware.of({
    config: {
        type: 'http'
    }
})

Leverage.Service

The Service class lets you create your own service. You can extend it using the class syntax or use Service.of to extend using a normal object.

Example (with class syntax):

import { Service } from 'leverage-js'
 
class MyComponent extends Service {
    constructor () {
        super()
 
        this.config = {
            name: 'myService'
        }
    }
}
Service.config

The config object is a service's special configuration object and defines how the service should be used.

Service.of()

You can create a service instance by calling this method with service definition object.

Example:

import { Service } from 'leverage-js'
 
Service.of({
    config: {
        name: 'myService'
    }
})

Leverage.Plugin

The Plugin class lets you create your own plugin. You can extend it using the class syntax or use Plugin.of to extend using a normal object.

Example (with class syntax):

import { Plugin } from 'leverage-js'
 
class MyComponent extends Plugin {
    constructor () {
        super()
 
        this.config = {
            type: 'http'
        }
    }
}
Plugin.config

The config object is a plugin's special configuration object and defines how the plugin should be used.

Plugin.of()

You can create a plugin instance by calling this method with plugin definition object.

Example:

import { Plugin } from 'leverage-js'
 
Plugin.of({
    config: {
        type: 'http'
    }
})

Leverage.manager

Leverage's manager handles loading components, plugins, middleware, and services.

manager.add()

manager.add will load leverage modules from arguments, arrays, or directory path.

Example:

import { manager, Component, Plugin, Service, Middleware } from 'leverage-js'
 
manager.add(
    Component.of({ config: { type: 'some-type' } }),
    Plugin.of({ config: { type: 'some-type', identifier: 'some-id' } }),
    Service.of({ config: { name: 'some-name' } }),
    Middleware.of({ config: { type: 'some-type' } })
)
manager.component()

manager.component will load a component instance.

Example:

import { manager, Component } from 'leverage-js'
 
const component = Component.of({
    config: {
        type: 'http'
    }
})
 
manager.component(component)
manager.plugin()

manager.plugin will load a plugin instance.

Example:

import { manager, Plugin } from 'leverage-js'
 
const plugin = Plugin.of({
    config: {
        type: 'http',
        identifier: 'path'
    },
    http (component) {
 
    }
})
 
manager.plugin(plugin)
manager.service()

manager.service will load a service instance.

Example:

import { manager, Service } from 'leverage-js'
 
const service = Service.of({
    config: {
        name: 'myService'
    }
})
 
manager.service(service)
manager.middleware()

manager.middleware will load a middleware instance

Example:

import { manager, Middleware } from 'leverage-js'
 
const middleware = Middleware.of({
    config: {
        type: 'http'
    }
})
 
manager.middleware(middleware)

Readme

Keywords

Package Sidebar

Install

npm i leverage-js

Weekly Downloads

3

Version

1.3.1

License

ISC

Last publish

Collaborators

  • jakehamilton