11interface NodeMessage {
22 topic ?: string ;
33 payload ?: any ;
4- _msgid ?: string ;
4+ /** `_msgid` is generated internally. It not something you typically need to set or modify. */ _msgid ?: string ;
55 [ other : string ] : any ; //permit other properties
66}
77
@@ -16,15 +16,15 @@ declare const promisify:typeof import('util').promisify
1616/**
1717 * @typedef NodeStatus
1818 * @type {object }
19- * @property {string } [fill] The fill property can be: red, green, yellow, blue or grey.
20- * @property {string } [shape] The shape property can be: ring or dot.
21- * @property {string } [text] The text to display
19+ * @property {'red'|'green'|'yellow'|'blue'|'grey'| string } [fill] - The fill property can be: red, green, yellow, blue or grey.
20+ * @property {'ring'|'dot'| string } [shape] The shape property can be: ring or dot.
21+ * @property {string|boolean|number } [text] The text to display
2222 */
2323interface NodeStatus {
2424 /** The fill property can be: red, green, yellow, blue or grey */
25- fill ?: string ,
25+ fill ?: 'red' | 'green' | 'yellow' | 'blue' | 'grey' | string ,
2626 /** The shape property can be: ring or dot */
27- shape ?: string ,
27+ shape ?: 'ring' | 'dot' | string ,
2828 /** The text to display */
2929 text ?: string | boolean | number
3030}
@@ -34,25 +34,24 @@ declare class node {
3434 * Send 1 or more messages asynchronously
3535 * @param {object | object[] } msg The msg object
3636 * @param {Boolean } [clone=true] Flag to indicate the `msg` should be cloned. Default = `true`
37- * @see node-red documentation [writing-functions: sending messages asynchronously](https://nodered.org/docs/user-guide/writing-functions#sending-messages-asynchronously)
37+ * @see Node-RED documentation [writing-functions: sending messages asynchronously](https://nodered.org/docs/user-guide/writing-functions#sending-messages-asynchronously)
3838 */
39- static send ( msg :object | object [ ] , clone ?:Boolean ) : void ;
39+ static send ( msg :NodeMessage | NodeMessage [ ] , clone ?:Boolean ) : void ;
4040 /** Inform runtime this instance has completed its operation */
4141 static done ( ) ;
4242 /** Send an error to the console and debug side bar. Include `msg` in the 2nd parameter to trigger the catch node. */
43- static error ( err :string | Error , msg ?:object ) ;
43+ static error ( err :string | Error , msg ?:NodeMessage ) ;
4444 /** Log a warn message to the console and debug sidebar */
4545 static warn ( warning :string | object ) ;
4646 /** Log an info message to the console (not sent to sidebar)' */
4747 static log ( info :string | object ) ;
4848 /** Sets the status icon and text underneath the node.
4949 * @param {NodeStatus } status - The status object `{fill, shape, text}`
50- * @see node-red documentation [writing-functions: adding-status](https://nodered.org/docs/user-guide/writing-functions#adding-status)
50+ * @see Node-RED documentation [writing-functions: adding-status](https://nodered.org/docs/user-guide/writing-functions#adding-status)
5151 */
5252 static status ( status :NodeStatus ) ;
5353 /** Sets the status text underneath the node.
54- * @param {string } status - The status to display
55- * @see node-red documentation [writing-functions: adding-status](https://nodered.org/docs/user-guide/writing-functions#adding-status)
54+ * @see Node-RED documentation [writing-functions: adding-status](https://nodered.org/docs/user-guide/writing-functions#adding-status)
5655 */
5756 static status ( status :string | boolean | number ) ;
5857 /** the id of this node */
@@ -261,9 +260,12 @@ declare class global {
261260 /** Get an array of the keys in the context store */
262261 static keys ( store : string , callback : Function ) ;
263262}
263+
264+ // (string & {}) is a workaround for offering string type completion without enforcing it. See https://github.com/microsoft/TypeScript/issues/29729#issuecomment-567871939
265+ type NR_ENV_NAME_STRING = 'NR_NODE_ID' | 'NR_NODE_NAME' | 'NR_NODE_PATH' | 'NR_GROUP_ID' | 'NR_GROUP_NAME' | 'NR_FLOW_ID' | 'NR_FLOW_NAME' | 'NR_SUBFLOW_ID' | 'NR_SUBFLOW_NAME' | 'NR_SUBFLOW_PATH' | ( string & { } )
264266declare class env {
265267 /**
266- * Get an environment variable value
268+ * Get an environment variable value defined in the OS, or in the global/flow/subflow/group environment variables.
267269 *
268270 * Predefined node-red variables...
269271 * * `NR_NODE_ID` - the ID of the node
@@ -273,9 +275,16 @@ declare class env {
273275 * * `NR_GROUP_NAME` - the Name of the containing group
274276 * * `NR_FLOW_ID` - the ID of the flow the node is on
275277 * * `NR_FLOW_NAME` - the Name of the flow the node is on
276- * @param name Name of the environment variable to get
278+ * * `NR_SUBFLOW_ID` - the ID of the subflow the node is in
279+ * * `NR_SUBFLOW_NAME` - the Name of the subflow the node is in
280+ * * `NR_SUBFLOW_PATH` - the Path of the subflow the node is in
281+ * @param name - The name of the environment variable
282+ * @example
283+ * ```const flowName = env.get("NR_FLOW_NAME") // get the name of the flow```
284+ * @example
285+ * ```const systemHomeDir = env.get("HOME") // get the user's home directory```
277286 * @example
278- * ```const flowName = env.get("NR_FLOW_NAME"); ```
287+ * ```const systemHomeDir = env.get("LABEL1") // get the value of a global/flow/subflow/group defined variable named "LABEL1" ```
279288 */
280- static get ( name :string ) :any ;
289+ static get ( name :NR_ENV_NAME_STRING ) :any ;
281290}
0 commit comments