Oja Save

Lightweight Dependency Injection Framework for Node.JS Apps - Structure your application business logic

Project README

Oja logo v2.0

Lightweight dependency injection framework to structure application business logic.

Lerna License: MIT codecov Build Status NPM Known Vulnerabilities

Idea

The context based approach allows a developer to slice the business logic into small, isolated business actions that communicate to each other via context. That encourages developers to use the same action interface across application code, which makes the code more predictable, easy to define/compose, and test with mock data. And yes - it makes it boring.

context diagram

Basic -> Components -> Actions (Dependency Injection)

process

Example

Action definition

  • folder structure:
  module-root/
    action.json
    action.js
  • action.json:
{
    "MATH/sum": "./action"
}
  • action.js
module.exports = context => (a, b) => a + b;

Calling action

const { createContext } = require('@ebay/oja-action');
// context creation can be called for every new flow
const context = await createContext();
// calling action can be done many times within the same context
console.log(await context.action('MATH/sum', 1, 2)); // >> 3
console.log(await context.action('MATH/sum', 5, 2)); // >> 7

Install

In order to realize all benefits of using oja framework you need to do the following:

  • Install the following modules as part of your application

    npm install @ebay/oja-context @ebay/oja-action --save
    npm install @ebay/oja-linter --save-dev
    
  • Install VSCode extension as part of your VSCode Editor

    1. Open VS Code
    2. Press F1
    3. Type "install"
    4. Select "Extensions: Install Extension".
    5. Select vscode-oja from the list

    Note: VSCode extension uses oja-linter to validate your project files (action.json, *.js/mjs) and it will start working as soon as you install @ebay/oja-linter, @ebay/oja-action and @ebay/oja-context under your application dependencies.

  • Install optional hygen generator

    npm install hygen hygen-add -g
    hygen-add oja-generators
    
  • Example

    Feel free to explore examples, a fully functional application.

Documentation and Packages

Each package is documented in a separate readme:

  • oja-action - Provides action discovery for oja actions based on dependency injection.
  • oja-context - Provides dependency injection.
  • oja-generators - Provides code and unit test generation for oja-action framework.
  • oja-flow - Provides a flow components based on pub/sub pattern with event backlog. This is former oja 1.0 implementation.
  • oja-tools - Builds on oja-action to provide tools composing actions into higher level actions and/or instrument them via pipe pattern.
  • examples - Example project demonstrating the use of dependency injection based on oja-action
  • vscode-oja - VS Code extension that simplifies oja-action dependency injection usage with automatic suggestions and action discovery.
  • oja-linter - Oja linter for oja-action dependency injection layer that validates your project and discovers any unreachable actions (deleted/modified) at the point of the use of the action.
  • oja-pubsub - Provides a way to organize actions into publishers and subscribers roles when the same business events need to be consumed by multiple consumer actions.
  • TBD: oja-workers - Provides an action pool that can be used to separate actions or group of actions into their own isolated execution environments based on Node v12 lightweight workers.
  • TBD: oja-cloud - Provides an adaptor layer to organize and deploy actions to distributed environments aka lambda/serverless.

Example Use-Cases

  • Extension point

  • Middleware

  • Feature activation/selection

  • Flow selection

  • Pub/sub pattern to decouple producer actions from consumer actions

  • What if you are "stuck" with express, but like Koa syntax?

Code of Conduct

This project adheres to the eBay Code of Conduct. By participating in this project you agree to abide by its terms.

Author(s)

Dmytro Semenov

License

Copyright (c) 2019 eBay Inc.

Released under the MIT License http://www.opensource.org/licenses/MIT

Open Source Agenda is not affiliated with "Oja" Project. README Source: eBay/oja
Stars
26
Open Issues
2
Last Commit
4 years ago
Repository

Open Source Agenda Badge

Open Source Agenda Rating