
Research
/Security News
11 Malicious Go Packages Distribute Obfuscated Remote Payloads
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.
property-graph
Advanced tools
Extensible base for creating objects that behave like a Property Graph.
The property-graph
package is intended as a foundation for libraries requiring many custom types of compatible parts, which can be represented as a Property Graph. The Property Graph representation is useful for dependency chains, resource references, node-based art workflows, and a broader class of applications where Graph databases are common.
Conceptually, a Property Graph is a labeled, directed multigraph, in which entities ("nodes") may have named relationships ("edges") with other nodes on the graph. Both nodes and edges may also be associated with key/value attributes. Beyond that, property-graph
is intended to be small and practical, rather than providing a large standard library for graph theory — if you need something more comprehensive, I'd suggest graphology
.
Typically, you'll define several classes inheriting from the base GraphNode
. When using TypeScript, an interface should be provided defining the kinds of connections that each type of graph node allows. Then, .set
and .get
methods may be used to set key/value attributes (strings, numbers, booleans, ...), and .getRef
and .setRef
methods may be used to create edges (or relationships) to other nodes of a compatible type. All references have names, and support compile-time type-checking.
In a codebase with many distinct types of entities and relationships among them (e.g. "Client has N Projects", "Project has N Tasks"), this project can make management of entities and their relationships considerably easier than writing plain getters/setters for each case.
.copy()
, .equals()
, and .swap(a, b)
can be implemented abstractlyDefinitions:
import { GraphNode, RefSet } from 'property-graph';
interface IPerson {
name: string;
age: number;
friends: RefSet<Person>;
pet: Pet;
}
interface IPet {
type: 'dog' | 'cat';
name: string;
}
class Person extends GraphNode<IPerson> {
getDefaults(): Nullable<IPerson> {
return {name: '', age: 0, friends: new RefSet(), pet: null};
}
}
class Pet extends GraphNode<IPet> {
getDefaults(): Nullable<IPet> {
return {type: 'dog', name: ''};
}
}
Basic usage:
const graph = new Graph();
const spot = new Pet(graph)
.set('type', 'dog')
.set('name', 'Spot');
const jo = new Person(graph)
.set('name', 'Jo')
.set('age', 41)
.setRef('pet', spot);
const sam = new Person(graph)
.set('name', 'Sam')
.set('age', 45)
.addRef('friends', jo);
Lifecycles:
jo.equals(sam); // recursive equality → false
console.log(sam.listRefs('friends')); // → [jo]
jo.dispose();
console.log(sam.listRefs('friends')); // → []
Literal attributes (string, number, boolean, ...) are modified with two methods:
node.get('key'): Literal
node.set('key', value: Literal): this
References support one named connection to a single graph node of a given type:
node.getRef('key'): GraphNode
node.setRef('key', node: GraphNode): this
Reference Lists support a named list of connections to graph nodes of a given type:
node.addRef('key', node: GraphNode): this
node.removeRef('key', node: GraphNode): this
node.listRefs('key'): GraphNode[]
Reference Maps support a named map having any number of subkeys, where each subkey points to a graph node of a given type:
node.getRefMap('key', 'subkey'): GraphNode
node.setRefMap('key', 'subkey', node: GraphNode): this
node.listRefMapKeys('key'): string[]
node.listRefMapValues('key'): GraphNode[]
FAQs
Base for creating objects that behave like a Property Graph.
The npm package property-graph receives a total of 28,962 weekly downloads. As such, property-graph popularity was classified as popular.
We found that property-graph demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
/Security News
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).