From 3f27dc89d8de478acb3ecd3882d5addfb1086304 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Wed, 23 Jun 2021 22:27:13 +0100 Subject: [PATCH] Add overloads for context/flow/global set/get/keys --- .../src/types/node-red/func.d.ts | 207 ++++++++++++++++-- 1 file changed, 190 insertions(+), 17 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/types/node-red/func.d.ts b/packages/node_modules/@node-red/editor-client/src/types/node-red/func.d.ts index 3c3ee7849..f2a1364c0 100644 --- a/packages/node_modules/@node-red/editor-client/src/types/node-red/func.d.ts +++ b/packages/node_modules/@node-red/editor-client/src/types/node-red/func.d.ts @@ -64,28 +64,201 @@ declare class node { public readonly outputCount:number; } declare class context { - /** Get a value from context */ - static get(name:string, store?:string); - /** Store a value in context */ - static set(name:string, value:any, store?:string); + /** + * Get one or multiple values from context (synchronous). + * @param name - Name of context variable + */ + static get(name: string | string[]); + /** + * Get one or multiple values from context (asynchronous). + * @param name - Name (or array of names) to get from context + * @param {function} callback - (optional) Callback function (`(err,value) => {}`) + */ + static get(name: string | string[], callback: Function); + /** + * Get one or multiple values from context (synchronous). + * @param name - Name (or array of names) to get from context + * @param store - Name of context store + */ + static get(name: string | string[], store: string); + /** + * Get one or multiple values from context (asynchronous). + * @param name - Name (or array of names) to get from context + * @param store - Name of context store + * @param {function} callback - (optional) Callback function (`(err,value) => {}`) + */ + static get(name: string | string[], store: string, callback: Function); + + + /** + * Set one or multiple values in context (synchronous). + * @param name - Name (or array of names) to set in context + * @param value - The value (or array of values) to store in context. If the value(s) are null/undefined, the context item(s) will be removed. + */ + static set(name: string | string[], value?: any | any[]); + /** + * Set one or multiple values in context (asynchronous). + * @param name - Name (or array of names) to set in context + * @param value - The value (or array of values) to store in context. If the value(s) are null/undefined, the context item(s) will be removed. + * @param callback - (optional) Callback function (`(err) => {}`) + */ + static set(name: string | string[], value?: any | any[], callback?: Function); + /** + * Set one or multiple values in context (synchronous). + * @param name - Name (or array of names) to set in context + * @param value - The value (or array of values) to store in context. If the value(s) are null/undefined, the context item(s) will be removed. + * @param store - (optional) Name of context store + */ + static set(name: string | string[], value?: any | any[], store?: string); + /** + * Set one or multiple values in context (asynchronous). + * @param name - Name (or array of names) to set in context + * @param value - The value (or array of values) to store in context. If the value(s) are null/undefined, the context item(s) will be removed. + * @param store - (optional) Name of context store + * @param callback - (optional) Callback function (`(err) => {}`) + */ + static set(name: string | string[], value?: any | any[], store?: string, callback?: Function); + /** Get an array of the keys in the context store */ - static keys(store?:string):Array ; + static keys(): Array; + /** Get an array of the keys in the context store */ + static keys(store: string): Array; + /** Get an array of the keys in the context store */ + static keys(callback: Function); + /** Get an array of the keys in the context store */ + static keys(store: string, callback: Function); } declare class flow { - /** Get a value from flow context */ - static get(name:string, store?:string); - /** Store a value in flow context */ - static set(name:string, value:any, store?:string); - /** Get an array of the keys in the flow context store */ - static keys(store?:string):Array ; + /** + * Get one or multiple values from context (synchronous). + * @param name - Name of context variable + */ + static get(name: string | string[]); + /** + * Get one or multiple values from context (asynchronous). + * @param name - Name (or array of names) to get from context + * @param {function} callback - (optional) Callback function (`(err,value) => {}`) + */ + static get(name: string | string[], callback: Function); + /** + * Get one or multiple values from context (synchronous). + * @param name - Name (or array of names) to get from context + * @param store - Name of context store + */ + static get(name: string | string[], store: string); + /** + * Get one or multiple values from context (asynchronous). + * @param name - Name (or array of names) to get from context + * @param store - Name of context store + * @param {function} callback - (optional) Callback function (`(err,value) => {}`) + */ + static get(name: string | string[], store: string, callback: Function); + + + /** + * Set one or multiple values in context (synchronous). + * @param name - Name (or array of names) to set in context + * @param value - The value (or array of values) to store in context. If the value(s) are null/undefined, the context item(s) will be removed. + */ + static set(name: string | string[], value?: any | any[]); + /** + * Set one or multiple values in context (asynchronous). + * @param name - Name (or array of names) to set in context + * @param value - The value (or array of values) to store in context. If the value(s) are null/undefined, the context item(s) will be removed. + * @param callback - (optional) Callback function (`(err) => {}`) + */ + static set(name: string | string[], value?: any | any[], callback?: Function); + /** + * Set one or multiple values in context (synchronous). + * @param name - Name (or array of names) to set in context + * @param value - The value (or array of values) to store in context. If the value(s) are null/undefined, the context item(s) will be removed. + * @param store - (optional) Name of context store + */ + static set(name: string | string[], value?: any | any[], store?: string); + /** + * Set one or multiple values in context (asynchronous). + * @param name - Name (or array of names) to set in context + * @param value - The value (or array of values) to store in context. If the value(s) are null/undefined, the context item(s) will be removed. + * @param store - (optional) Name of context store + * @param callback - (optional) Callback function (`(err) => {}`) + */ + static set(name: string | string[], value?: any | any[], store?: string, callback?: Function); + + /** Get an array of the keys in the context store */ + static keys(): Array; + /** Get an array of the keys in the context store */ + static keys(store: string): Array; + /** Get an array of the keys in the context store */ + static keys(callback: Function); + /** Get an array of the keys in the context store */ + static keys(store: string, callback: Function); } + +// @ts-ignore declare class global { - /** Get a value from global context */ - static get(name:string, store?:string); - /** Store a value in global context */ - static set(name:string, value:any, store?:string); - /** Get an array of the keys in the global context store */ - static keys(store?:string):Array ; + /** + * Get one or multiple values from context (synchronous). + * @param name - Name of context variable + */ + static get(name: string | string[]); + /** + * Get one or multiple values from context (asynchronous). + * @param name - Name (or array of names) to get from context + * @param {function} callback - (optional) Callback function (`(err,value) => {}`) + */ + static get(name: string | string[], callback: Function); + /** + * Get one or multiple values from context (synchronous). + * @param name - Name (or array of names) to get from context + * @param store - Name of context store + */ + static get(name: string | string[], store: string); + /** + * Get one or multiple values from context (asynchronous). + * @param name - Name (or array of names) to get from context + * @param store - Name of context store + * @param {function} callback - (optional) Callback function (`(err,value) => {}`) + */ + static get(name: string | string[], store: string, callback: Function); + + + /** + * Set one or multiple values in context (synchronous). + * @param name - Name (or array of names) to set in context + * @param value - The value (or array of values) to store in context. If the value(s) are null/undefined, the context item(s) will be removed. + */ + static set(name: string | string[], value?: any | any[]); + /** + * Set one or multiple values in context (asynchronous). + * @param name - Name (or array of names) to set in context + * @param value - The value (or array of values) to store in context. If the value(s) are null/undefined, the context item(s) will be removed. + * @param callback - (optional) Callback function (`(err) => {}`) + */ + static set(name: string | string[], value?: any | any[], callback?: Function); + /** + * Set one or multiple values in context (synchronous). + * @param name - Name (or array of names) to set in context + * @param value - The value (or array of values) to store in context. If the value(s) are null/undefined, the context item(s) will be removed. + * @param store - (optional) Name of context store + */ + static set(name: string | string[], value?: any | any[], store?: string); + /** + * Set one or multiple values in context (asynchronous). + * @param name - Name (or array of names) to set in context + * @param value - The value (or array of values) to store in context. If the value(s) are null/undefined, the context item(s) will be removed. + * @param store - (optional) Name of context store + * @param callback - (optional) Callback function (`(err) => {}`) + */ + static set(name: string | string[], value?: any | any[], store?: string, callback?: Function); + + /** Get an array of the keys in the context store */ + static keys(): Array; + /** Get an array of the keys in the context store */ + static keys(store: string): Array; + /** Get an array of the keys in the context store */ + static keys(callback: Function); + /** Get an array of the keys in the context store */ + static keys(store: string, callback: Function); } declare class env { /** Get an environment variable value */