New:Microsoft Teams Notifications Are Now Available in Socket.Learn more
Get Started

@toa.io/bridges.node

Package Overview
Dependencies
Maintainers
1
Versions
284
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@toa.io/bridges.node

Toa Node Bridge (inproc)

latest
Source
npmnpm
Version
0.24.0-alpha.0
Version published
Weekly downloads
1.6K
112.15%
Maintainers
1
Weekly downloads
 
Created
Source

Node.js Bridge

Currently, Node.js bridge only supports CommonJS modules.

Algorithm Definition

Operation's algorithms are defined as CommonJS modules in under operations directory in the component root. Algorithm module must export a function which is Algorithm Function, Class or Factory. Module file name without extension is an operation name (endpoint).

Function

// operations/create.js

function transition (input, object, context) {
  // ...

  return { foo: 'bar' }
}

exports.transition = transition

Exported function's name defines operation type property, thus must be one of: transition, observation, or assignment. Second (state) argument name must be object, objects, or changeset as it defines operation's scope.

Following function signature defines operation of observation type with objects scope.

// operations/set.js

function observation (input, objects) {
  // ...
}

See Operation properties.

Class

Example

// operations/transit.js

class Transition {
  #context

  async mount (context) {
    this.#context = context
  }

  execute (input, object) {
    // ...

    return { foo: 'bar' }
  }
}

exports.Transition = Transition

Exported class name must be one of: Transition, Observation, or Assignment, as it defines operation's type. Class must implement Algorithm interface. Second (state) argument name of the execute method must be object, objects, or changeset as it defines operation's scope.

Factory

class ObjectTransitionFactory {
  create () {
    // ...
  }
}

exports.ObjectTransitionFactory = ObjectTransitionFactory

Exported class name must follow the pattern: {Subject}{Type}Factory, where Subject and Type defines operation's scope and type respectively. Class must implement Algorithm Factory interface.

Factory class name examples: ObjectTransitionFactory, ObjectsObservationFactory, ChangesetAssignmentFactory.

Storing Context

Algorithm definition should store reference to the context object without copying its value type variables as they may change over operation lifetime.

FAQs

Package last updated on 16 Nov 2023

Related posts