/** * @file Shared runtime helpers for the Node-RED nodes in this package. * * Keep this module deliberately small and dependency-free. The helpers here are * the cross-node primitives that must behave identically in `lsh-logic`, * `lsh-actuator-sync` and `lsh-external-state`: context selection, Node-RED * status shapes, defensive config normalization and boolean state parsing. */ import type { Node, NodeAPI, NodeMessage } from "node-red"; /** Node-RED context stores supported by these nodes. */ export type ContextName = "flow" | "global"; /** Read-only view used when a node only needs to inspect context. */ export type ContextReader = { get(key: string): unknown; }; /** Read/write view used by helpers that persist state into context. */ export type ContextStore = ContextReader & { set(key: string, value: unknown): void; }; /** Compact status shape accepted by `node.status`. */ export type StatusShape = { fill: "red" | "green" | "yellow" | "blue" | "grey"; shape: "dot" | "ring"; text: string; }; /** Node-RED 1.0+ input `send` callback shape used by synchronous helpers. */ export type SendFunction = (msg: NodeMessage | Array) => void; /** Node-RED 1.0+ input `done` callback shape used by synchronous helpers. */ export type DoneFunction = (err?: Error) => void; /** Minimal shape required by `clearPendingTimers`. */ type PendingWithTimer = { timer?: ReturnType; }; /** Conservative boolean text values shared by LSH command-facing helpers. */ export declare const BASIC_TRUE_TEXT_VALUES: readonly ["1", "true", "on", "yes"]; /** Conservative boolean text values shared by LSH command-facing helpers. */ export declare const BASIC_FALSE_TEXT_VALUES: readonly ["0", "false", "off", "no"]; /** * Normalizes a required string-like config value and rejects empty values early. */ export declare const normalizeRequiredString: (value: unknown, fieldName: string) => string; /** * Normalizes an optional string-like value; blank and unsupported values become undefined. */ export declare const normalizeOptionalString: (value: unknown) => string | undefined; /** * Normalizes message identifiers where booleans would be accidental, not useful. */ export declare const normalizeMessageString: (value: unknown) => string | undefined; /** * Validates a context-store selector from the Node-RED editor. */ export declare const normalizeContextName: (value: unknown, fieldName: string) => ContextName; /** * Normalizes checkbox-like editor values while preserving explicit defaults. */ export declare const normalizeBoolean: (value: unknown, defaultValue: boolean) => boolean; /** * Normalizes a numeric editor field that cannot be negative. */ export declare const normalizeNonNegativeNumber: (value: unknown, fieldName: string, defaultValue: number) => number; /** * Checks that an unknown value is a plain object record, not null or an array. */ export declare const isObjectRecord: (value: unknown) => value is Record; /** * Normalizes a token before matching it against configured boolean text values. */ export declare const normalizeStateToken: (value: string, caseSensitive: boolean) => string; /** * Parses comma/newline-separated text values into a normalized lookup set. */ export declare const parseBooleanTextSet: (value: unknown, defaultValues: readonly string[], caseSensitive: boolean) => ReadonlySet; /** * Normalizes external/device state values to a boolean without guessing. */ export declare const normalizeBooleanState: (value: unknown, options: { trueValues: ReadonlySet; falseValues: ReadonlySet; caseSensitive?: boolean; invert?: boolean; }) => boolean | undefined; /** * Human-readable on/off text used in statuses across helper nodes. */ export declare const formatState: (state: boolean) => string; /** * Reads a Node-RED message property using the runtime utility implementation. */ export declare const readMessageProperty: (red: NodeAPI, msg: NodeMessage, propertyPath: string) => unknown; /** * Selects a flow/global context store from a Node-RED node instance. */ export declare const getNodeContext: (node: Node, contextName: ContextName) => ContextStore; /** * Clears timer-backed pending work and empties the owning map. */ export declare const clearPendingTimers: (pendingItems: Map) => void; /** * Emits a Node-RED warning and status for intentionally skipped input. */ export declare const warnAndSetStatus: (node: Node, warning: string, status: StatusShape) => null; export {}; //# sourceMappingURL=node-red-runtime.d.ts.map