UNPKG

@altostra/core

Version:

Core library for shared types and logic

122 lines (121 loc) 4.64 kB
import type { It } from "../../../common/Iterable"; import type { Maybe } from "../../../common/Maybe"; import { ParameterPathBuilder } from "../../Parameters"; import type { ParameterPath, ParametersDict, ParameterSpec } from "../../Parameters"; import type { Parameterized } from "../Parameters"; /** * An object having parameters property */ export interface ParametersContainer { parameters?: ParametersDict; } /** * A helper class to handle parameters */ export declare class ParametersHelper { #private; /** * The root parameters path */ static readonly resourcesRoot: ParameterPathBuilder; static readonly connectionsRoot: ParameterPathBuilder; static readonly globalEnvironmentRoot: ParameterPathBuilder; /** * The root parameters path */ readonly resourcesRoot: ParameterPathBuilder; readonly connectionsRoot: ParameterPathBuilder; /** * Creates new ParametersHelper instance * @param container The parameters container */ constructor(container: ParametersContainer); /** * Gets the parameters object. */ get parameters(): Readonly<Maybe<ParametersDict>>; private get _blueprintParams(); private set _blueprintParams(value); /** * Returns an IterableX of parameter entries */ iterateParams(): It<[string, ParameterSpec]>; /** * Returns an IterableX of parameter and path entries */ iteratePaths(): It<[string, ParameterPath]>; iteratePathBuilders(): It<[string, ParameterPathBuilder]>; /** * Add the parameter at the specified path. \ * * If the parameter exists at the specify path, nothing happens. \ * If the parameter does not exist it is created; otherwise, the path is added * to its spec * @param name The name of the parameter * @param pathsOrSpec Path for the parameter, or parameter spec * @returns The parameter spec of the parameter. */ add(name: string, pathsOrSpec: ParameterPath | ParameterSpec): ParameterSpec; /** * Removes a parameter. \ * * If the parameter does not exist, or is not residing in the provided paths, nothing happens. \ * If the parameter has other paths, it remains with those paths; otherwise, * the parameter is removed * @param name The name of the parameter to remove * @param spec A path to remove, or a `ParameterSpec` containing many paths to remove * @returns The parameter spec with removed paths. If no paths left, then undefined is returned. */ remove(name: string, spec: ParameterPath | ParameterSpec): Maybe<ParameterSpec>; /** * Removes all paths from a parameter. * @param name The name of the parameter to remove */ remove(name: string): void; /** * Removes all parameter paths that are starting with the specified path * @param path The base path to clear */ deleteAllFromPath(path: ParameterPath | ParameterPathBuilder): void; /** * Gets all parameters with paths starting with the specified path * @param path The path to get parameters from * @returns A parameters dictionary of parameter names, and paths starting by * the specified path. */ getPathParameters(path: ParameterPath | ParameterPathBuilder): ParametersDict; /** * Adds and removes parameters from parameterized object. * * If the parameterized object has `Parameter<T>` value, and there's no parameter at the * parameter's property path - then a new parameter is added. * If the parameterized object has simple property at the path where existing * parameter contained - the parameter is removed. * @returns The unparameterized object. */ setParametersFrom<T extends object>({ root, parameterized, valueSetter, defaultParameterValue, }: SetParametersFromParams<T>): T; } /** * setParametersFromParams parameters */ export interface SetParametersFromParams<T extends object> { /** * The root path, representing the provided object's root */ root: ParameterPath | ParameterPathBuilder; /** * The parameterized object. */ parameterized: Readonly<Parameterized<T>>; /** * Optional setter for the result. \ * Let you process the result, **before** the parameters from it are set. */ valueSetter?: (unparameterized: T) => void; /** * Optional default value value to set instead of the parameter * @param path The path to get default value for * @returns A default value or undefined */ defaultParameterValue?: (path: ParameterPathBuilder) => any; }