SOCKO! - Hierarchical Tree Weaver
Introduction
SOCKO! is an ETL tool for trees. It walks through an input tree, applies various modifications from a hierarchy tree to it and returns the resulting tree.
This is the core SOCKO api. It's currently the base framework for the SOCKO! command line tool and Grunt helper, that use the API to modify a set of directories in the area of configuration file management. The API is heavily based on js-hierarchy.
The current features include:
- Use the contents of a node in the hierarchy-tree, that has the same name as a node in the input-tree
- Insert the content of one or multiple cartridge node in the hierarchy tree into the content of a socket node in the input tree at a specific index
- Collect a bunch of nodes from the hierarchy-tree and put them in a corresponding branch node of the result tree
For details, see the API documentation
Usage
Typescript
The module includes the complete type definitions for Typescript applications. Simply install the module and you're ready to go:
; ;
Node.js
After installing the module, use it with require():
var sockoApi = ; var rootNode = ;
Browser
Install the module and include the browser script:
or use the jsDelivr CDN hosted version:
With this the global namespace will include a "sockoapi" object:
var rootNode = ;
After that, everything's right as working in Node.js.
Nodes and processors
The SOCKO! api provides a set of custom js-hierarchy nodes. All nodes implement the interface "SockoNodeInterface", that adds a "type" and a "content" property. The type references the specific node, that was used and is mainly used to identify the nodes at runtime. The content holds the original or generated content of the node.
These nodes are provided by the core API:
- RootNodeInterface: The root of each tree
- BranchNodeInterface: A node, that holds children
- SimpleNodeInterface, OutputNodeInterface: A node, that holds content, but no children. The SimpleNode is used in the input- and hierarchy-trees and the OutputNode in the result tree.
- SkippedNodeInterface: A node, that was skipped by the current processor
The different features of the SOCKO! api rely on processors, that process specific node types when walking the input tree. So each processor uses additional node types
- SocketProcessor:
- SocketNodeInterface: A "skeleton" node, that holds different insertion slots for cartridge nodes or cartridge collectors to insert content at various parts of the SocketNode content
- CartridgeNodeInterface: A node, that is inserted into one or more slots of SocketNodes
- BucketProcessor:
- BucketNodeInterface: A node in the input node producing a branch node in the result tree collecting SimpleNodes from the hierarchy-tree