@dflowng/extensions-loader

0.0.1 • Public • Published

@dflowng/extensions-loader - extension (plugin) loader of Data Flow eNGine

This package is a part of the Data Flow eNGine project.

Extensions in Data Flow eNGine

Some of components of Data Flow eNGine (such as operation and context classes, data types and applications (solutions)) are loaded dynamic as extension components that are defined in extension packages.

Extension package for Data Flow eNGine is a NPM package exporting a JSON document -- manifest of the extension package. Manifest contains list of package dependencies that should be loaded as extension packages (some of extension package dependencies may not be extension packages but just a libraries used by some components defined in the package) and list of extension components defined in the package.

Here is a simple example of a package manifest:

{
    "define": {
        "plugin": ["scripts/myPlugin1.js", "scripts/myPlugin2.js"],
        "operator-class": {
            "vector-constant": {
                "super": "constant",
                "config": {
                    "value-type": "float",
                    "value-size": [4],
                    "value": [0,0,0,0]
                }
            }
        }
    },
    "dependencies": ["@dflowng/ext-default"]
}

Extensions package manifest of which is shown in the example above defines three extension components -- two components of class "plugin" that are described by files in package's subdirectory scripts and the component of class "operator-class" named "vector-constant". Also this package depends on another extensions package named @dflowng/ext-default. The extension package manifest contains no information about version of extension packages this one depends on -- the versions of packages should be defined in package.json.

Loading extensions

To load specific extensions package function loadExtensions(di, package, require) should be called:

// Get function from DI container
const loadExtensions = DI.func('loadExtensions').get();

// Or just using require
// const loadExtensions = require('@dflowng/extensions-loader');

// Load extensions components from package into DI container
loadExtensions(DI, 'package-name', require)
    .then(
        ( ) => console.log('Done.'),
        err => console.error('Error:', err.stack));

This function will load a package (resolving path using given require function) and it's dependencies. For each extension component function defined #func('extensionLoader') is called with the DI container instance passed to the loadExtensions function as first argument and component definition object as second one.

Component definition object includes the following fields:

  • "name" -- name of the component.
  • "type" -- name of component class.
  • "params" -- parameters object. The object at right side of component name if list of components of the class is a object or empty object if list is a array.
  • "basePath" -- path to the directory the manifest file is located in.
  • "require" -- the Module#require(id) function of manifest module.

Default implementation of extensionLoader delegates call to function defined as #func('extensionLoader', definition.type) with the same signature.

Readme

Keywords

none

Package Sidebar

Install

npm i @dflowng/extensions-loader

Weekly Downloads

0

Version

0.0.1

License

MIT

Last publish

Collaborators

  • dflowng