@iobroker/types 5.0.0-alpha.0-20221217-d87d529d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts ADDED
@@ -0,0 +1,489 @@
1
+ // Type definitions for ioBroker 4.0
2
+ // Project: https://github.com/ioBroker/ioBroker, http://iobroker.net
3
+ // Definitions by: AlCalzone <https://github.com/AlCalzone>
4
+ // Definitions: https://github.com/iobroker/iobroker.js-controller
5
+ // TypeScript Version: 4.5
6
+
7
+ // Note: This is not the definition for the package `iobroker`,
8
+ // which is just an installer, not a library.
9
+ // The definitions may change with updates to ioBroker.js-controller
10
+
11
+ /// <reference types="node" />
12
+ // eslint-disable-next-line @typescript-eslint/triple-slash-reference
13
+ /// <reference path="./objects.d.ts" />
14
+
15
+ import { AdapterClass, AdapterOptions as _AdapterOptions } from './build/types';
16
+ import * as fs from 'fs';
17
+ export {}; // avoids exporting AtLeastOne into the global scope
18
+
19
+ // Requires at least one of the properties of T to be given, whether it's optional or not
20
+ type AtLeastOne<T, Req = { [K in keyof T]-?: T[K] }, Opt = { [K in keyof T]+?: T[K] }> = {
21
+ [K in keyof Req]: Omit<Opt, K> & { [P in K]: Req[P] };
22
+ }[keyof Req];
23
+
24
+ declare global {
25
+ namespace ioBroker {
26
+ enum StateQuality {
27
+ good = 0x00, // or undefined or null
28
+ bad = 0x01,
29
+ general_problem = 0x01,
30
+ general_device_problem = 0x41,
31
+ general_sensor_problem = 0x81,
32
+ device_not_connected = 0x42,
33
+ sensor_not_connected = 0x82,
34
+ device_reports_error = 0x44,
35
+ sensor_reports_error = 0x84
36
+ }
37
+
38
+ type StateValue = string | number | boolean | null;
39
+
40
+ interface State {
41
+ /** The value of the state. */
42
+ val: StateValue;
43
+
44
+ /** Direction flag: false for desired value and true for actual value. Default: false. */
45
+ ack: boolean;
46
+
47
+ /** Unix timestamp. Default: current time */
48
+ ts: number;
49
+
50
+ /** Unix timestamp of the last time the value changed */
51
+ lc: number;
52
+
53
+ /** Name of the adapter instance which set the value, e.g. "system.adapter.web.0" */
54
+ from: string;
55
+
56
+ /** The user who set this value */
57
+ user?: string;
58
+
59
+ /** Optional time in seconds after which the state is reset to null */
60
+ expire?: number;
61
+
62
+ /** Optional quality of the state value */
63
+ q?: StateQuality;
64
+
65
+ /** Optional comment */
66
+ c?: string;
67
+ }
68
+
69
+ type SettableState = AtLeastOne<State>;
70
+
71
+ type Session = any; // TODO: implement
72
+
73
+ /** Defines access rights for a single object type */
74
+ interface ObjectOperationPermissions {
75
+ /** Whether a user may enumerate objects of this type */
76
+ list: boolean;
77
+ /** Whether a user may read objects of this type */
78
+ read: boolean;
79
+ /** Whether a user may write objects of this type */
80
+ write: boolean;
81
+ /** Whether a user may create objects of this type */
82
+ create: boolean;
83
+ /** Whether a user may delete objects of this type */
84
+ delete: boolean;
85
+ }
86
+
87
+ /** Defines the rights a user or group has to change objects */
88
+ interface ObjectPermissions {
89
+ /** The access rights for files */
90
+ file: ObjectOperationPermissions;
91
+ /** The access rights for objects */
92
+ object: ObjectOperationPermissions;
93
+ /** The access rights for users/groups */
94
+ users: ObjectOperationPermissions;
95
+ /** The access rights for states */
96
+ state?: ObjectOperationPermissions;
97
+ }
98
+ /** Defined the complete set of access rights a user has */
99
+ interface PermissionSet extends ObjectPermissions {
100
+ /** The name of the user this ACL is for */
101
+ user: string;
102
+ /** The name of the groups this ACL was merged from */
103
+ groups: string[];
104
+ /** The access rights for certain commands */
105
+ other: {
106
+ execute: boolean;
107
+ http: boolean;
108
+ sendto: boolean;
109
+ };
110
+ }
111
+
112
+ interface Permission {
113
+ /** The type of the permission */
114
+ type: string;
115
+ /** Which kind of operation is required */
116
+ operation: string;
117
+ }
118
+ interface ObjectOrStatePermission extends Permission {
119
+ type: 'object' | 'file' | 'users' | 'state';
120
+ operation: 'list' | 'read' | 'write' | 'create' | 'delete';
121
+ }
122
+ interface OtherPermission extends Permission {
123
+ type: 'other';
124
+ operation: 'execute' | 'http' | 'sendto';
125
+ }
126
+ interface CommandsPermissions {
127
+ // TODO: Are all properties required or is a partial object ok?
128
+ getObject: ObjectOrStatePermission;
129
+ getObjects: ObjectOrStatePermission;
130
+ getObjectView: ObjectOrStatePermission;
131
+ setObject: ObjectOrStatePermission;
132
+ subscribeObjects: ObjectOrStatePermission;
133
+ unsubscribeObjects: ObjectOrStatePermission;
134
+ getStates: ObjectOrStatePermission;
135
+ getState: ObjectOrStatePermission;
136
+ setState: ObjectOrStatePermission;
137
+ getStateHistory: ObjectOrStatePermission;
138
+ subscribe: ObjectOrStatePermission;
139
+ unsubscribe: ObjectOrStatePermission;
140
+ getVersion: Permission;
141
+ httpGet: OtherPermission;
142
+ sendTo: OtherPermission;
143
+ sendToHost: OtherPermission;
144
+ readFile: ObjectOrStatePermission;
145
+ readFile64: ObjectOrStatePermission;
146
+ writeFile: ObjectOrStatePermission;
147
+ writeFile64: ObjectOrStatePermission;
148
+ unlink: ObjectOrStatePermission;
149
+ rename: ObjectOrStatePermission;
150
+ mkdir: ObjectOrStatePermission;
151
+ readDir: ObjectOrStatePermission;
152
+ chmodFile: ObjectOrStatePermission;
153
+ authEnabled: Permission;
154
+ disconnect: Permission;
155
+ listPermissions: Permission;
156
+ getUserPermissions: ObjectOrStatePermission;
157
+ }
158
+
159
+ type UserGroup = any; // TODO find out how this looks like
160
+ // interface UserGroup { }
161
+
162
+ /** Contains information about a user */
163
+ interface User {
164
+ /** Which groups this user belongs to */
165
+ groups: UserGroup[];
166
+ /** Access rights of this user */
167
+ acl: ObjectPermissions;
168
+ }
169
+
170
+ /** Parameters for adapter.getObjectView */
171
+ interface GetObjectViewParams {
172
+ /** First id to include in the return list */
173
+ startkey?: string;
174
+ /** Last id to include in the return list */
175
+ endkey?: string;
176
+ /** Whether docs should be included in the return list */ // TODO: What are docs?
177
+ include_docs?: boolean;
178
+ }
179
+
180
+ /** Parameters for adapter.getObjectList */
181
+ type GetObjectListParams = GetObjectViewParams;
182
+
183
+ type LogLevel = 'silly' | 'debug' | 'info' | 'warn' | 'error';
184
+ interface Logger {
185
+ /** log message with silly level */
186
+ silly(message: string): void;
187
+ /** log message with debug level */
188
+ debug(message: string): void;
189
+ /** log message with info level (default output level for all adapters) */
190
+ info(message: string): void;
191
+ /** log message with warning severity */
192
+ warn(message: string): void;
193
+ /** log message with error severity */
194
+ error(message: string): void;
195
+
196
+ /** Verbosity of the log output */
197
+ level: LogLevel;
198
+ }
199
+
200
+ interface Certificates {
201
+ /** private key file */
202
+ key: string | Buffer;
203
+ /** public certificate */
204
+ cert: string | Buffer;
205
+ /** chained CA certificates */
206
+ ca: Array<string | Buffer>;
207
+ }
208
+
209
+ type MessagePayload = string | Record<string, any>;
210
+
211
+ /** Callback information for a passed message */
212
+ interface MessageCallbackInfo {
213
+ /** The original message payload */
214
+ message: MessagePayload;
215
+ /** ID of this callback */
216
+ id: number;
217
+ // ???
218
+ ack: boolean;
219
+ /** Timestamp of this message */
220
+ time: number;
221
+ }
222
+
223
+ /** A message being passed between adapter instances */
224
+ interface Message {
225
+ /** The command to be executed */
226
+ command: string;
227
+ /** The message payload */
228
+ message: MessagePayload;
229
+ /** The source of this message */
230
+ from: string;
231
+ /** ID of this message */
232
+ _id: number;
233
+ /** Callback information. This is set when the source expects a response */
234
+ callback: MessageCallbackInfo;
235
+ }
236
+
237
+ type Log = any; // TODO: define this https://github.com/ioBroker/ioBroker.js-controller/blob/master/lib/states/statesInMemServer.js#L873
238
+
239
+ type EnumList = string | string[];
240
+
241
+ type Enum = any; // TODO: implement this
242
+
243
+ type Plugin = Record<string, any>; // TODO: Add definition
244
+
245
+ interface DirectoryEntry {
246
+ file: string;
247
+ stats: fs.Stats;
248
+ isDir: boolean;
249
+ acl: any; // access control list object
250
+ modifiedAt: number;
251
+ createdAt: number;
252
+ }
253
+
254
+ interface GetHistoryOptions {
255
+ instance?: string;
256
+ start?: number;
257
+ end?: number;
258
+ step?: number;
259
+ count?: number;
260
+ from?: boolean;
261
+ ack?: boolean;
262
+ q?: boolean;
263
+ addID?: boolean;
264
+ limit?: number;
265
+ ignoreNull?: boolean;
266
+ sessionId?: any;
267
+ aggregate?: 'minmax' | 'min' | 'max' | 'average' | 'total' | 'count' | 'none';
268
+ }
269
+
270
+ interface DelObjectOptions {
271
+ /** Whether all child objects should be deleted aswell */
272
+ recursive?: boolean;
273
+ // Allow non-documented properties
274
+ [other: string]: unknown;
275
+ }
276
+
277
+ interface ExtendObjectOptionsPreserve {
278
+ [prop: string]: ExtendObjectOptionsPreserve | boolean | string[];
279
+ }
280
+
281
+ interface ExtendObjectOptions {
282
+ /** Which properties of the original object should be preserved */
283
+ preserve?: ExtendObjectOptionsPreserve;
284
+ // Allow non-documented properties
285
+ [other: string]: unknown;
286
+ }
287
+
288
+ /** Predefined notification scopes and their categories */
289
+ interface NotificationScopes {
290
+ system:
291
+ | 'memIssues'
292
+ | 'fsIoErrors'
293
+ | 'noDiskSpace'
294
+ | 'accessErrors'
295
+ | 'nonExistingFileErrors'
296
+ | 'remoteHostErrors'
297
+ | 'restartLoop'
298
+ | 'fileToJsonl';
299
+ }
300
+
301
+ type AdapterOptions = _AdapterOptions;
302
+
303
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
304
+ interface AdapterConfig {
305
+ // This is a stub to be augmented in every adapter
306
+ }
307
+
308
+ type Adapter = AdapterClass;
309
+
310
+ type ReadyHandler = () => void | Promise<void>;
311
+ type ObjectChangeHandler = (id: string, obj: ioBroker.Object | null | undefined) => void | Promise<void>;
312
+ type StateChangeHandler = (id: string, obj: State | null | undefined) => void | Promise<void>;
313
+ type MessageHandler = (obj: Message) => void | Promise<void>;
314
+ type UnloadHandler = (callback: EmptyCallback) => void | Promise<void>;
315
+ type ErrorHandler = (err: Error) => boolean;
316
+
317
+ type EmptyCallback = () => void;
318
+ type ErrorCallback = (err?: Error | null) => void;
319
+ /** Special variant of ErrorCallback for methods where Node.js returns an ErrnoException */
320
+ type ErrnoCallback = (err?: NodeJS.ErrnoException | null) => void;
321
+ // TODO: Redefine callbacks as subclass of GenericCallback
322
+ type GenericCallback<T> = (err?: Error | null, result?: T) => void;
323
+
324
+ type MessageCallback = (response?: Message) => void;
325
+
326
+ type SetObjectCallback = (err?: Error | null, obj?: { id: string }) => void;
327
+ type SetObjectPromise = Promise<NonNullCallbackReturnTypeOf<SetObjectCallback>>;
328
+
329
+ type GetObjectCallback<T extends string = string> = (
330
+ err?: Error | null,
331
+ obj?: ObjectIdToObjectType<T> | null
332
+ ) => void;
333
+ type GetObjectPromise<T extends string = string> = Promise<CallbackReturnTypeOf<GetObjectCallback<T>>>;
334
+
335
+ type GetEnumCallback = (err?: Error | null, enums?: Record<string, Enum>, requestedEnum?: string) => void;
336
+ type GetEnumsCallback = (
337
+ err?: Error | null,
338
+ result?: {
339
+ [groupName: string]: Record<string, Enum>;
340
+ }
341
+ ) => void;
342
+ type GetEnumsPromise = Promise<NonNullCallbackReturnTypeOf<GetEnumsCallback>>;
343
+
344
+ type GetObjectsCallback = (err?: Error | null, objects?: Record<string, ioBroker.Object>) => void;
345
+ type GetObjectsPromise = Promise<NonNullCallbackReturnTypeOf<GetObjectsCallback>>;
346
+
347
+ type GetObjectsCallbackTyped<T extends ObjectType> = (
348
+ err?: Error | null,
349
+ objects?: Record<string, ioBroker.AnyObject & { type: T }>
350
+ ) => void;
351
+ type GetObjectsPromiseTyped<T extends ObjectType> = Promise<
352
+ NonNullCallbackReturnTypeOf<GetObjectsCallbackTyped<T>>
353
+ >;
354
+
355
+ type FindObjectCallback = (
356
+ /** If an error happened, this contains the message */
357
+ err?: Error | null,
358
+ /** If an object was found, this contains the ID */
359
+ id?: string,
360
+ /** If an object was found, this contains the common.name */
361
+ name?: StringOrTranslated
362
+ ) => void;
363
+
364
+ // This is a version used by GetDevices/GetChannelsOf/GetStatesOf
365
+ type GetObjectsCallback3<T extends BaseObject> = (err?: Error | null, result?: T[]) => void;
366
+
367
+ type SecondParameterOf<T extends (...args: any[]) => any> = T extends (
368
+ arg0: any,
369
+ arg1: infer R,
370
+ ...args: any[]
371
+ ) => any
372
+ ? R
373
+ : never;
374
+ /** Infers the return type from a callback-style API and strips out null and undefined */
375
+ type NonNullCallbackReturnTypeOf<T extends (...args: any[]) => any> = Exclude<
376
+ SecondParameterOf<T>,
377
+ null | undefined
378
+ >;
379
+ /** Infers the return type from a callback-style API and and leaves null and undefined in */
380
+ type CallbackReturnTypeOf<T extends (...args: any[]) => any> = SecondParameterOf<T>;
381
+
382
+ type GetStateCallback = (err: Error | null, state?: State | null) => void;
383
+ type GetStatePromise = Promise<CallbackReturnTypeOf<GetStateCallback>>;
384
+
385
+ type GetStatesCallback = (err: Error | null, states?: Record<string, State>) => void;
386
+ type GetStatesPromise = Promise<NonNullCallbackReturnTypeOf<GetStatesCallback>>;
387
+
388
+ type GetBinaryStateCallback = (err?: Error | null, state?: Buffer) => void;
389
+ type GetBinaryStatePromise = Promise<CallbackReturnTypeOf<GetBinaryStateCallback>>;
390
+
391
+ type SetStateCallback = (err?: Error | null, id?: string) => void;
392
+ type SetStatePromise = Promise<NonNullCallbackReturnTypeOf<SetStateCallback>>;
393
+
394
+ type SetStateChangedCallback = (err?: Error | null, id?: string, notChanged?: boolean) => void;
395
+ type SetStateChangedPromise = Promise<NonNullCallbackReturnTypeOf<SetStateChangedCallback>>;
396
+
397
+ type DeleteStateCallback = (err?: Error | null, id?: string) => void;
398
+
399
+ type GetHistoryResult = Array<State & { id?: string }>;
400
+ type GetHistoryCallback = (
401
+ err: Error | null,
402
+ result?: GetHistoryResult,
403
+ step?: number,
404
+ sessionId?: string
405
+ ) => void;
406
+
407
+ /** Contains the return values of readDir */
408
+ interface ReadDirResult {
409
+ /** Name of the file or directory */
410
+ file: string;
411
+ /** File system stats */
412
+ stats: Partial<fs.Stats>;
413
+ /** Whether this is a directory or a file */
414
+ isDir: boolean;
415
+ /** Access rights */
416
+ acl?: EvaluatedFileACL;
417
+ /** Date of last modification */
418
+ modifiedAt?: number;
419
+ /** Date of creation */
420
+ createdAt?: number;
421
+ }
422
+ type ReadDirCallback = (err?: NodeJS.ErrnoException | null, entries?: ReadDirResult[]) => void;
423
+ type ReadDirPromise = Promise<NonNullCallbackReturnTypeOf<ReadDirCallback>>;
424
+
425
+ type ReadFileCallback = (err?: NodeJS.ErrnoException | null, data?: Buffer | string, mimeType?: string) => void;
426
+ type ReadFilePromise = Promise<{ data: string | Buffer; mimeType?: string }>;
427
+
428
+ /** Contains the return values of chownFile */
429
+ interface ChownFileResult {
430
+ /** The parent directory of the processed file or directory */
431
+ path: string;
432
+ /** Name of the file or directory */
433
+ file: string;
434
+ /** File system stats */
435
+ stats: fs.Stats;
436
+ /** Whether this is a directory or a file */
437
+ isDir: boolean;
438
+ /** Access rights */
439
+ acl: FileACL;
440
+ /** Date of last modification */
441
+ modifiedAt: number;
442
+ /** Date of creation */
443
+ createdAt: number;
444
+ }
445
+ type ChownFileCallback = (err?: NodeJS.ErrnoException | null, processed?: ChownFileResult[]) => void;
446
+
447
+ /** Contains the return values of rm */
448
+ interface RmResult {
449
+ /** The parent directory of the deleted file or directory */
450
+ path: string;
451
+ /** The name of the deleted file or directory */
452
+ file: string;
453
+ }
454
+ type RmCallback = (err?: NodeJS.ErrnoException | null, entries?: RmResult[]) => void;
455
+
456
+ type ChownObjectCallback = (err?: NodeJS.ErrnoException | null, list?: ioBroker.Object[]) => void;
457
+
458
+ type GetConfigKeysCallback = (err?: Error | null, list?: string[]) => void;
459
+
460
+ interface GetObjectViewItem<T> {
461
+ /** The ID of this object */
462
+ id: string;
463
+ /** A copy of the object from the DB */
464
+ value: T | null;
465
+ }
466
+ type GetObjectViewCallback<T> = (err?: Error | null, result?: { rows: Array<GetObjectViewItem<T>> }) => void;
467
+ type GetObjectViewPromise<T> = Promise<NonNullCallbackReturnTypeOf<GetObjectViewCallback<T>>>;
468
+
469
+ interface GetObjectListItem extends GetObjectViewItem<ioBroker.Object> {
470
+ /** A copy of the object */
471
+ value: ioBroker.Object;
472
+ /** The same as @link{value} */
473
+ doc: ioBroker.Object;
474
+ }
475
+ type GetObjectListCallback = (err?: Error | null, result?: { rows: GetObjectListItem[] }) => void;
476
+ type GetObjectListPromise = Promise<NonNullCallbackReturnTypeOf<GetObjectListCallback>>;
477
+
478
+ type ExtendObjectCallback = (
479
+ err?: Error | null,
480
+ result?: { id: string; value: ioBroker.Object },
481
+ id?: string
482
+ ) => void;
483
+
484
+ type GetSessionCallback = (session: Session) => void;
485
+
486
+ type Timeout = number & { __ioBrokerBrand: 'Timeout' };
487
+ type Interval = number & { __ioBrokerBrand: 'Interval' };
488
+ } // end namespace ioBroker
489
+ } // end declare global