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

@deda-ca/core-bus

v3.0.1

Published

Core DEDA (Distributed Event Driven Application) is an event based, component loader framework used to create server side (nodejs) and client side (browser).

Downloads

4

Readme

DEDA Core

DEDA Core is an event based, component loader framework used to create server side (nodejs) and client side (browser). It is responsible for loading application components defined within a JSON file and running the application.

The main design principal in this project is simplicity and less code. This simply a structure. DEDA provides a very simple, clean and straight forward way fo created modularized/componentized application.

DEDA Application JSON

The idea behind creating an application using a JSON file is to force componentization. Components can be loaded from anywhere; local file system, remote file shares, web URL (github or gitlab) etc. In DEDA an application is simply a list of components and their configurations. For example:

{
    "deda": {
        "dependencies": [
            "deda-core",
        ],

        "files": [
            "./src/myComponent1.js",
            "./src/myComponent2.js",
            "./src/myComponent2.js",
        ],

        "components": [
            {
                "namespace": "MyApp.Component1",
                "port": 4500,
                "host": "0.0.0.0"
            },
            {
                "namespace": "MyApp.Component2",
                "debug": true,
                "maxUsers": 5
            }
        ]
    }
}

The JSON file has 3 sections:

  • dependencies: a list of dependencies which are also DEDA components.
  • files: a list of files within this project to load.
  • components: a list of components to create and start.

The Module loader starts by loading the dependencies and their dependencies, followed by the application files, then the Bus creates the components using their namespace. Finally initializes and starts the application/components.

Project Files

The project files are split into 3;

  • Common files for both node and browser.
  • Node specific files.
  • Browser specific files.

Classes

  • DEDA.Core.Component - Is the heart of DEDA components and all components must extend this class. The constructor accepts the application bus and the components configurations.
  • DEDA.Core.Bus - This is the application heat. All components have a reference to it this.bus. It is the event emitter used by components to communicate. It also loads the "components" from the JSON and provides a common API for applications such as: env, event emitter, list of all components, logging interface, and language interface.
  • DEDA.Core.Module - The module is similar to the JS Common where it is responsible for loading the "dependencies" and "files" for the application no matter where they are. There is a node and browser implementation of the base class.

There are 2 helper classes

  • DEDA.Core.Utility - Provides general utility methods.
  • DEDA.Core.Environment - Provides node specified environment and command line arguments parsing and loading.

There isn't much code in any of these classes the project idea is to provide a simple structure for promoting component/module based application architecture.

Environment

The environment class provides a way to parse command line arguments and load environment files:

  • Loads JSON config files for multiple components, applications, and environments. See config JSON format above.
  • Create different config profiles for debug, development, release, etc. within a single file and apply them based on a command line argument.
  • Loads process.env within bus.env.
  • Loads process.args within DEDA.env and applies commands.

Env File Format:

{
    "use": "<string>|[<string>]",
    "defaults": {
        "base_url": "https://domain.com"
    },
    
    "dev": {
        "api_url": "${env.base_url}/api/laundry/admin"
    }
}
  • The use property lists the configs to add to the env object.
  • The defaults are automatically add to the env object.

Added property values are processed and replaced with the variables within the environment. In the above example ${env.base_url} will be replace with the actual value. This format also applies to all DEDA JSON component configs automatically when a component is loaded.

Command Line Arguments

The parser supports the following:

  • Key value as: -key value

  • Key with no value is set to true: -key

  • If same key exists multiple times the values are converted to an array.

    -v false -dev -port 456 -host 10.10.10.4 -host 192.168.1.1

This is converted to the following object.

{
    "v": false,
    "dev": true,
    "port": "456",
    "host": [
        "10.10.10.4",
        "192.168.1.1"
    ]
}