@darkobits/marin

General-purpose dependency orchestration.

Stats

StarsIssuesVersionUpdatedCreatedSize
@darkobits/marin
070.1.23 years ago3 years agoMinified + gzip package size for @darkobits/marin in KB

Readme

Marin is a general-purpose tool for dependency orchestration based on the popular Orchestrator library. It lets you express relationships between objects, functions, classes, or any kind of value that permits property assignment.

There are only 3 concepts you need to understand to use Marin:

  1. Your dependency graph should have a root node and be acyclic.
  2. Each object in your graph must enumerate its dependencies at the same key (of your choosing).
  3. When each node is encountered during resolution, it will be passed to a handler function that you implement, which can perform any action with/on that node.

Install

npm i @darkobits/marin

Use

This package's default export is a function that accepts an options object with the following shape:

{
  /**
   * Root of your dependency graph.
   */
  root: any;

  /**
   * Key/property on each node in the graph that enumerates the node's dependencies.
   */
  dependencies: string | number | symbol;

  /**
   * Function which will be invoked with each node in the graph. This function may return a Promise and
   * will be await-ed.
   */
  hander: Function;
}

Examples

Below are a few examples demonstrating how to use Marin.

Objects

import Orchestrator from '@darkobits/marin';

const A = {
  prepareSelf: async () => { /* ... */ }
};

const B = {
  prepareSelf: async () => { /* ... */ },
  dependsOn: [A]
};

const C = {
  prepareSelf: async () => { /* ... */ },
  dependsOn: [A, B]
};

const root = {
  prepareSelf: async () => { /* ... */ },
  dependsOn: [C]
};

const orchestration = new Orchestrator({
  root: root,
  dependencies: 'dependsOn',
  handler: async node => {
    return node.prepareSelf();
  }
});

await orchestration.start();

Functions

import Orchestrator from '@darkobits/marin';

function A () { /* ... */ }

function B () { /* ... */ }
B.dependsOn = [A];

function C () { /* ... */ }
C.dependsOn = [A, B]

function root () { /* ... */ }
root.dependsOn = [C];

const orchestration = new Orchestrator({
  root: root,
  dependencies: 'dependsOn',
  handler: fn => fn()
});

await orchestration.start();

Classes

import Orchestrator from '@darkobits/marin';

class A {
  initialize() { /* ... */ }
}

class B {
  static dependsOn = [A];

  initialize() { /* ... */ }
}

class C {
  static dependsOn = [A, B];

  initialize() { /* ... */ }
}

class Root {
  static dependsOn = [C];

  initialize() { /* ... */ }
}

const orchestration = new Orchestrator({
  root: Root,
  dependencies: 'dependsOn',
  handler: Ctor => {
    const instance = new Ctor();
    return instance.initialize();
  }
});

await orchestration.start();

 


If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.