UNPKG

7.35 kBTypeScriptView Raw
1// tslint:disable:no-empty-interface
2
3import { EventEmitter } from "events";
4import { Express } from "express";
5import { Server as HttpServer } from "http";
6
7import * as editorAPI from "@node-red/editor-api";
8import * as editorClient from "@node-red/editor-client";
9import * as registry from "@node-red/registry";
10import * as runtime from "@node-red/runtime";
11import * as util from "@node-red/util";
12
13declare const nodeRed: nodeRed.NodeRedApp;
14
15export = nodeRed;
16
17declare namespace nodeRed {
18 interface NodeRedApp {
19 /**
20 * Initialise the Node-RED application.
21 * @param httpServer - the HTTP server object to use
22 * @param userSettings - an object containing the runtime settings
23 */
24 init: (httpServer: HttpServer, userSettings: runtime.LocalSettings) => void;
25
26 /**
27 * Start the Node-RED application.
28 */
29 start: () => Promise<void>;
30
31 /**
32 * Stop the Node-RED application.
33 */
34 stop: () => Promise<void>;
35
36 /**
37 * Logging utilities
38 */
39 log: util.Log;
40
41 /**
42 * General utilities
43 */
44 util: util.Util;
45
46 /**
47 * This provides access to the internal nodes module of the
48 * runtime. The details of this API remain undocumented as they should not
49 * be used directly.
50 *
51 * Most administrative actions should be performed use the runtime api
52 * under @node-red/runtime.
53 */
54 readonly nodes: runtime.InternalNodesModule;
55
56 /**
57 * This provides access to the internal plugins module of the
58 * runtime. The details of this API remain undocumented as they should not
59 * be used directly.
60 *
61 * Most administrative actions should be performed use the runtime api
62 * under @node-red/runtime.
63 */
64 readonly plugins: runtime.InternalPluginsModule;
65
66 /**
67 * Runtime events emitter
68 */
69 events: EventEmitter;
70
71 /**
72 * Runtime hooks engine
73 */
74 hooks: util.Hooks;
75
76 /**
77 * This provides access to the internal settings module of the
78 * runtime.
79 */
80 readonly settings: runtime.PersistentSettings;
81
82 /**
83 * Get the version of the runtime
84 */
85 readonly version: string;
86
87 /**
88 * The express application for the Editor Admin API
89 */
90 readonly httpAdmin: Express;
91
92 /**
93 * The express application for HTTP Nodes
94 */
95 readonly httpNode: Express;
96
97 /**
98 * The HTTP Server used by the runtime
99 */
100 readonly server: HttpServer;
101
102 /**
103 * The runtime api
104 */
105 runtime: runtime.RuntimeModule;
106
107 /**
108 * The editor authentication api.
109 */
110 auth: editorAPI.Auth;
111 }
112
113 /*******************************************************************
114 * Type shortcuts for writing the runtime side of nodes (.js file)
115 *******************************************************************/
116
117 /**
118 * Type def for the functions that should be exported
119 * by the node .js files.
120 */
121 interface NodeInitializer<TSets extends NodeAPISettingsWithData = NodeAPISettingsWithData>
122 extends registry.NodeInitializer<TSets>
123 {}
124
125 interface NodeConstructor<TNode extends Node<TCreds>, TNodeDef extends NodeDef, TCreds extends {}>
126 extends registry.NodeConstructor<TNode, TNodeDef, TCreds>
127 {}
128
129 interface NodeAPISettingsWithData extends registry.NodeAPISettingsWithData {}
130
131 interface NodeSetting<T> extends registry.NodeSetting<T> {}
132
133 type NodeSettings<TSets> = registry.NodeSettings<TSets>;
134
135 interface NodeCredential extends registry.NodeCredential {}
136
137 type NodeCredentials<TCreds> = registry.NodeCredentials<TCreds>;
138
139 interface NodeMessage extends registry.NodeMessage {}
140
141 interface NodeMessageParts extends registry.NodeMessageParts {}
142
143 interface NodeMessageInFlow extends registry.NodeMessageInFlow {}
144
145 interface NodeAPI<TSets extends NodeAPISettingsWithData = NodeAPISettingsWithData>
146 extends registry.NodeAPI<TSets>
147 {}
148
149 interface Node<TCreds extends {} = {}> extends registry.Node<TCreds> {}
150
151 type NodeStatusFill = registry.NodeStatusFill;
152
153 type NodeStatusShape = registry.NodeStatusShape;
154
155 interface NodeStatus extends registry.NodeStatus {}
156
157 interface NodeDef extends registry.NodeDef {}
158
159 interface NodeContextData extends registry.NodeContextData {}
160
161 interface NodeContext extends registry.NodeContext {}
162
163 /********************************************************************
164 * Type shortcuts for writing the editor side of nodes (.html file)
165 ********************************************************************/
166
167 /**
168 * Property definition
169 * Read more: https://nodered.org/docs/creating-nodes/properties#property-definitions
170 */
171 interface EditorNodePropertyDef<TVal, TInstProps extends EditorNodeProperties = EditorNodeProperties>
172 extends editorClient.NodePropertyDef<TVal, TInstProps>
173 {}
174
175 /**
176 * Properties definitions (`defaults` object)
177 * Read more: https://nodered.org/docs/creating-nodes/properties
178 */
179 type EditorNodePropertiesDef<
180 TProps extends EditorNodeProperties,
181 TInstProps extends TProps = TProps,
182 > = editorClient.NodePropertiesDef<TProps, TInstProps>;
183
184 /**
185 * Node properties
186 * Read more: https://nodered.org/docs/creating-nodes/properties
187 */
188 interface EditorNodeProperties extends editorClient.NodeProperties {}
189
190 type EditorNodeInstance<TProps extends EditorNodeProperties = EditorNodeProperties> = editorClient.NodeInstance<
191 TProps
192 >;
193
194 type EditorNodeCredentials<T> = editorClient.NodeCredentials<T>;
195
196 interface EditorNodeCredential extends editorClient.NodeCredential {}
197
198 /**
199 * Node Definition
200 * Read more: https://nodered.org/docs/creating-nodes/node-html#node-definition
201 */
202 interface EditorNodeDef<
203 TProps extends EditorNodeProperties = EditorNodeProperties,
204 TCreds = undefined,
205 TInstProps extends TProps = TProps,
206 > extends editorClient.NodeDef<TProps, TCreds, TInstProps> {}
207
208 /**
209 * Type def for the global `RED` in the node .html files.
210 * Should be used to access `RED.nodes.registerType` function
211 * registering a node with the editor.
212 *
213 * Example:
214 * ```
215 * declare const RED: EditorRED;
216 *
217 * RED.nodes.registerType<
218 * MyNodeProps
219 * >("my-node", {
220 * ...
221 * })
222 * ```
223 */
224 interface EditorRED extends editorClient.RED {}
225
226 /**
227 * WIDGETS
228 */
229
230 interface EditorWidgetEditableListOptions<T> extends editorClient.WidgetEditableListOptions<T> {}
231
232 interface EditorWidgetEditableList extends editorClient.WidgetEditableList {}
233
234 interface EditorWidgetTypedInputOptions extends editorClient.WidgetTypedInputOptions {}
235
236 type EditorWidgetTypedInputType = editorClient.WidgetTypedInputType;
237
238 interface EditorWidgetTypedInputTypeDefinition extends editorClient.WidgetTypedInputTypeDefinition {}
239
240 interface EditorWidgetTypedInput extends editorClient.WidgetTypedInput {}
241}