@iobroker/js-controller-adapter 8.0.0-alpha.9-20261029-b65f8b5d8 → 8.0.0-beta.0
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/build/cjs/lib/_Types.d.ts +21 -0
- package/build/cjs/lib/adapter/adapter.d.ts +130 -5
- package/build/cjs/lib/adapter/adapter.js +346 -65
- package/build/cjs/lib/adapter/adapter.js.map +3 -3
- package/build/cjs/lib/adapter/asyncAdapter.d.ts +34 -2
- package/build/cjs/lib/adapter/asyncAdapter.js +68 -4
- package/build/cjs/lib/adapter/asyncAdapter.js.map +2 -2
- package/build/cjs/lib/adapter/context.d.ts +1 -1
- package/build/cjs/lib/adapter/managers/AdapterContextBase.d.ts +1 -1
- package/build/cjs/lib/adapter/managers/AdapterFileManager.d.ts +29 -0
- package/build/cjs/lib/adapter/managers/AdapterFileManager.js +264 -0
- package/build/cjs/lib/adapter/managers/AdapterFileManager.js.map +7 -0
- package/build/cjs/lib/adapter/managers/AliasManager.d.ts +3 -3
- package/build/cjs/lib/adapter/managers/AliasManager.js +2 -2
- package/build/cjs/lib/adapter/managers/CertificateManager.d.ts +2 -2
- package/build/cjs/lib/adapter/managers/CertificateManager.js +1 -1
- package/build/cjs/lib/adapter/managers/DiskFileManager.d.ts +52 -0
- package/build/cjs/lib/adapter/managers/DiskFileManager.js +187 -0
- package/build/cjs/lib/adapter/managers/DiskFileManager.js.map +7 -0
- package/build/cjs/lib/adapter/managers/HostDiskClient.d.ts +60 -0
- package/build/cjs/lib/adapter/managers/HostDiskClient.js +137 -0
- package/build/cjs/lib/adapter/managers/HostDiskClient.js.map +7 -0
- package/build/cjs/lib/adapter/managers/MessagingManager.d.ts +12 -2
- package/build/cjs/lib/adapter/managers/MessagingManager.js +19 -4
- package/build/cjs/lib/adapter/managers/MessagingManager.js.map +2 -2
- package/build/cjs/lib/adapter/managers/ResourceManager.d.ts +3 -3
- package/build/cjs/lib/adapter/managers/ResourceManager.js +1 -1
- package/build/cjs/lib/adapter/managers/SubscriptionManager.d.ts +3 -3
- package/build/cjs/lib/adapter/managers/SubscriptionManager.js +2 -2
- package/build/cjs/lib/adapter/userInterfaceMessagingController.d.ts +2 -2
- package/build/cjs/lib/adapter/utils.d.ts +0 -43
- package/build/cjs/lib/adapter/utils.js +2 -121
- package/build/cjs/lib/adapter/utils.js.map +2 -2
- package/build/cjs/lib/adapter/validator.js +1 -1
- package/build/esm/lib/_Types.d.ts +21 -0
- package/build/esm/lib/_Types.d.ts.map +1 -1
- package/build/esm/lib/adapter/adapter.d.ts +130 -5
- package/build/esm/lib/adapter/adapter.d.ts.map +1 -1
- package/build/esm/lib/adapter/adapter.js +372 -70
- package/build/esm/lib/adapter/adapter.js.map +1 -1
- package/build/esm/lib/adapter/asyncAdapter.d.ts +34 -2
- package/build/esm/lib/adapter/asyncAdapter.d.ts.map +1 -1
- package/build/esm/lib/adapter/asyncAdapter.js +68 -4
- package/build/esm/lib/adapter/asyncAdapter.js.map +1 -1
- package/build/esm/lib/adapter/context.d.ts +1 -1
- package/build/esm/lib/adapter/managers/AdapterContextBase.d.ts +1 -1
- package/build/esm/lib/adapter/managers/AdapterFileManager.d.ts +29 -0
- package/build/esm/lib/adapter/managers/AdapterFileManager.d.ts.map +1 -0
- package/build/esm/lib/adapter/managers/AdapterFileManager.js +244 -0
- package/build/esm/lib/adapter/managers/AdapterFileManager.js.map +1 -0
- package/build/esm/lib/adapter/managers/AliasManager.d.ts +3 -3
- package/build/esm/lib/adapter/managers/AliasManager.js +2 -2
- package/build/esm/lib/adapter/managers/CertificateManager.d.ts +2 -2
- package/build/esm/lib/adapter/managers/CertificateManager.js +1 -1
- package/build/esm/lib/adapter/managers/DiskFileManager.d.ts +52 -0
- package/build/esm/lib/adapter/managers/DiskFileManager.d.ts.map +1 -0
- package/build/esm/lib/adapter/managers/DiskFileManager.js +159 -0
- package/build/esm/lib/adapter/managers/DiskFileManager.js.map +1 -0
- package/build/esm/lib/adapter/managers/HostDiskClient.d.ts +60 -0
- package/build/esm/lib/adapter/managers/HostDiskClient.d.ts.map +1 -0
- package/build/esm/lib/adapter/managers/HostDiskClient.js +125 -0
- package/build/esm/lib/adapter/managers/HostDiskClient.js.map +1 -0
- package/build/esm/lib/adapter/managers/MessagingManager.d.ts +12 -2
- package/build/esm/lib/adapter/managers/MessagingManager.d.ts.map +1 -1
- package/build/esm/lib/adapter/managers/MessagingManager.js +17 -2
- package/build/esm/lib/adapter/managers/MessagingManager.js.map +1 -1
- package/build/esm/lib/adapter/managers/ResourceManager.d.ts +3 -3
- package/build/esm/lib/adapter/managers/ResourceManager.js +1 -1
- package/build/esm/lib/adapter/managers/SubscriptionManager.d.ts +3 -3
- package/build/esm/lib/adapter/managers/SubscriptionManager.js +2 -2
- package/build/esm/lib/adapter/userInterfaceMessagingController.d.ts +2 -2
- package/build/esm/lib/adapter/utils.d.ts +0 -43
- package/build/esm/lib/adapter/utils.d.ts.map +1 -1
- package/build/esm/lib/adapter/utils.js +1 -159
- package/build/esm/lib/adapter/utils.js.map +1 -1
- package/build/esm/lib/adapter/validator.js +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +17 -17
|
@@ -647,6 +647,27 @@ export interface MayReadOptions {
|
|
|
647
647
|
/** The file inside `id`, for `type: 'file'`, e.g. `main/vis-views.json` */
|
|
648
648
|
fileName?: string;
|
|
649
649
|
}
|
|
650
|
+
/** Which directory of which adapter is fetched, and where to - see `AdapterClass.fetchAdapterDir` */
|
|
651
|
+
export interface FetchAdapterDirOptions {
|
|
652
|
+
/** Name of the adapter, without `iobroker.` and without instance number, e.g. `wattcycle` */
|
|
653
|
+
adapter: string;
|
|
654
|
+
/** The directory inside the package of the adapter, separated by `/`, e.g. `widgets` */
|
|
655
|
+
path: string;
|
|
656
|
+
/** Local directory the files are written to; it is created if it does not exist */
|
|
657
|
+
target: string;
|
|
658
|
+
/**
|
|
659
|
+
* The host to fetch from. If not given, this host is taken if the adapter is installed here, else the first
|
|
660
|
+
* running host with an instance of the adapter.
|
|
661
|
+
*/
|
|
662
|
+
host?: string;
|
|
663
|
+
}
|
|
664
|
+
/** What `AdapterClass.fetchAdapterDir` fetched */
|
|
665
|
+
export interface FetchAdapterDirResult {
|
|
666
|
+
/** The host the files came from */
|
|
667
|
+
host: string;
|
|
668
|
+
/** The written files, relative to `target` and separated by `/` */
|
|
669
|
+
files: string[];
|
|
670
|
+
}
|
|
650
671
|
/** Options for sending a message to another instance */
|
|
651
672
|
export interface InternalSendToOptions {
|
|
652
673
|
/** The instance to send the message to */
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
|
+
import type { Readable } from 'node:stream';
|
|
2
3
|
import type { CommandResult } from '@alcalzone/pak';
|
|
3
|
-
import { Log } from '
|
|
4
|
-
import { STATE_QUALITY } from '
|
|
5
|
-
import type { AdapterOptions, CalculatePermissionsCallback, CheckGroupCallback, CheckPasswordCallback, CommandsPermissions, GetCertificatesCallback, GetCertificatesPromiseReturnType, GetEncryptedConfigCallback, InstallNodeModuleOptions, MaybePromise, NotificationOptions, Pattern, MayReadOptions, SendToOptions, SendToUserInterfaceClientOptions, StopParameters, SuitableLicense, TimeoutCallback } from '
|
|
4
|
+
import { Log } from './log.js';
|
|
5
|
+
import { STATE_QUALITY } from './constants.js';
|
|
6
|
+
import type { AdapterOptions, CalculatePermissionsCallback, CheckGroupCallback, CheckPasswordCallback, CommandsPermissions, GetCertificatesCallback, GetCertificatesPromiseReturnType, GetEncryptedConfigCallback, InstallNodeModuleOptions, MaybePromise, NotificationOptions, Pattern, MayReadOptions, FetchAdapterDirOptions, FetchAdapterDirResult, SendToOptions, SendToUserInterfaceClientOptions, StopParameters, SuitableLicense, TimeoutCallback } from '../_Types.js';
|
|
6
7
|
/**
|
|
7
8
|
* Here we define dynamically created methods
|
|
8
9
|
*/
|
|
@@ -313,8 +314,9 @@ export interface AdapterClass {
|
|
|
313
314
|
* @param hostName name of the host
|
|
314
315
|
* @param command command name
|
|
315
316
|
* @param message message to send
|
|
317
|
+
* @param options optional options to control the send behaviour
|
|
316
318
|
*/
|
|
317
|
-
sendToHostAsync(hostName: string, command: string, message: ioBroker.MessagePayload): Promise<ioBroker.MessagePayload>;
|
|
319
|
+
sendToHostAsync(hostName: string, command: string, message: ioBroker.MessagePayload, options?: SendToOptions): Promise<ioBroker.MessagePayload>;
|
|
318
320
|
/**
|
|
319
321
|
* Sends a message to a specific instance or all instances of some specific adapter.
|
|
320
322
|
*/
|
|
@@ -571,6 +573,8 @@ export declare class AdapterClass extends EventEmitter {
|
|
|
571
573
|
private readonly _config;
|
|
572
574
|
private readonly _options;
|
|
573
575
|
private readonly startedInCompactMode;
|
|
576
|
+
/** Name of the host this process runs on, only its controller is allowed to terminate us via sigKill */
|
|
577
|
+
private readonly localHostname;
|
|
574
578
|
/** List of instances which want our logs */
|
|
575
579
|
private readonly logList;
|
|
576
580
|
private enums;
|
|
@@ -632,6 +636,12 @@ export declare class AdapterClass extends EventEmitter {
|
|
|
632
636
|
/** contents of io-package.json */
|
|
633
637
|
ioPack: ioBroker.InstanceObject;
|
|
634
638
|
private _initializeTimeout?;
|
|
639
|
+
/** Whether the DB clients fence after a reconnect */
|
|
640
|
+
private _fenceEnabled;
|
|
641
|
+
/** `ts` of the last alive write that reached the DB, undefined if the next renewal should not check */
|
|
642
|
+
private _aliveTs;
|
|
643
|
+
/** Set if the fence terminated this instance, its unload must not run any more */
|
|
644
|
+
private _fenced;
|
|
635
645
|
private inited?;
|
|
636
646
|
/** contents of iobroker.json if required via AdapterOptions */
|
|
637
647
|
systemConfig?: InternalAdapterJsonConfig;
|
|
@@ -2024,8 +2034,9 @@ export declare class AdapterClass extends EventEmitter {
|
|
|
2024
2034
|
* @param command command name
|
|
2025
2035
|
* @param message message to send
|
|
2026
2036
|
* @param callback optional return result
|
|
2037
|
+
* @param options optional options to control the send behaviour
|
|
2027
2038
|
*/
|
|
2028
|
-
sendToHost(hostName: string | null, command: string, message: any, callback?: ioBroker.MessageCallback | ioBroker.MessageCallbackInfo): void;
|
|
2039
|
+
sendToHost(hostName: string | null, command: string, message: any, callback?: ioBroker.MessageCallback | ioBroker.MessageCallbackInfo, options?: SendToOptions): void;
|
|
2029
2040
|
/**
|
|
2030
2041
|
* Send a message to an active UI Client
|
|
2031
2042
|
*
|
|
@@ -2041,6 +2052,53 @@ export declare class AdapterClass extends EventEmitter {
|
|
|
2041
2052
|
* @param options Additional options for the notification, currently `contextData` is supported
|
|
2042
2053
|
*/
|
|
2043
2054
|
registerNotification<Scope extends keyof ioBroker.NotificationScopes>(scope: Scope, category: ioBroker.NotificationScopes[Scope] | null, message: string, options?: NotificationOptions): Promise<void>;
|
|
2055
|
+
/**
|
|
2056
|
+
* Build an `iobdisk://` URL for a file in the data directory of this instance.
|
|
2057
|
+
*
|
|
2058
|
+
* A plain file path is only valid on the host where the file is. An `iobdisk://` URL also names the host, so it
|
|
2059
|
+
* can be handed to an instance on another host, which reads the file with {@link readDiskFile} or
|
|
2060
|
+
* {@link createDiskFileReadStream}. Example: `iobdisk://pi4/telegram.0/video/2026-11-04_10-00-00.mp4`
|
|
2061
|
+
*
|
|
2062
|
+
* Only files in the data directory of the instance can be addressed: `iobroker-data/<namespace>` as
|
|
2063
|
+
* `utils.getAbsoluteInstanceDataDir()` of adapter-core gives it, or the older `iobroker-data/<adapter>_<instance>`.
|
|
2064
|
+
*
|
|
2065
|
+
* @param filePath absolute path inside the data directory of this instance, or a path relative to `iobroker-data/<namespace>`
|
|
2066
|
+
* @throws {Error} if the file is outside the data directory of this instance
|
|
2067
|
+
*/
|
|
2068
|
+
getDiskFileUrl(filePath: string): string;
|
|
2069
|
+
/**
|
|
2070
|
+
* Read the whole file an `iobdisk://` URL points to.
|
|
2071
|
+
*
|
|
2072
|
+
* A file on this host is read from the disk. A file on another host is fetched piece by piece (1 MB each) from the
|
|
2073
|
+
* js-controller of that host, which needs js-controller 8.0 or newer (feature `CONTROLLER_DISK_FILES`).
|
|
2074
|
+
* For big files prefer {@link createDiskFileReadStream}, which does not hold the whole file in memory.
|
|
2075
|
+
*
|
|
2076
|
+
* @param url e.g. `iobdisk://pi4/telegram.0/video/2026-11-04_10-00-00.mp4`
|
|
2077
|
+
* @throws {Error} if the URL is invalid, the host does not answer or is too old, or the file does not exist or changes while it is read
|
|
2078
|
+
*/
|
|
2079
|
+
readDiskFile(url: string): Promise<Buffer>;
|
|
2080
|
+
/**
|
|
2081
|
+
* Read the file an `iobdisk://` URL points to as a stream, piece by piece, from this or another host.
|
|
2082
|
+
*
|
|
2083
|
+
* The errors of {@link readDiskFile} are emitted as `error` event of the stream.
|
|
2084
|
+
*
|
|
2085
|
+
* @param url e.g. `iobdisk://pi4/telegram.0/video/2026-11-04_10-00-00.mp4`
|
|
2086
|
+
* @throws {Error} if the URL is invalid
|
|
2087
|
+
*/
|
|
2088
|
+
createDiskFileReadStream(url: string): Readable;
|
|
2089
|
+
/**
|
|
2090
|
+
* Delete the file an `iobdisk://` URL points to, e.g. a video of another instance after it was processed.
|
|
2091
|
+
*
|
|
2092
|
+
* A file on this host is deleted directly, a file on another host by the js-controller of that host (js-controller
|
|
2093
|
+
* 8.0 or newer, feature `CONTROLLER_DISK_FILES`). Only a regular file in the data directory of the instance is
|
|
2094
|
+
* deleted - never a directory, nothing outside the data directory, and a symbolic link is refused instead of
|
|
2095
|
+
* deleting its target.
|
|
2096
|
+
*
|
|
2097
|
+
* @param url e.g. `iobdisk://pi4/telegram.0/video/2026-11-04_10-00-00.mp4`
|
|
2098
|
+
* @returns `true` if the file was deleted, `false` if it did not exist (any more)
|
|
2099
|
+
* @throws {Error} if the URL is invalid, the host does not answer or is too old, or the file cannot be deleted
|
|
2100
|
+
*/
|
|
2101
|
+
deleteDiskFile(url: string): Promise<boolean>;
|
|
2044
2102
|
/**
|
|
2045
2103
|
* Register an exclusive resource (serial port, TCP/UDP port, USB device, ...) as used by this instance.
|
|
2046
2104
|
*
|
|
@@ -2119,6 +2177,36 @@ export declare class AdapterClass extends EventEmitter {
|
|
|
2119
2177
|
* @returns the list of registered resources (across all instances and types of this host)
|
|
2120
2178
|
*/
|
|
2121
2179
|
getHostUsedResources(): Promise<ioBroker.RegisteredResource[]>;
|
|
2180
|
+
/**
|
|
2181
|
+
* Copy a directory of an installed adapter into a local directory - also from another host.
|
|
2182
|
+
*
|
|
2183
|
+
* The files of an adapter only exist on the hosts it is installed on. vis-2 for example collects the
|
|
2184
|
+
* `widgets` folder of every adapter with widgets, which fails when the adapter runs on another host. This
|
|
2185
|
+
* fetches such a directory: if the adapter is installed on this host, it is copied from its package,
|
|
2186
|
+
* otherwise the js-controller of the host hands the files out - small files several in one answer, big files
|
|
2187
|
+
* piece by piece, compressed with gzip where it helps (js-controller 8.0 or newer on that host, feature
|
|
2188
|
+
* `CONTROLLER_ADAPTER_FILES`).
|
|
2189
|
+
*
|
|
2190
|
+
* Only the package directory of the adapter can be read, and not all of it: everything below
|
|
2191
|
+
* `node_modules`, hidden files and directories (name starting with a dot) and symbolic links are left out.
|
|
2192
|
+
*
|
|
2193
|
+
* Existing files in `target` are overwritten, other files there are kept. If fetching fails, `target` may
|
|
2194
|
+
* hold a part of the files - fetch into an empty directory and move it into place when it is complete.
|
|
2195
|
+
*
|
|
2196
|
+
* @example
|
|
2197
|
+
* ```ts
|
|
2198
|
+
* const { host, files } = await adapter.fetchAdapterDir({
|
|
2199
|
+
* adapter: 'wattcycle',
|
|
2200
|
+
* path: 'widgets',
|
|
2201
|
+
* target: '/opt/iobroker/iobroker-data/vis-2.0/remote/wattcycle',
|
|
2202
|
+
* });
|
|
2203
|
+
* ```
|
|
2204
|
+
* @param options which directory of which adapter, where to, and optionally from which host
|
|
2205
|
+
* @returns the host the files came from and the written files, relative to `target`
|
|
2206
|
+
* @throws {Error} if the adapter or path is invalid, no running host has the adapter, the host is too old or
|
|
2207
|
+
* does not answer, or a file changes while it is fetched
|
|
2208
|
+
*/
|
|
2209
|
+
fetchAdapterDir(options: FetchAdapterDirOptions): Promise<FetchAdapterDirResult>;
|
|
2122
2210
|
/**
|
|
2123
2211
|
* Writes value into states DB.
|
|
2124
2212
|
*
|
|
@@ -2549,6 +2637,21 @@ export declare class AdapterClass extends EventEmitter {
|
|
|
2549
2637
|
* @param id the id to add
|
|
2550
2638
|
*/
|
|
2551
2639
|
private logRedirect;
|
|
2640
|
+
/**
|
|
2641
|
+
* Renew the alive of this instance. With the fence on, it is read first: if it is not the last write of this
|
|
2642
|
+
* process any more, it expired, so this instance may have moved.
|
|
2643
|
+
*
|
|
2644
|
+
* @param expireSec expiry of the alive in seconds
|
|
2645
|
+
*/
|
|
2646
|
+
private _renewAlive;
|
|
2647
|
+
/**
|
|
2648
|
+
* Log a failed write of the status report. A lost connection only goes to debug: with the fence on, the writes in
|
|
2649
|
+
* flight are not resent but all fail at once, and the next report writes these states again.
|
|
2650
|
+
*
|
|
2651
|
+
* @param state name of the state below `system.adapter.<namespace>`
|
|
2652
|
+
* @param e the error of the write
|
|
2653
|
+
*/
|
|
2654
|
+
private _statusWriteFailed;
|
|
2552
2655
|
private _reportStatus;
|
|
2553
2656
|
private _checkLogging;
|
|
2554
2657
|
/**
|
|
@@ -2557,6 +2660,17 @@ export declare class AdapterClass extends EventEmitter {
|
|
|
2557
2660
|
private _initLogging;
|
|
2558
2661
|
private _initStates;
|
|
2559
2662
|
private _initObjects;
|
|
2663
|
+
/**
|
|
2664
|
+
* Checks whether a sigKill written by `from` may terminate this process.
|
|
2665
|
+
*
|
|
2666
|
+
* In multihost the sigKill state is shared by all copies of this instance: a controller stopping its
|
|
2667
|
+
* (possibly stale) copy on another host must not terminate us, so a sigKill from another existing host
|
|
2668
|
+
* is ignored. A sender that is not a host of this installation, e.g. the test harness of
|
|
2669
|
+
* the adapter testing package ("system.host.testing"), is still obeyed, as before.
|
|
2670
|
+
*
|
|
2671
|
+
* @param from the `from` of the sigKill state
|
|
2672
|
+
*/
|
|
2673
|
+
private _mayTerminateUs;
|
|
2560
2674
|
/**
|
|
2561
2675
|
* Called if states and objects successfully initialized
|
|
2562
2676
|
*/
|
|
@@ -2571,6 +2685,17 @@ export declare class AdapterClass extends EventEmitter {
|
|
|
2571
2685
|
* Calls the ready handler, if it is an install run it calls the install handler instead
|
|
2572
2686
|
*/
|
|
2573
2687
|
private _callReadyHandler;
|
|
2688
|
+
/**
|
|
2689
|
+
* Whether to fence: `system.fence` of iobroker.json, else only with more than one host
|
|
2690
|
+
*/
|
|
2691
|
+
private _needsFence;
|
|
2692
|
+
/**
|
|
2693
|
+
* Fence after a reconnect: true if this instance is still assigned to this host. Otherwise it terminates
|
|
2694
|
+
* without unload, as it could write stale states over those of the copy on the new host.
|
|
2695
|
+
*
|
|
2696
|
+
* @param reason why the check runs, for the log
|
|
2697
|
+
*/
|
|
2698
|
+
private _fence;
|
|
2574
2699
|
private _exceptionHandler;
|
|
2575
2700
|
private _createInstancesObjects;
|
|
2576
2701
|
private _extendObjects;
|