import * as jsonpatch from 'fast-json-patch'; import { ConfigSettingsArgs, MergeOptions } from '../types'; import { ConfigNodeArgs, ConfigNodeHooks, ConfigNodeInheritedNodeOptionsArg, ConfigNodeInheritedNodesArg, ConfigNodeOptions, ConfigNodePropertyFactory, ConfigNodePropertyPath, ConfigNodeValueArg, ConfigPropertyNodeFactoryArgs } from './types'; /** * Abstract Base class defining a Config Node. All ConfigNodes ultimately inherit from this. */ export declare abstract class ConfigNodeBase = ConfigNodeArgs> { protected readonly args: TArgs; /** * Root Node from which this Node descends ('this' if this is node is the root). Root Node has not parent. */ get rootNode(): ConfigNodeBase; get propertyPath(): string[]; /** * Resolved value of this Node. */ get value(): TValue; /** * Hooks to Node notifications implemented as AsyncParallelHook */ get hooks(): ConfigNodeHooks; /** * Direct value of this Node without inherited values. */ get nodeValue(): TValue; /** * Map of Nodes representing properties of this Node, keyed on Property name. */ get propertyNodes(): { [name: string]: ConfigNodeBase; }; /** * Inherit parent node's value for this node */ get shouldInheritParent(): boolean; /** * Inherit parent node's value for this node */ set shouldInheritParent(inherit: boolean); /** * Array of Inherited nodes providing base values from which this Node inherits. */ protected get inheritedNodes(): ConfigNodeBase[]; /** * Indicates whether this Node has a staic value (e.g. number, string, bool) * and not an object with property nodes */ protected get hasStaticValue(): boolean; /** * Getter for Option data used to configure Node handling */ protected get options(): TOptions; /** * Setter for Option data used to configure Node handling */ protected set options(options: TOptions); get propertyName(): string; get parentNode(): ConfigNodeBase; protected abstract get defaultPropertyNodeFactory(): ConfigNodePropertyFactory; static merge: (settings: any[], options?: MergeOptions) => any; /** * Unique Id for this Node */ readonly id: string; protected _initialValue: ConfigNodeValueArg; private _propertyNodes; private _staticValue; private _inheritedNodes; private _options; private _hooks; private _applyingValue; private _initializing; private _shouldInheritParent; private _propertyName; private _parentNode; protected constructor(args: TArgs); /** * Adds a Node from which this Node will inherit values from. * @param node Node from which this will inherit. */ addInheritedNode: (node: ConfigNodeInheritedNodesArg) => void; /** * Returns Node at a property path * @param path path to property, delimited by '.', '/', or as an array * @param includeInherited if true, return matching inherited node if path doesn't exist directly on this node */ getPropertyNode(path: ConfigNodePropertyPath, includeInherited?: boolean): TNodeValue | undefined; /** * Applies passed value to Node. * @param value Value to apply to Node in form of ConfigNodeValueArg built with ConfigSettingsBuilder. */ applyValue(value: ConfigNodeValueArg): Promise; /** * Returns array of all inherited nodes, optionally nodes for a given path * @param propertyPath property path */ resolveInheritedNodes(propertyPath?: ConfigNodePropertyPath): ConfigNodeBase[]; /** * Build value to be returned by value property. Subclasses can override with specialized logic to build value. * @param excludeInherited do not include inherited values * @param omitProperties omit properties from value (primarily needed to avoid cycles in certain use cases) */ getValue(excludeInherited?: boolean, omitProperties?: string[]): TValue; /** * Convert ConfigNodeInheritedNodeOptionsArg for inherited node to a Node */ protected inheritedNodeOptionsArgToNode: (optionsArg: ConfigNodeInheritedNodeOptionsArg) => ConfigNodeBase<{}, ConfigNodeOptions, ConfigNodeArgs>>; /** * Convert inherited node argument to array of nodes */ protected inheritedNodeArgToNodes: (arg: ConfigNodeInheritedNodesArg) => ConfigNodeBase<{}, ConfigNodeOptions, ConfigNodeArgs>>[]; /** * Getter hook to return defined inherited nodes. Allows subclasses to defined inherited * nodes dynamically. Returns nodes in instance value by default. */ protected _getInheritedNodes(): ConfigNodeBase[]; /** * Get array of all property nodes for given path, including direct node (if exists) and inherited nodes for property path * @param path property path */ protected getPropertyNodes(path: ConfigNodePropertyPath): ConfigNodeBase[]; /** * Return default value for this node. Can be used by subclasses to provide defaults. */ protected getDefaultValue(): Promise>; /** * Build value from inherited nodes. */ protected getInheritedValue(): any; /** * Return raw initial value. By default returns value supplied to constructor. */ protected getInitialValue(): Promise; /** * Called prior to init function (for subclass hook) */ protected beforeInit(): Promise; /** * Called after init function (for subclass hook) */ protected afterInit(): Promise; /** * Async method to initialize Node. Must be called asyncronously, after Node constructed */ protected init(): Promise; /** * Searches the node hierarchy to find a configured property node factory based on a provided path. Returns * undefinded if a factory is not defined for the specific property path. * @param propertyPath property path for which to find configured node factory * @param includeInherited whether or not to search inherited nodes for factory */ protected findPropertyNodeFactory(propertyPath: ConfigNodePropertyPath, includeInherited?: boolean): ConfigNodePropertyFactory | undefined; /** * Creates a property node, tryes to find a defined factory to create the node based on the path * @param args property node args */ protected createPropertyNode(args: TArgs & ConfigPropertyNodeFactoryArgs): Promise; /** * Returns argument object to pass to Property Node Factory. Allows specialized sub-classes to include additional arguments. * @param baseArgs base args supplied by ConfigNodeBase */ protected getPropertyNodeFactoryArgs(baseArgs: ConfigPropertyNodeFactoryArgs): TArgs & ConfigPropertyNodeFactoryArgs; /** * Returns json patch for previous and current values. Note, this only makes sense for object values. We can't * create a json patch for non-object static values, so only completely accurate at the parent object level * @param previousValue previous value to compare * @param currentValue current value to compare */ protected getJsonPatchDiff(previousValue: TValue | {}, currentValue: TValue | {}): jsonpatch.Operation[]; /** * Helper using ConfigSettingsBuilder to build setting supplied by argument to applySettings * @param settings ConfigSettingsArgs value to be passed to ConfigSettingsBuilder */ protected buildSettingsFromArgs(settings: ConfigSettingsArgs): Promise<{}>; /** * Internal method to apply value to node * @param value Value to apply * @param notify Indicates whether valueChanged hook is called */ protected _applyValue(value: ConfigNodeValueArg, notify?: boolean): Promise; /** * Handles valueChanged notifications from property nodes and calls notify hook with properties * mapped to this node's property paths. */ protected handlePropertyValueChanged: (patch: jsonpatch.Operation[], propertyNode: ConfigNodeBase<{}, ConfigNodeOptions, ConfigNodeArgs>>) => Promise; /** * Fires valueChanged hook with changes to node value * @param patch json patch with changes to node value */ protected notifyValueChanged(patch: jsonpatch.Operation[]): Promise; /** * Fires propertyAdded hook when new property is added to this node * @param propertyNode added property node */ protected notifyPropertyAdded(propertyNode: ConfigNodeBase): Promise; protected merge: (settings: any[], options?: MergeOptions) => any; }