UNPKG

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