UNPKG

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