@stoplight/graphite v12.7.1
@stoplight/graphite
Nodes'n things.
Installation
Supported in modern browsers and node.
# latest stable
yarn add @stoplight/graphiteUsage
Note, this is not all implemented, but rather an example of what it might look like.
import {
Graphite,
FilesystemPlugin,
JsonPlugin,
YamlPlugin,
Oas2Plugin
} from "@stoplight/graphite";
const graphite = Graphite();
graphite.registerPlugins(
FilesystemSource(),
JsonPlugin(),
YamlPlugin(),
Oas2Plugin()
);
// Mirror two Graphite instances. The mirroredGraphite instance has no plugins, and simply applies the results of the graphite instance.
const mirroredGraphite = Graphite();
graphite.on("did_patch", mirroredGraphite.applyPatch);
// Add a single SourceNode of type file
const n = graphite.addSourceNode({
type: FilesystemPlugin.File,
path: "/foo.json"
});
// Queue up a read task for that node
n.read();
// Wait until all processing is done
await graphite.tasksProcessed();
// The two graphs should be identical, ids and all.
// Note, the mirroredGraph did NO work - all the file reading, parsing, etc, was done by the plugins in the main graphite instance.
expect(graphite.dehydrate()).toEqual(mirroredGraphite.dehydrate());Concepts
Graph
- Holds nodes and edges.
- Exposes methods to
addandremovenodes/edges. - Responsible for managing node/edge lifecycle.
Nodes
- They hold data.
- There are three node categories (described below):
source,source_map, andvirtual.
Edges
- They represent relationships between nodes.
Graphite
- Manages a single graph instance.
- Exposes
applyPatchmethod. - Emits events as patches are processed.
- Exposes convenience methods for common patterns, such as
addSourceNode, that simply build and a patch or task and callapplyPatchorqueueTask. - Manages tasks.
Mutations
- ALL changes, both internal and external, pass through the
graphite.applyPatchmethod.
JsonPatch
- A group of
JsonOperations.
GraphPatch
- A group of
JsonOperations, and their inverse. This is similar to the concept of a "transaction". - If one operation fails, they all fail, and a rollback is attempted.
GraphTask
- Describes a single change to be made to the graph.
- Any operations that cannot be accomplished via
JsonPatchmust be queued up via aGraphTask. - Examples include
add_node,read_node,write_node,parse_node,compute_node_source_map. - Plugins can define their own tasks, such as
oas2_lint_node. - The result of a
GraphTaskmust always be aGraphPatch. - When a task is run, the
GraphPatchit returns is applied to the graph.
Scheduler
- Manages one or more task queues.
- We will at the very least have
highandlowpriority queues. - Tasks such as
add_nodeandread_nodewill go into ahighpriority queue. - Tasks such as
oas2_lint_nodeandresolve_nodewill go into alowpriority queue.
Notifier
- Manages events like a boss.
Sources
SourceNode
- Source nodes are the only node category
- Exposes 4 primary properties -
original,raw,parsed(TODO), andisDirty. - Exposes 4 primary methods -
read,write,updateRaw, andupdateParsed.
SourceSink
- Responsible for reading data from some data source, and adding the appropriate source nodes.
- Responsible for refreshing the
originalproperty of aSourceNodein response toread_nodetasks. - Responsible for writing the
SourceNoderaw property back to the data source in response towrite_nodetasks. - Implements
ISourceReaderand/orISourceWriter.
SourceParser
- Targets one or more
SourceNodes. - Responsible for computing its
parsedvalue whenrawchanges. - Responsible for computing its
rawvalue whenparsedchanges.
SourceMapNode
- A specific type of node that is a child of a
SourceNode. - Its
uripoints to a real location in the original source. - Its data property points to a value in its parent
SourceNode.parsed, according to itsuri. - Exposes an
updatemethod that queues aGraphPatchto update its source node parsed value.
SourceTree
- Defines a
ISourceTreeMapthat describes how aSourceNode.parsedvalue should be translated intoSourceMapNodes.
VirtualNode
- Anything that is not a
SourceNodeorSourceTreeNode - Examples: linting results, transformed http operation and http service nodes, etc
Contributing
- Clone repo.
- Create / checkout
feature/{name},chore/{name}, orfix/{name}branch. - Install deps:
yarn. - Make your changes.
- Run tests:
yarn test.prod. - Stage relevant files to git.
- Commit:
yarn commit. NOTE: Commits that don't follow the conventional format will be rejected.yarn commitcreates this format for you, or you can put it together manually and then do a regulargit commit. - Push:
git push. - Open PR targeting the
nextbranch.
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago