Skip to content

Adds optional callback to env.get in function node#4227

Merged
knolleary merged 2 commits into4196-fix-jsonata-env-var-asyncfrom
4196-add-callback-opt-to-env.get
Jun 21, 2023
Merged

Adds optional callback to env.get in function node#4227
knolleary merged 2 commits into4196-fix-jsonata-env-var-asyncfrom
4196-add-callback-opt-to-env.get

Conversation

@knolleary
Copy link
Copy Markdown
Member

Adds optional callback to env.get in function node so that it can get jsonata properties in the future.

@knolleary knolleary requested a review from Steve-Mcl June 21, 2023 13:21
@Steve-Mcl
Copy link
Copy Markdown
Contributor

Looks good to me.

I would suggest we also update the function node d.ts so that editor intelisense offers the alternative sig.
packages/node_modules/@node-red/editor-client/src/types/node-red/func.d.ts

declare class env {
    /** 
     * Get an environment variable value  
     * 
     * Predefined node-red variables...  
     *   * `NR_NODE_ID` - the ID of the node
     *   * `NR_NODE_NAME` - the Name of the node
     *   * `NR_NODE_PATH` - the Path of the node
     *   * `NR_GROUP_ID` - the ID of the containing group
     *   * `NR_GROUP_NAME` - the Name of the containing group
     *   * `NR_FLOW_ID` - the ID of the flow the node is on
     *   * `NR_FLOW_NAME` - the Name of the flow the node is on
     * @param name Name of the environment variable to get
     * @example 
     * ```const flowName = env.get("NR_FLOW_NAME");```
     */
    static get(name:string) :any;
    /** 
     * Get an environment variable value (asynchronous).
     * 
     * Predefined node-red variables...  
     *   * `NR_NODE_ID` - the ID of the node
     *   * `NR_NODE_NAME` - the Name of the node
     *   * `NR_NODE_PATH` - the Path of the node
     *   * `NR_GROUP_ID` - the ID of the containing group
     *   * `NR_GROUP_NAME` - the Name of the containing group
     *   * `NR_FLOW_ID` - the ID of the flow the node is on
     *   * `NR_FLOW_NAME` - the Name of the flow the node is on
     * @param name Name of the environment variable to get
     * @param callback Callback function (`(err,value) => {}`)
     * @example 
     * ```const flowName = env.get("NR_FLOW_NAME");```
     */
    static get(name:string, callback: Function) :void;
}

I will also raise an issue to bake this into the nr monaco editor repo so we have this for future monaco version updates.

@knolleary
Copy link
Copy Markdown
Member Author

Types updated.

@knolleary knolleary merged commit b382d04 into 4196-fix-jsonata-env-var-async Jun 21, 2023
@knolleary knolleary deleted the 4196-add-callback-opt-to-env.get branch June 21, 2023 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants