@chakrajs/framework
0.0.3

Intro

Installable via npm install --save @chakrajs/framework, it can also be used directly in the browser.

Download

The source is available for download from GitHub. Alternatively, you can install using npm:

$ npm install --save @chakrajs/framework

You can then require() @chakrajs/framework as normal:

const chakrajsFramework = require('@chakrajs/framework')

In the Browser

@chakrajs/framework should work in any ES2015 environment out of the box.

Usage:

<script type="text/javascript" src="index.js"></script>

The portable versions of @chakrajs/framework, including index.js and index.min.js, are included in the /dist folder. @chakrajs/framework can also be found on unkpkg.com under

Chakra

Chakra main class

Parameters

  1. config: Object (={}):  
    Configuration of the Chakra instance

instance

Chakra.prototype.plug

plug(plugins: ...Plugin): undefined

Register new plugins with Chakra

Parameters

  1. plugins: ...Plugin:  
    List of Plugin objects to register

Returns

Throws

Error Will throw on plugin registration failure

Chakra.prototype.start

start(): undefined

Start the Chakra application

Returns

EventBus

Publish-subscribe event-bus

instance

EventBus.prototype.register

register(entity: String, action: String, schema: Object): undefined

Register a new topic with the event bus

Parameters

  1. entity: String:  
    Entity the new topic relates to
  2. action: String:  
    Action the new topic relates to
  3. schema: Object:  
    JSON Schema for the topic

Returns

EventBus.prototype.subscribe

subscribe(entity: String, action: String, publishHandler: function): string

Subscribe to a new topic

Parameters

  1. entity: String:  
    Entity of the topic to subscribe to
  2. action: String:  
    Action of the topic to subscribe to.
  3. publishHandler: function:  
    Function to handle published data.

Returns

string Subscription key for the subscription

Throws

any Will throw if the topic is not found.

EventBus.prototype.publish

publish(entity: String, action: String, content: Object): undefined

Publish a new message

Parameters

  1. entity: String:  
    Entity of the message topic
  2. action: String:  
    Action of the message topic
  3. content: Object:  
    Message to publish

Returns

Throws

Error Will throw if the message is invalid against the schema

EventBus.prototype.unsubscribe

unsubscribe(subscriptionKey: string): undefined

Unsubscribe from a subscribed topic

Parameters

  1. subscriptionKey: string:  
    Key that was returned when subscribing

Returns

Message

Data to be published through the event bus

Parameters

  1. topic: Topic:  
    Topic of the content
  2. content: Object:  
    Message content JSON

Topic

Topic of the event to publish

Parameters

  1. entity: string:  
    Entity of the topic
  2. action: string?:  
    Action of the topic.

instance

Topic.prototype.getName

getName(): string

Returns the name of the topic

Returns

string Name of the topic

TopicRegistry

Schema registry for the topics

instance

TopicRegistry.prototype.register

register(topic: Topic, schema: Object): undefined

Add new topic to the registry

Parameters

  1. topic: Topic:  
    Topic to register with the registry
  2. schema: Object:  
    Schema for the topic

Returns

Throws

Error Will throw if topic is already registered

TopicRegistry.prototype.isRegistered

isRegistered(topic: Topic): boolean

Check if a given topic is registered with the registry.

Parameters

  1. topic: Topic:  
    Topic to verify registration

Returns

boolean Whether the topic is already registered

TopicRegistry.prototype.getSchema

getSchema(topic: Topic): undefined

Get schema by topic name.

Parameters

  1. topic: Topic:  
    Topic to get schema for.

Returns

TopicRegistry.prototype.validate

validate(message: Message): boolean

Validate a content against its schema

Parameters

  1. message: Message:  
    Message to validate

Returns

boolean Whether the message is valid

ChakraStatus

Chakra framework's built-in Status plugin

Extends Plugin.

instance

ChakraStatus.prototype.publishStartedMessage

publishStartedMessage(appData: Object): undefined

Publish Chakra.Started message

Parameters

  1. appData: Object (={name:'App',version:'1.0.0'}):  
    Details about the Chakra app
  2. appData.name: string (='App'):  
    Name of the Chakra app
  3. appData.version: string (='1.0.0'):  
    Version of the Chakra app

Returns