Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
DAG maker utilize topological sorting to make directed acyclic graphs.
It can be used to solve following problems:
npm i dag-maker
Suppose we have two classes A and B. The dependency graph as follows:
A <- B
To instantiate them, first we create an instance of A, then pass the instance to B's constructor. Since there are only two classes, it's quite straightforward.
However, when it comes to a dozen classes with complex dependencies, it's no longer feasible to figure out the proper construction order manually. Not to mention the destruction order.
Here is an example (in TypeScript) presents how to solve this kind of problem with dag-maker
:
import { dependencies, DagMaker } from 'dag-maker';
class A {
static async create() {
console.log('create A');
return new A();
}
static async destroy(a: A) {
console.log('destroy A:', a);
}
}
@dependencies({
a: A,
})
class B {
constructor(a: A) {
this.a = a;
}
static async create(options: { a: A }) {
console.log('create B');
return new B(options.a);
}
static async destroy(b: B) {
console.log('destroy B:', b);
}
}
const dagMaker = new DagMaker(A, B);
console.log(dagMaker.orderBy('dependencies'));
// [ [ 'A' ], [ 'B' ] ]
console.log(dagMaker.orderBy('dependents'));
// [ [ 'B' ], [ 'A' ] ]
const dag = await dagMaker.create();
// create A
// create B
console.log(dag);
// Map(2) { 'A' => A {}, 'B' => B { a: A {} } }
await dagMaker.destroy(dag);
// destroy B: B { a: A {} }
// destroy A: A {}
In this example, we implement factory methods create()
and destroy()
right inside class A and B, and declare B's dependencies with a decorator @dependencies
. If you don't want to use decorator, declare a static variable named dependencies
could achieve the same semantic. After then, we create a DagMaker
for class A and B. Eventually, the DAG maker will inspect dependencies
property and figure out how to construct A and B.
FAQs
DAG maker
The npm package dag-maker receives a total of 9 weekly downloads. As such, dag-maker popularity was classified as not popular.
We found that dag-maker demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.