Nodes'n things.
npm install @stoplight/graphiteNodes'n things.
- Explore the components: Storybook
- View the changelog: Releases
Supported in modern browsers and node.
``bash`latest stable
yarn add @stoplight/graphite
Note, this is not all implemented, but rather an example of what it might look like.
`ts
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());
`
- Holds nodes and edges.
- Exposes methods to add and remove nodes/edges.
- Responsible for managing node/edge lifecycle.
#### Nodes
- They hold data.
- There are three node categories (described below): source, source_map, and virtual.
#### Edges
- They represent relationships between nodes.
- Manages a single graph instance.
- Exposes applyPatch method.addSourceNode
- Emits events as patches are processed.
- Exposes convenience methods for common patterns, such as , that simply build and a patch or task and call applyPatch or queueTask.
- Manages tasks.
- ALL changes, both internal and external, pass through the graphite.applyPatch method.
#### 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 JsonPatch must be queued up via a GraphTask.add_node
- Examples include , read_node, write_node, parse_node, compute_node_source_map.oas2_lint_node
- Plugins can define their own tasks, such as .GraphTask
- The result of a must always be a GraphPatch.GraphPatch
- When a task is run, the it returns is applied to the graph.
#### Scheduler
- Manages one or more task queues.
- We will at the very least have high and low priority queues.add_node
- Tasks such as and read_node will go into a high priority queue.oas2_lint_node
- Tasks such as and resolve_node will go into a low priority queue.
#### Notifier
- Manages events like a boss.
#### SourceNode
- Source nodes are the only node category
- Exposes 4 primary properties - original, raw, parsed (TODO), and isDirty.read
- Exposes 4 primary methods - , write, updateRaw, and updateParsed.
#### SourceSink
- Responsible for reading data from some data source, and adding the appropriate source nodes.
- Responsible for refreshing the original property of a SourceNode in response to read_node tasks.SourceNode
- Responsible for writing the raw property back to the data source in response to write_node tasks.ISourceReader
- Implements and/or ISourceWriter.
#### SourceParser
- Targets one or more SourceNodes.parsed
- Responsible for computing its value when raw changes.raw
- Responsible for computing its value when parsed changes.
#### SourceMapNode
- A specific type of node that is a child of a SourceNode.uri
- Its points to a real location in the original source.SourceNode.parsed
- Its data property points to a value in its parent , according to its uri.update
- Exposes an method that queues a GraphPatch to update its source node parsed value.
#### SourceTree
- Defines a ISourceTreeMap that describes how a SourceNode.parsed value should be translated into SourceMapNodes.
- Anything that is not a SourceNode or SourceTreeNode
- Examples: linting results, transformed http operation and http service nodes, etc
1. Clone repo.
2. Create / checkout feature/{name}, chore/{name}, or fix/{name} branch.yarn
3. Install deps: .yarn test.prod
4. Make your changes.
5. Run tests: .yarn commit
6. Stage relevant files to git.
7. Commit: . _NOTE: Commits that don't follow the conventional format will be rejected. yarn commit creates this format for you, or you can put it together manually and then do a regular git commit._git push
8. Push: .next` branch.
9. Open PR targeting the