UNPKG

2.19 kBTypeScriptView Raw
1/// <reference types="node" />
2import { IDisposable } from '@stoplight/lifecycle';
3import { Dictionary, IDiagnostic } from '@stoplight/types';
4import { IFSTreeItem } from '../backends/filesystem';
5import { INotifier } from '../notifier';
6import { ITraceData } from '../types';
7import { IGraphDom, IGraphPatch, IGraphPatchResult, INodeFinder, JsonPatch, SourceNodeProp } from './dom/types';
8import { IBaseNode, ISourceNodeInstance, IVirtualNodeInstance, NodeInstance, NodeWithOptionalId } from './nodes/types';
9export interface IGraph<N = NodeInstance> extends IDisposable, INodeFinder, IPatchableGraph, IHydratable<IDehydratedGraph> {
10 readonly dom: IGraphDom<N>;
11 readonly nodeValues: NodeInstance[];
12 readonly sourceNodes: ISourceNodeInstance[];
13 readonly virtualNodes: IVirtualNodeInstance[];
14 readonly rootNodes: ISourceNodeInstance[];
15 readonly notifier: INotifier;
16 processIndexedTree: (tree: IFSTreeItem[], parentId: string) => void;
17 printTree: () => string;
18}
19export interface IPatchableGraph {
20 applyPatch: (patch: IGraphPatch) => IGraphPatchResult;
21 addNode: <NodeType extends NodeWithOptionalId>(props: NodeType, trace?: ITraceData) => NodeInstance;
22 indexNode: <NodeType extends NodeWithOptionalId>(props: NodeType, trace?: ITraceData) => NodeInstance;
23 setSourceNodeDiagnostics: (id: string, source: string, value: IDiagnostic[], trace?: ITraceData) => void;
24 setSourceNodeProp: (id: string, prop: SourceNodeProp, value: unknown, trace?: ITraceData) => void;
25 patchSourceNodeProp: (id: string, prop: SourceNodeProp, patch: JsonPatch, trace?: ITraceData) => void;
26 moveNode: (id: string, newParentId?: string | null, newPath?: string, trace?: ITraceData) => void;
27 removeNode: (id: string, trace?: ITraceData) => void;
28 reportError: (nodeId: string, err: NodeJS.ErrnoException, trace?: ITraceData) => void;
29}
30export interface IHydratable<D = unknown> {
31 dehydrate: () => D;
32}
33export interface IDehydratedGraph {
34 nodes: Dictionary<IBaseNode, string>;
35}
36export declare type IdGeneratorWrapper = (node: NodeWithOptionalId) => string;
37export declare type IdGenerator = (node: NodeWithOptionalId, uri: string) => string;