
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@ebay/oja-context
Advanced tools
Defines a basic Oja dependency injection API.
This module is a subset of eBay Oja framework.
The dependency injection approach allows the developer to slice the business logic into small, isolated business actions that are injected via context.
That encourages developers to use the same action interface across application code and makes the code more predictable, easy to define, and test with mock data. And yes - it makes it boring.
npm install @ebay/oja-context --save
The context based approach provides a more explicit way of composing actions in the application while in publisher/subscriber pattern the consumers of the events are completely disconnected from the publishers.
ojaContext(createBaseContext: Function): Function
Create a factory function, that if called, will return a context object extended from an object returned by createBaseContext.
ojaContext(options: Map): Function
Create a context with actions and properties injected as part of options. It returns a context reference which provides access to all other actions. It can also extend a Flow class if requested, so that one can mix flow with context API.
{
functions: Map <
namespace: String,
Map <actoinName: String, action: Function>
>,
properties: <Map <string, value:Any> >,
resolve: Function,
selectors: Map <string, value:Any>
}
Where:
const result = await context.action('action-name-space', arg1, arg2, ...);
Or more specific in some rare case with the help of selectors
const result = await context.action({
name: 'action-name-space',
'selector1': 'foo', // this selector will not be dropped
'~selector2': /^bar/, // <<< you can use regexp, and this selector can be dropped
'~selector3': (value) => true, // <<< or match function, and this selector can be dropped
...
}, arg1, arg2, ...);
It will make the most relevant match. If no exact match found for the selectors, it will drop selectors prefixed with '~' one by one trying to match the rest starting from the last and moving up while removing. This provide a fallback logic.
These are the main properties used for context creation:
context.<property name>
access patternconst createContext = require('@ebay/oja-context');
// inject/configure context
const context = createContext({
// injecting properteis
properties: {
parameters: {
foo: 'foov',
bar: 'barv'
}
},
// injecting actions
functions: {
'domainName1/actionName1': context => {},
'domainName1/actionName2': context => {},
'domainName2/actionName3': context => {},
'domainName2/actionName4': context => {}
}
});
// use it
console.log(context.foo); // >> foov
console.log(context.bar); // >> barv
// call action
const actionResult1 = await context.action('domainName1/actionName1');
const actionResult3 = await context.action('domainName2/actionName3', 'foo', 'bar);
Context can extend any base object, for example, you can extend Flow class, and use a pub/sub with context based approach.
const createContextFactory = require('@ebay/oja-context');
const Flow = require('@ebay/oja-pipe').Flow;
const createContext = createContextFactory(() => new Flow());
// inject/configure context
const context = createContext({
...
});
modules.exports = async context => {
const searchResults = await context.action('actions/search', 'foo'); // passing some parameters
// publish it
context.define('searchResults', searchResults);
};
// consume it in some other action
modules.exports = async context => {
const searchResults = await context.consume('searchResults');
return {
searchResults
};
};
When you migrate your application to oja dependency injection and to make sure you enjoy using it, your code MUST avoid:
then
or catch
. Outlaw them! Always use async/await style.FAQs
Dependency injection via actions
The npm package @ebay/oja-context receives a total of 2 weekly downloads. As such, @ebay/oja-context popularity was classified as not popular.
We found that @ebay/oja-context demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 13 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.