@iobroker/js-controller-adapter 7.2.2 → 7.2.3-alpha.1-20260621-61726ea22

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.
Files changed (38) hide show
  1. package/build/cjs/lib/_Types.d.ts +256 -0
  2. package/build/cjs/lib/adapter/adapter.d.ts +1403 -3
  3. package/build/cjs/lib/adapter/adapter.js +147 -24
  4. package/build/cjs/lib/adapter/adapter.js.map +2 -2
  5. package/build/cjs/lib/adapter/defaultObjs.d.ts +5 -0
  6. package/build/cjs/lib/adapter/defaultObjs.js.map +2 -2
  7. package/build/cjs/lib/adapter/log.d.ts +25 -0
  8. package/build/cjs/lib/adapter/log.js +25 -0
  9. package/build/cjs/lib/adapter/log.js.map +2 -2
  10. package/build/cjs/lib/adapter/userInterfaceMessagingController.d.ts +10 -0
  11. package/build/cjs/lib/adapter/userInterfaceMessagingController.js +3 -0
  12. package/build/cjs/lib/adapter/userInterfaceMessagingController.js.map +2 -2
  13. package/build/cjs/lib/adapter/validator.d.ts +4 -0
  14. package/build/cjs/lib/adapter/validator.js.map +2 -2
  15. package/build/esm/lib/_Types.d.ts +256 -0
  16. package/build/esm/lib/_Types.d.ts.map +1 -1
  17. package/build/esm/lib/adapter/adapter.d.ts +1403 -3
  18. package/build/esm/lib/adapter/adapter.d.ts.map +1 -1
  19. package/build/esm/lib/adapter/adapter.js +147 -24
  20. package/build/esm/lib/adapter/adapter.js.map +1 -1
  21. package/build/esm/lib/adapter/defaultObjs.d.ts +5 -0
  22. package/build/esm/lib/adapter/defaultObjs.d.ts.map +1 -1
  23. package/build/esm/lib/adapter/defaultObjs.js +5 -0
  24. package/build/esm/lib/adapter/defaultObjs.js.map +1 -1
  25. package/build/esm/lib/adapter/log.d.ts +25 -0
  26. package/build/esm/lib/adapter/log.d.ts.map +1 -1
  27. package/build/esm/lib/adapter/log.js +25 -0
  28. package/build/esm/lib/adapter/log.js.map +1 -1
  29. package/build/esm/lib/adapter/userInterfaceMessagingController.d.ts +10 -0
  30. package/build/esm/lib/adapter/userInterfaceMessagingController.d.ts.map +1 -1
  31. package/build/esm/lib/adapter/userInterfaceMessagingController.js +6 -0
  32. package/build/esm/lib/adapter/userInterfaceMessagingController.js.map +1 -1
  33. package/build/esm/lib/adapter/validator.d.ts +4 -0
  34. package/build/esm/lib/adapter/validator.d.ts.map +1 -1
  35. package/build/esm/lib/adapter/validator.js +3 -0
  36. package/build/esm/lib/adapter/validator.js.map +1 -1
  37. package/build/tsconfig.build.tsbuildinfo +1 -1
  38. package/package.json +10 -10
@@ -1,2 +1,7 @@
1
+ /**
2
+ * Create the default `common` definitions for the well-known state roles (e.g. level.dimmer, indicator.working)
3
+ *
4
+ * @returns a map of state role to its default common properties
5
+ */
1
6
  export declare function createDefaults(): Record<string, Partial<ioBroker.StateCommon>>;
2
7
  //# sourceMappingURL=defaultObjs.d.ts.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/adapter/defaultObjs.ts"],
4
- "sourcesContent": ["export function createDefaults(): Record<string, Partial<ioBroker.StateCommon>> {\n return {\n 'level.dimmer': {\n type: 'number',\n read: true,\n write: true,\n min: 0,\n max: 100,\n unit: '%',\n },\n 'indicator.working': {\n def: false,\n type: 'boolean',\n read: true,\n write: false,\n },\n 'indicator.maintenance': {\n def: false,\n type: 'boolean',\n read: true,\n write: false,\n },\n 'indicator.maintenance.lowbat': {\n def: false,\n type: 'boolean',\n read: true,\n write: false,\n desc: 'Low battery',\n },\n 'indicator.maintenance.unreach': {\n def: false,\n type: 'boolean',\n read: true,\n write: false,\n desc: 'Device unreachable',\n },\n switch: {\n type: 'boolean',\n read: true,\n write: true,\n },\n } as const;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;AAAM,SAAU,iBAAc;AAC1B,SAAO;IACH,gBAAgB;MACZ,MAAM;MACN,MAAM;MACN,OAAO;MACP,KAAK;MACL,KAAK;MACL,MAAM;;IAEV,qBAAqB;MACjB,KAAK;MACL,MAAM;MACN,MAAM;MACN,OAAO;;IAEX,yBAAyB;MACrB,KAAK;MACL,MAAM;MACN,MAAM;MACN,OAAO;;IAEX,gCAAgC;MAC5B,KAAK;MACL,MAAM;MACN,MAAM;MACN,OAAO;MACP,MAAM;;IAEV,iCAAiC;MAC7B,KAAK;MACL,MAAM;MACN,MAAM;MACN,OAAO;MACP,MAAM;;IAEV,QAAQ;MACJ,MAAM;MACN,MAAM;MACN,OAAO;;;AAGnB;",
4
+ "sourcesContent": ["/**\n * Create the default `common` definitions for the well-known state roles (e.g. level.dimmer, indicator.working)\n *\n * @returns a map of state role to its default common properties\n */\nexport function createDefaults(): Record<string, Partial<ioBroker.StateCommon>> {\n return {\n 'level.dimmer': {\n type: 'number',\n read: true,\n write: true,\n min: 0,\n max: 100,\n unit: '%',\n },\n 'indicator.working': {\n def: false,\n type: 'boolean',\n read: true,\n write: false,\n },\n 'indicator.maintenance': {\n def: false,\n type: 'boolean',\n read: true,\n write: false,\n },\n 'indicator.maintenance.lowbat': {\n def: false,\n type: 'boolean',\n read: true,\n write: false,\n desc: 'Low battery',\n },\n 'indicator.maintenance.unreach': {\n def: false,\n type: 'boolean',\n read: true,\n write: false,\n desc: 'Device unreachable',\n },\n switch: {\n type: 'boolean',\n read: true,\n write: true,\n },\n } as const;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;AAKM,SAAU,iBAAc;AAC1B,SAAO;IACH,gBAAgB;MACZ,MAAM;MACN,MAAM;MACN,OAAO;MACP,KAAK;MACL,KAAK;MACL,MAAM;;IAEV,qBAAqB;MACjB,KAAK;MACL,MAAM;MACN,MAAM;MACN,OAAO;;IAEX,yBAAyB;MACrB,KAAK;MACL,MAAM;MACN,MAAM;MACN,OAAO;;IAEX,gCAAgC;MAC5B,KAAK;MACL,MAAM;MACN,MAAM;MACN,OAAO;MACP,MAAM;;IAEV,iCAAiC;MAC7B,KAAK;MACL,MAAM;MACN,MAAM;MACN,OAAO;MACP,MAAM;;IAEV,QAAQ;MACJ,MAAM;MACN,MAAM;MACN,OAAO;;;AAGnB;",
6
6
  "names": []
7
7
  }
@@ -13,10 +13,35 @@ export declare class Log implements ioBroker.Logger {
13
13
  * @param logger logger instance
14
14
  */
15
15
  constructor(namespaceLog: string, level: ioBroker.LogLevel, logger: any);
16
+ /**
17
+ * Log a message at the silly level, prefixed with the adapter namespace
18
+ *
19
+ * @param msg the message to log
20
+ */
16
21
  silly(msg: string): void;
22
+ /**
23
+ * Log a message at the debug level, prefixed with the adapter namespace
24
+ *
25
+ * @param msg the message to log
26
+ */
17
27
  debug(msg: string): void;
28
+ /**
29
+ * Log a message at the info level, prefixed with the adapter namespace
30
+ *
31
+ * @param msg the message to log
32
+ */
18
33
  info(msg: string): void;
34
+ /**
35
+ * Log a message at the error level, prefixed with the adapter namespace
36
+ *
37
+ * @param msg the message to log
38
+ */
19
39
  error(msg: string): void;
40
+ /**
41
+ * Log a message at the warn level, prefixed with the adapter namespace
42
+ *
43
+ * @param msg the message to log
44
+ */
20
45
  warn(msg: string): void;
21
46
  }
22
47
  //# sourceMappingURL=log.d.ts.map
@@ -41,18 +41,43 @@ class Log {
41
41
  this.error = this.error.bind(this);
42
42
  this.warn = this.warn.bind(this);
43
43
  }
44
+ /**
45
+ * Log a message at the silly level, prefixed with the adapter namespace
46
+ *
47
+ * @param msg the message to log
48
+ */
44
49
  silly(msg) {
45
50
  this.logger.silly(`${this.namespaceLog} ${msg}`);
46
51
  }
52
+ /**
53
+ * Log a message at the debug level, prefixed with the adapter namespace
54
+ *
55
+ * @param msg the message to log
56
+ */
47
57
  debug(msg) {
48
58
  this.logger.debug(`${this.namespaceLog} ${msg}`);
49
59
  }
60
+ /**
61
+ * Log a message at the info level, prefixed with the adapter namespace
62
+ *
63
+ * @param msg the message to log
64
+ */
50
65
  info(msg) {
51
66
  this.logger.info(`${this.namespaceLog} ${msg}`);
52
67
  }
68
+ /**
69
+ * Log a message at the error level, prefixed with the adapter namespace
70
+ *
71
+ * @param msg the message to log
72
+ */
53
73
  error(msg) {
54
74
  this.logger.error(`${this.namespaceLog} ${msg}`);
55
75
  }
76
+ /**
77
+ * Log a message at the warn level, prefixed with the adapter namespace
78
+ *
79
+ * @param msg the message to log
80
+ */
56
81
  warn(msg) {
57
82
  this.logger.warn(`${this.namespaceLog} ${msg}`);
58
83
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/adapter/log.ts"],
4
- "sourcesContent": ["type LogFunction = (msg: string) => void;\n\n/**\n * Log class for adapter.js\n *\n * It prefixes every message with the given namespace\n */\nexport class Log implements ioBroker.Logger {\n private readonly namespaceLog: string;\n readonly level: ioBroker.LogLevel;\n // TODO: this should be a winston.Logger, but the exported types will mess up because of https://github.com/microsoft/rushstack/issues/2220\n private readonly logger: {\n silly: LogFunction;\n debug: LogFunction;\n info: LogFunction;\n warn: LogFunction;\n error: LogFunction;\n };\n\n /**\n * @param namespaceLog Logging namespace to prefix\n * @param level The log level\n * @param logger logger instance\n */\n constructor(namespaceLog: string, level: ioBroker.LogLevel, logger: any) {\n this.namespaceLog = namespaceLog;\n this.level = level;\n // We have to bind the `this` context here, or it is possible that `this` is\n // undefined when passing around the logger methods. This happens e.g. when doing this:\n // const log = new Log(...);\n // const test = log.info;\n // test();\n this.logger = logger;\n this.silly = this.silly.bind(this);\n this.debug = this.debug.bind(this);\n this.info = this.info.bind(this);\n this.error = this.error.bind(this);\n this.warn = this.warn.bind(this);\n }\n\n silly(msg: string): void {\n this.logger.silly(`${this.namespaceLog} ${msg}`);\n }\n\n debug(msg: string): void {\n this.logger.debug(`${this.namespaceLog} ${msg}`);\n }\n\n info(msg: string): void {\n this.logger.info(`${this.namespaceLog} ${msg}`);\n }\n\n error(msg: string): void {\n this.logger.error(`${this.namespaceLog} ${msg}`);\n }\n\n warn(msg: string): void {\n this.logger.warn(`${this.namespaceLog} ${msg}`);\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAEA;;;;;AAKM,MAAO,IAAG;EACK;EACR;;EAEQ;;;;;;EAajB,YAAY,cAAsB,OAA0B,QAAW;AACnE,SAAK,eAAe;AACpB,SAAK,QAAQ;AAMb,SAAK,SAAS;AACd,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AACjC,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AACjC,SAAK,OAAO,KAAK,KAAK,KAAK,IAAI;AAC/B,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AACjC,SAAK,OAAO,KAAK,KAAK,KAAK,IAAI;EACnC;EAEA,MAAM,KAAW;AACb,SAAK,OAAO,MAAM,GAAG,KAAK,YAAY,IAAI,GAAG,EAAE;EACnD;EAEA,MAAM,KAAW;AACb,SAAK,OAAO,MAAM,GAAG,KAAK,YAAY,IAAI,GAAG,EAAE;EACnD;EAEA,KAAK,KAAW;AACZ,SAAK,OAAO,KAAK,GAAG,KAAK,YAAY,IAAI,GAAG,EAAE;EAClD;EAEA,MAAM,KAAW;AACb,SAAK,OAAO,MAAM,GAAG,KAAK,YAAY,IAAI,GAAG,EAAE;EACnD;EAEA,KAAK,KAAW;AACZ,SAAK,OAAO,KAAK,GAAG,KAAK,YAAY,IAAI,GAAG,EAAE;EAClD;;",
4
+ "sourcesContent": ["type LogFunction = (msg: string) => void;\n\n/**\n * Log class for adapter.js\n *\n * It prefixes every message with the given namespace\n */\nexport class Log implements ioBroker.Logger {\n private readonly namespaceLog: string;\n readonly level: ioBroker.LogLevel;\n // TODO: this should be a winston.Logger, but the exported types will mess up because of https://github.com/microsoft/rushstack/issues/2220\n private readonly logger: {\n silly: LogFunction;\n debug: LogFunction;\n info: LogFunction;\n warn: LogFunction;\n error: LogFunction;\n };\n\n /**\n * @param namespaceLog Logging namespace to prefix\n * @param level The log level\n * @param logger logger instance\n */\n constructor(namespaceLog: string, level: ioBroker.LogLevel, logger: any) {\n this.namespaceLog = namespaceLog;\n this.level = level;\n // We have to bind the `this` context here, or it is possible that `this` is\n // undefined when passing around the logger methods. This happens e.g. when doing this:\n // const log = new Log(...);\n // const test = log.info;\n // test();\n this.logger = logger;\n this.silly = this.silly.bind(this);\n this.debug = this.debug.bind(this);\n this.info = this.info.bind(this);\n this.error = this.error.bind(this);\n this.warn = this.warn.bind(this);\n }\n\n /**\n * Log a message at the silly level, prefixed with the adapter namespace\n *\n * @param msg the message to log\n */\n silly(msg: string): void {\n this.logger.silly(`${this.namespaceLog} ${msg}`);\n }\n\n /**\n * Log a message at the debug level, prefixed with the adapter namespace\n *\n * @param msg the message to log\n */\n debug(msg: string): void {\n this.logger.debug(`${this.namespaceLog} ${msg}`);\n }\n\n /**\n * Log a message at the info level, prefixed with the adapter namespace\n *\n * @param msg the message to log\n */\n info(msg: string): void {\n this.logger.info(`${this.namespaceLog} ${msg}`);\n }\n\n /**\n * Log a message at the error level, prefixed with the adapter namespace\n *\n * @param msg the message to log\n */\n error(msg: string): void {\n this.logger.error(`${this.namespaceLog} ${msg}`);\n }\n\n /**\n * Log a message at the warn level, prefixed with the adapter namespace\n *\n * @param msg the message to log\n */\n warn(msg: string): void {\n this.logger.warn(`${this.namespaceLog} ${msg}`);\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAEA;;;;;AAKM,MAAO,IAAG;EACK;EACR;;EAEQ;;;;;;EAajB,YAAY,cAAsB,OAA0B,QAAW;AACnE,SAAK,eAAe;AACpB,SAAK,QAAQ;AAMb,SAAK,SAAS;AACd,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AACjC,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AACjC,SAAK,OAAO,KAAK,KAAK,KAAK,IAAI;AAC/B,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AACjC,SAAK,OAAO,KAAK,KAAK,KAAK,IAAI;EACnC;;;;;;EAOA,MAAM,KAAW;AACb,SAAK,OAAO,MAAM,GAAG,KAAK,YAAY,IAAI,GAAG,EAAE;EACnD;;;;;;EAOA,MAAM,KAAW;AACb,SAAK,OAAO,MAAM,GAAG,KAAK,YAAY,IAAI,GAAG,EAAE;EACnD;;;;;;EAOA,KAAK,KAAW;AACZ,SAAK,OAAO,KAAK,GAAG,KAAK,YAAY,IAAI,GAAG,EAAE;EAClD;;;;;;EAOA,MAAM,KAAW;AACb,SAAK,OAAO,MAAM,GAAG,KAAK,YAAY,IAAI,GAAG,EAAE;EACnD;;;;;;EAOA,KAAK,KAAW;AACZ,SAAK,OAAO,KAAK,GAAG,KAAK,YAAY,IAAI,GAAG,EAAE;EAClD;;",
6
6
  "names": []
7
7
  }
@@ -1,12 +1,14 @@
1
1
  import type { Client as StatesInRedisClient } from '@iobroker/db-states-redis';
2
2
  import type { AdapterClass } from '../../lib/adapter/adapter.js';
3
3
  import type { UserInterfaceClientRemoveMessage, UserInterfaceClientSubscribeHandler, UserInterfaceClientSubscribeReturnType, UserInterfaceClientUnsubscribeHandler } from '../../lib/_Types.js';
4
+ /** A heartbeat timer for a subscribed UI client */
4
5
  export interface HeartbeatTimer {
5
6
  /** The actual timer */
6
7
  timer: NodeJS.Timeout;
7
8
  /** The heartbeat interval */
8
9
  heartbeat: number;
9
10
  }
11
+ /** Options for the UI messaging controller */
10
12
  export interface MessagingControllerOptions {
11
13
  /** The adapter using this messaging controller */
12
14
  adapter: AdapterClass;
@@ -15,6 +17,7 @@ export interface MessagingControllerOptions {
15
17
  /** Callback to call if successfully unsubscribed */
16
18
  unsubscribeCallback?: UserInterfaceClientUnsubscribeHandler;
17
19
  }
20
+ /** Options for sending a message to a single UI client */
18
21
  export interface SendToClientOptions {
19
22
  /** ID of the client to send the message to, will send to all if omitted */
20
23
  clientId: string;
@@ -24,6 +27,7 @@ export interface SendToClientOptions {
24
27
  states: StatesInRedisClient;
25
28
  }
26
29
  export type SendToAllClientOptions = Omit<SendToClientOptions, 'clientId'>;
30
+ /** Handler describing a subscribed UI client */
27
31
  export interface ClientHandler {
28
32
  /** The session id of the client connection */
29
33
  sid: string;
@@ -32,6 +36,9 @@ export interface ClientHandler {
32
36
  /** Individual type which can be specified */
33
37
  type: string;
34
38
  }
39
+ /**
40
+ * Controller for messaging with UI clients (subscribe, heartbeat and sending data)
41
+ */
35
42
  export declare class UserInterfaceMessagingController {
36
43
  /** The adapter using this messaging controller */
37
44
  private readonly adapter;
@@ -43,6 +50,9 @@ export declare class UserInterfaceMessagingController {
43
50
  private readonly handlers;
44
51
  /** Collection of current heartbeat timers */
45
52
  private heartbeatTimers;
53
+ /**
54
+ * @param options The adapter and the subscribe/unsubscribe callbacks
55
+ */
46
56
  constructor(options: MessagingControllerOptions);
47
57
  /**
48
58
  * Send a message to the given clientId
@@ -32,6 +32,9 @@ class UserInterfaceMessagingController {
32
32
  handlers = /* @__PURE__ */ new Map();
33
33
  /** Collection of current heartbeat timers */
34
34
  heartbeatTimers = /* @__PURE__ */ new Map();
35
+ /**
36
+ * @param options The adapter and the subscribe/unsubscribe callbacks
37
+ */
35
38
  constructor(options) {
36
39
  const { adapter, unsubscribeCallback, subscribeCallback } = options;
37
40
  this.adapter = adapter;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/adapter/userInterfaceMessagingController.ts"],
4
- "sourcesContent": ["import type { Client as StatesInRedisClient } from '@iobroker/db-states-redis';\nimport type { AdapterClass } from '@/lib/adapter/adapter.js';\nimport type {\n UserInterfaceClientRemoveMessage,\n UserInterfaceClientSubscribeHandler,\n UserInterfaceClientSubscribeReturnType,\n UserInterfaceClientUnsubscribeHandler,\n} from '@/lib/_Types.js';\n\nexport interface HeartbeatTimer {\n /** The actual timer */\n timer: NodeJS.Timeout;\n /** The heartbeat interval */\n heartbeat: number;\n}\n\nexport interface MessagingControllerOptions {\n /** The adapter using this messaging controller */\n adapter: AdapterClass;\n /** Callback to call if successfully subscribed */\n subscribeCallback?: UserInterfaceClientSubscribeHandler;\n /** Callback to call if successfully unsubscribed */\n unsubscribeCallback?: UserInterfaceClientUnsubscribeHandler;\n}\n\nexport interface SendToClientOptions {\n /** ID of the client to send the message to, will send to all if omitted */\n clientId: string;\n /** Data to send to the client */\n data: unknown;\n /** The states db */\n states: StatesInRedisClient;\n}\n\nexport type SendToAllClientOptions = Omit<SendToClientOptions, 'clientId'>;\n\nexport interface ClientHandler {\n /** The session id of the client connection */\n sid: string;\n /** Name of the subscriber */\n from: string;\n /** Individual type which can be specified */\n type: string;\n}\n\n/**\n * The message has short keys, to save bytes for high-throughput messaging\n */\ninterface UserInterfaceMessage {\n /** The individual type of the client handler */\n m: string;\n /** The session id of the client connection */\n s: string;\n /** The actual data */\n d: unknown;\n}\n\nexport class UserInterfaceMessagingController {\n /** The adapter using this messaging controller */\n private readonly adapter: AdapterClass;\n /** Callback to call if successfully subscribed */\n private readonly unsubscribeCallback?: UserInterfaceClientUnsubscribeHandler;\n /** Callback to call if successfully unsubscribed */\n private readonly subscribeCallback?: UserInterfaceClientSubscribeHandler;\n /** All currently registered client handlers */\n private readonly handlers = new Map<string, ClientHandler>();\n /** Collection of current heartbeat timers */\n private heartbeatTimers = new Map<string, HeartbeatTimer>();\n constructor(options: MessagingControllerOptions) {\n const { adapter, unsubscribeCallback, subscribeCallback } = options;\n\n this.adapter = adapter;\n this.unsubscribeCallback = unsubscribeCallback;\n this.subscribeCallback = subscribeCallback;\n }\n\n /**\n * Send a message to the given clientId\n *\n * @param options Data, states and client information\n */\n sendToClient(options: SendToClientOptions): Promise<void> {\n const { states, clientId, data } = options;\n\n if (!this.handlers.has(clientId)) {\n throw new Error(`Client \"${clientId}\" is not registered`);\n }\n\n const handler = this.handlers.get(clientId)!;\n\n return states.pushMessage(handler.from, {\n command: 'im',\n message: { m: handler.type, s: handler.sid, d: data } satisfies UserInterfaceMessage,\n from: `system.adapter.${this.adapter.namespace}`,\n });\n }\n\n /**\n * Send a message to all active clients\n *\n * @param options Data and states options\n */\n async sendToAllClients(options: SendToAllClientOptions): Promise<void> {\n const { states, data } = options;\n\n for (const clientId of Object.keys(this.handlers)) {\n await this.sendToClient({ clientId, data, states });\n }\n }\n\n /**\n * Register subscription from new client\n *\n * @param msg The subscribe message\n */\n async registerClientSubscribeByMessage(\n msg: ioBroker.Message,\n ): Promise<UserInterfaceClientSubscribeReturnType | undefined> {\n if (!this.subscribeCallback) {\n return;\n }\n\n const handler = this.extractHandlerFromMessage(msg);\n const clientId = this.handlerToId(handler);\n\n if (this.heartbeatTimers.has(clientId)) {\n this.heartbeatTimers.get(clientId)!.timer.refresh();\n return;\n }\n\n const resOrAwaitable = this.subscribeCallback({ clientId, message: msg });\n let res: UserInterfaceClientSubscribeReturnType;\n\n if (resOrAwaitable instanceof Promise) {\n res = await resOrAwaitable;\n } else {\n res = resOrAwaitable;\n }\n\n if (!res.accepted) {\n return res;\n }\n\n this.handlers.set(clientId, handler);\n if (res.heartbeat) {\n const timer = setTimeout(() => this.heartbeatExpired(clientId), res.heartbeat);\n this.heartbeatTimers.set(clientId, { heartbeat: res.heartbeat, timer });\n }\n\n return res;\n }\n\n /**\n * Remove a client subscription, issued by message\n * It contains an array of types which should be unsubscribed\n *\n * @param msg The unsubscribe message\n */\n removeClientSubscribeByMessage(msg: UserInterfaceClientRemoveMessage): void {\n const handler = this.extractHandlerFromMessage(msg);\n const reason = msg.command === 'clientSubscribeError' ? msg.command : msg.message.reason;\n\n const types = msg.message.type;\n\n for (const type of types) {\n const clientId = this.handlerToId({ ...handler, type });\n\n if (this.heartbeatTimers.has(clientId)) {\n const timer = this.heartbeatTimers.get(clientId)!;\n\n clearTimeout(timer.timer);\n this.heartbeatTimers.delete(clientId);\n }\n\n if (!this.handlers.has(clientId)) {\n return;\n }\n\n this.handlers.delete(clientId);\n if (this.unsubscribeCallback) {\n this.unsubscribeCallback({ clientId, message: msg, reason });\n }\n }\n }\n\n /**\n * Convert handler to id\n *\n * @param handler the client handler to creat the id for\n */\n private handlerToId(handler: ClientHandler): string {\n const { sid, type, from } = handler;\n\n return `${sid}-${from}-${type}`;\n }\n\n /**\n * Extract the client handler from a given message\n *\n * @param msg the subscribe or unsubscribe message\n */\n private extractHandlerFromMessage(msg: ioBroker.Message): ClientHandler {\n return { sid: msg.message.sid, from: msg.from, type: msg.message.type };\n }\n\n /**\n * Handle expired heartbeat\n *\n * @param clientId the id of the expired client\n */\n private heartbeatExpired(clientId: string): void {\n this.handlers.delete(clientId);\n this.heartbeatTimers.delete(clientId);\n\n if (this.unsubscribeCallback) {\n this.unsubscribeCallback({ clientId, reason: 'timeout' });\n }\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAyDA;;;;;AAAM,MAAO,iCAAgC;;EAExB;;EAEA;;EAEA;;EAEA,WAAW,oBAAI,IAAG;;EAE3B,kBAAkB,oBAAI,IAAG;EACjC,YAAY,SAAmC;AAC3C,UAAM,EAAE,SAAS,qBAAqB,kBAAiB,IAAK;AAE5D,SAAK,UAAU;AACf,SAAK,sBAAsB;AAC3B,SAAK,oBAAoB;EAC7B;;;;;;EAOA,aAAa,SAA4B;AACrC,UAAM,EAAE,QAAQ,UAAU,KAAI,IAAK;AAEnC,QAAI,CAAC,KAAK,SAAS,IAAI,QAAQ,GAAG;AAC9B,YAAM,IAAI,MAAM,WAAW,QAAQ,qBAAqB;IAC5D;AAEA,UAAM,UAAU,KAAK,SAAS,IAAI,QAAQ;AAE1C,WAAO,OAAO,YAAY,QAAQ,MAAM;MACpC,SAAS;MACT,SAAS,EAAE,GAAG,QAAQ,MAAM,GAAG,QAAQ,KAAK,GAAG,KAAI;MACnD,MAAM,kBAAkB,KAAK,QAAQ,SAAS;KACjD;EACL;;;;;;EAOA,MAAM,iBAAiB,SAA+B;AAClD,UAAM,EAAE,QAAQ,KAAI,IAAK;AAEzB,eAAW,YAAY,OAAO,KAAK,KAAK,QAAQ,GAAG;AAC/C,YAAM,KAAK,aAAa,EAAE,UAAU,MAAM,OAAM,CAAE;IACtD;EACJ;;;;;;EAOA,MAAM,iCACF,KAAqB;AAErB,QAAI,CAAC,KAAK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J;;;;;;EAOQ,YAAY,SAAsB;AACtC,UAAM,EAAE,KAAK,MAAM,KAAI,IAAK;AAE5B,WAAO,GAAG,GAAG,IAAI,IAAI,IAAI,IAAI;EACjC;;;;;;EAOQ,0BAA0B,KAAqB;AACnD,WAAO,EAAE,KAAK,IAAI,QAAQ,KAAK,MAAM,IAAI,MAAM,MAAM,IAAI,QAAQ,KAAI;EACzE;;;;;;EAOQ,iBAAiB,UAAgB;AACrC,SAAK,SAAS,OAAO,QAAQ;AAC7B,SAAK,gBAAgB,OAAO,QAAQ;AAEpC,QAAI,KAAK,qBAAqB;AAC1B,WAAK,oBAAoB,EAAE,UAAU,QAAQ,UAAS,CAAE;IAC5D;EACJ;;",
4
+ "sourcesContent": ["import type { Client as StatesInRedisClient } from '@iobroker/db-states-redis';\nimport type { AdapterClass } from '@/lib/adapter/adapter.js';\nimport type {\n UserInterfaceClientRemoveMessage,\n UserInterfaceClientSubscribeHandler,\n UserInterfaceClientSubscribeReturnType,\n UserInterfaceClientUnsubscribeHandler,\n} from '@/lib/_Types.js';\n\n/** A heartbeat timer for a subscribed UI client */\nexport interface HeartbeatTimer {\n /** The actual timer */\n timer: NodeJS.Timeout;\n /** The heartbeat interval */\n heartbeat: number;\n}\n\n/** Options for the UI messaging controller */\nexport interface MessagingControllerOptions {\n /** The adapter using this messaging controller */\n adapter: AdapterClass;\n /** Callback to call if successfully subscribed */\n subscribeCallback?: UserInterfaceClientSubscribeHandler;\n /** Callback to call if successfully unsubscribed */\n unsubscribeCallback?: UserInterfaceClientUnsubscribeHandler;\n}\n\n/** Options for sending a message to a single UI client */\nexport interface SendToClientOptions {\n /** ID of the client to send the message to, will send to all if omitted */\n clientId: string;\n /** Data to send to the client */\n data: unknown;\n /** The states db */\n states: StatesInRedisClient;\n}\n\nexport type SendToAllClientOptions = Omit<SendToClientOptions, 'clientId'>;\n\n/** Handler describing a subscribed UI client */\nexport interface ClientHandler {\n /** The session id of the client connection */\n sid: string;\n /** Name of the subscriber */\n from: string;\n /** Individual type which can be specified */\n type: string;\n}\n\n/**\n * The message has short keys, to save bytes for high-throughput messaging\n */\ninterface UserInterfaceMessage {\n /** The individual type of the client handler */\n m: string;\n /** The session id of the client connection */\n s: string;\n /** The actual data */\n d: unknown;\n}\n\n/**\n * Controller for messaging with UI clients (subscribe, heartbeat and sending data)\n */\nexport class UserInterfaceMessagingController {\n /** The adapter using this messaging controller */\n private readonly adapter: AdapterClass;\n /** Callback to call if successfully subscribed */\n private readonly unsubscribeCallback?: UserInterfaceClientUnsubscribeHandler;\n /** Callback to call if successfully unsubscribed */\n private readonly subscribeCallback?: UserInterfaceClientSubscribeHandler;\n /** All currently registered client handlers */\n private readonly handlers = new Map<string, ClientHandler>();\n /** Collection of current heartbeat timers */\n private heartbeatTimers = new Map<string, HeartbeatTimer>();\n /**\n * @param options The adapter and the subscribe/unsubscribe callbacks\n */\n constructor(options: MessagingControllerOptions) {\n const { adapter, unsubscribeCallback, subscribeCallback } = options;\n\n this.adapter = adapter;\n this.unsubscribeCallback = unsubscribeCallback;\n this.subscribeCallback = subscribeCallback;\n }\n\n /**\n * Send a message to the given clientId\n *\n * @param options Data, states and client information\n */\n sendToClient(options: SendToClientOptions): Promise<void> {\n const { states, clientId, data } = options;\n\n if (!this.handlers.has(clientId)) {\n throw new Error(`Client \"${clientId}\" is not registered`);\n }\n\n const handler = this.handlers.get(clientId)!;\n\n return states.pushMessage(handler.from, {\n command: 'im',\n message: { m: handler.type, s: handler.sid, d: data } satisfies UserInterfaceMessage,\n from: `system.adapter.${this.adapter.namespace}`,\n });\n }\n\n /**\n * Send a message to all active clients\n *\n * @param options Data and states options\n */\n async sendToAllClients(options: SendToAllClientOptions): Promise<void> {\n const { states, data } = options;\n\n for (const clientId of Object.keys(this.handlers)) {\n await this.sendToClient({ clientId, data, states });\n }\n }\n\n /**\n * Register subscription from new client\n *\n * @param msg The subscribe message\n */\n async registerClientSubscribeByMessage(\n msg: ioBroker.Message,\n ): Promise<UserInterfaceClientSubscribeReturnType | undefined> {\n if (!this.subscribeCallback) {\n return;\n }\n\n const handler = this.extractHandlerFromMessage(msg);\n const clientId = this.handlerToId(handler);\n\n if (this.heartbeatTimers.has(clientId)) {\n this.heartbeatTimers.get(clientId)!.timer.refresh();\n return;\n }\n\n const resOrAwaitable = this.subscribeCallback({ clientId, message: msg });\n let res: UserInterfaceClientSubscribeReturnType;\n\n if (resOrAwaitable instanceof Promise) {\n res = await resOrAwaitable;\n } else {\n res = resOrAwaitable;\n }\n\n if (!res.accepted) {\n return res;\n }\n\n this.handlers.set(clientId, handler);\n if (res.heartbeat) {\n const timer = setTimeout(() => this.heartbeatExpired(clientId), res.heartbeat);\n this.heartbeatTimers.set(clientId, { heartbeat: res.heartbeat, timer });\n }\n\n return res;\n }\n\n /**\n * Remove a client subscription, issued by message\n * It contains an array of types which should be unsubscribed\n *\n * @param msg The unsubscribe message\n */\n removeClientSubscribeByMessage(msg: UserInterfaceClientRemoveMessage): void {\n const handler = this.extractHandlerFromMessage(msg);\n const reason = msg.command === 'clientSubscribeError' ? msg.command : msg.message.reason;\n\n const types = msg.message.type;\n\n for (const type of types) {\n const clientId = this.handlerToId({ ...handler, type });\n\n if (this.heartbeatTimers.has(clientId)) {\n const timer = this.heartbeatTimers.get(clientId)!;\n\n clearTimeout(timer.timer);\n this.heartbeatTimers.delete(clientId);\n }\n\n if (!this.handlers.has(clientId)) {\n return;\n }\n\n this.handlers.delete(clientId);\n if (this.unsubscribeCallback) {\n this.unsubscribeCallback({ clientId, message: msg, reason });\n }\n }\n }\n\n /**\n * Convert handler to id\n *\n * @param handler the client handler to creat the id for\n */\n private handlerToId(handler: ClientHandler): string {\n const { sid, type, from } = handler;\n\n return `${sid}-${from}-${type}`;\n }\n\n /**\n * Extract the client handler from a given message\n *\n * @param msg the subscribe or unsubscribe message\n */\n private extractHandlerFromMessage(msg: ioBroker.Message): ClientHandler {\n return { sid: msg.message.sid, from: msg.from, type: msg.message.type };\n }\n\n /**\n * Handle expired heartbeat\n *\n * @param clientId the id of the expired client\n */\n private heartbeatExpired(clientId: string): void {\n this.handlers.delete(clientId);\n this.heartbeatTimers.delete(clientId);\n\n if (this.unsubscribeCallback) {\n this.unsubscribeCallback({ clientId, reason: 'timeout' });\n }\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AA6DA;;;;;AAGM,MAAO,iCAAgC;;EAExB;;EAEA;;EAEA;;EAEA,WAAW,oBAAI,IAAG;;EAE3B,kBAAkB,oBAAI,IAAG;;;;EAIjC,YAAY,SAAmC;AAC3C,UAAM,EAAE,SAAS,qBAAqB,kBAAiB,IAAK;AAE5D,SAAK,UAAU;AACf,SAAK,sBAAsB;AAC3B,SAAK,oBAAoB;EAC7B;;;;;;EAOA,aAAa,SAA4B;AACrC,UAAM,EAAE,QAAQ,UAAU,KAAI,IAAK;AAEnC,QAAI,CAAC,KAAK,SAAS,IAAI,QAAQ,GAAG;AAC9B,YAAM,IAAI,MAAM,WAAW,QAAQ,qBAAqB;IAC5D;AAEA,UAAM,UAAU,KAAK,SAAS,IAAI,QAAQ;AAE1C,WAAO,OAAO,YAAY,QAAQ,MAAM;MACpC,SAAS;MACT,SAAS,EAAE,GAAG,QAAQ,MAAM,GAAG,QAAQ,KAAK,GAAG,KAAI;MACnD,MAAM,kBAAkB,KAAK,QAAQ,SAAS;KACjD;EACL;;;;;;EAOA,MAAM,iBAAiB,SAA+B;AAClD,UAAM,EAAE,QAAQ,KAAI,IAAK;AAEzB,eAAW,YAAY,OAAO,KAAK,KAAK,QAAQ,GAAG;AAC/C,YAAM,KAAK,aAAa,EAAE,UAAU,MAAM,OAAM,CAAE;IACtD;EACJ;;;;;;EAOA,MAAM,iCACF,KAAqB;AAErB,QAAI,CAAC,KAAK,mBAAmB;AACzB;IACJ;AAEA,UAAM,UAAU,KAAK,0BAA0B,GAAG;AAClD,UAAM,WAAW,KAAK,YAAY,OAAO;AAEzC,QAAI,KAAK,gBAAgB,IAAI,QAAQ,GAAG;AACpC,WAAK,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;AACnD,WAAO,EAAE,KAAK,IAAI,QAAQ,KAAK,MAAM,IAAI,MAAM,MAAM,IAAI,QAAQ,KAAI;EACzE;;;;;;EAOQ,iBAAiB,UAAgB;AACrC,SAAK,SAAS,OAAO,QAAQ;AAC7B,SAAK,gBAAgB,OAAO,QAAQ;AAEpC,QAAI,KAAK,qBAAqB;AAC1B,WAAK,oBAAoB,EAAE,UAAU,QAAQ,UAAS,CAAE;IAC5D;EACJ;;",
6
6
  "names": []
7
7
  }
@@ -1,12 +1,16 @@
1
1
  type Callback = (...args: any[]) => void | Promise<void>;
2
2
  type OptionalCallback = undefined | Callback;
3
3
  type Pattern = string | string[];
4
+ /** Options for validating an object/state id */
4
5
  export interface ValidateIdOptions {
5
6
  /** in maintenance mode, we can access invalid ids to delete them, only works with the admin user */
6
7
  maintenance?: boolean;
7
8
  /** User used to check for access rights */
8
9
  user?: string;
9
10
  }
11
+ /**
12
+ * Validates arguments passed to the adapter's public methods
13
+ */
10
14
  export declare class Validator {
11
15
  private readonly objects;
12
16
  private readonly states;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/adapter/validator.ts"],
4
- "sourcesContent": ["import { MAX_TIMEOUT, SYSTEM_ADMIN_USER } from '@/lib/adapter/constants.js';\nimport { tools, EXIT_CODES } from '@iobroker/js-controller-common';\n\ntype Callback = (...args: any[]) => void | Promise<void>;\ntype OptionalCallback = undefined | Callback;\ntype Pattern = string | string[];\n\nexport interface ValidateIdOptions {\n /** in maintenance mode, we can access invalid ids to delete them, only works with the admin user */\n maintenance?: boolean;\n /** User used to check for access rights */\n user?: string;\n}\n\nexport class Validator {\n private readonly objects: any;\n private readonly states: any;\n private readonly namespaceLog: string;\n private readonly log: any;\n private readonly namespace: string;\n private readonly namespaceRegExp: RegExp;\n\n /**\n * Validator for internal adapter.js usage\n *\n * @param objects - Objects DB\n * @param states - States DB\n * @param namespaceLog - Log prefix\n * @param logger - Logger instance\n * @param namespace - the namespace of the adapter\n * @param namespaceRegExp - the namespace RegExp of the adapter `adapter.0`\n */\n constructor(\n objects: any,\n states: any,\n namespaceLog: string,\n logger: any,\n namespace: string,\n namespaceRegExp: RegExp,\n ) {\n this.objects = objects;\n this.states = states;\n this.namespaceLog = namespaceLog;\n this.namespace = namespace;\n this.namespaceRegExp = namespaceRegExp;\n this.log = logger;\n }\n\n /**\n * Performs the strict object check, which includes checking object existence, read-only logic, type and min/max\n * additionally it rounds state values whose objects have a `common.step` attribute defined\n *\n * @param id - id of the state\n * @param state - ioBroker setState object\n */\n async performStrictObjectCheck(id: string, state: ioBroker.SettableState): Promise<void> {\n // TODO: in js-c 3.5 (or 2 releases after 3.3) we should let it throw and add tests, maybe we\n // can already let the non existing object case throw with 3.4 because this is already producing a warning\n try {\n if (state.val === undefined) {\n // only ack etc. is also possible to acknowledge the current value,\n // if only undefined provided, it should have thrown before\n return;\n }\n\n const obj = await this.objects.getObjectAsync(id);\n // at first check object existence\n if (!obj) {\n this.log.warn(\n `${this.namespaceLog} State \"${id}\" has no existing object, this might lead to an error in future versions`,\n );\n return;\n }\n\n // for a state object, we require common.type to exist\n if (obj.common?.type) {\n // check if we are allowed to write (read-only can only be written with ack: true)\n if (!state.ack && obj.common.write === false) {\n this.log.warn(\n `${this.namespaceLog} Read-only state \"${id}\" has been written without ack-flag with value \"${state.val}\"`,\n );\n }\n\n if (state.val !== null) {\n // now check if a type is correct, null is always allowed\n if (\n !(\n (obj.common.type === 'mixed' && typeof state.val !== 'object') ||\n (obj.common.type !== 'object' && obj.common.type === typeof state.val) ||\n (obj.common.type === 'array' && typeof state.val === 'string') ||\n (obj.common.type === 'json' && typeof state.val === 'string') ||\n (obj.common.type === 'object' && typeof state.val === 'string')\n )\n ) {\n // types can be 'number', 'string', 'boolean', 'array', 'object', 'mixed', 'json';\n // 'array', 'object', 'json' need to be string\n if (['object', 'json', 'array'].includes(obj.common.type)) {\n this.log.info(\n `${\n this.namespaceLog\n } State value to set for \"${id}\" has to be stringified but received type \"${typeof state.val}\"`,\n );\n } else {\n this.log.info(\n `${this.namespaceLog} State value to set for \"${id}\" has to be ${\n obj.common.type === 'mixed'\n ? `one of type \"string\", \"number\", \"boolean\"`\n : `type \"${obj.common.type}\"`\n } but received type \"${typeof state.val}\" `,\n );\n }\n }\n\n // now round step and check min/max if it's a number\n if (typeof state.val === 'number') {\n if (typeof obj.common.step === 'number' && obj.common.step > 0) {\n // round to next step\n const inv = 1 / obj.common.step;\n state.val = Math.round(state.val * inv) / inv;\n }\n\n if (obj.common.max !== undefined && state.val > obj.common.max) {\n this.log.warn(\n `${this.namespaceLog} State value to set for \"${id}\" has value \"${state.val}\" greater than max \"${obj.common.max}\"`,\n );\n }\n\n if (obj.common.min !== undefined && state.val < obj.common.min) {\n this.log.warn(\n `${this.namespaceLog} State value to set for \"${id}\" has value \"${state.val}\" less than min \"${obj.common.min}\"`,\n );\n }\n }\n }\n } else {\n this.log.warn(\n `${this.namespaceLog} Object of state \"${id}\" is missing the required property \"common.type\"`,\n );\n }\n } catch (e) {\n this.log.warn(`${this.namespaceLog} Could not perform strict object check of state ${id}: ${e.message}`);\n }\n }\n\n /**\n * Checks if a passed ID is valid. Throws an error if id is invalid\n *\n * @param id id to check or object with properties device, channel and state\n * @param isForeignId true&false if the ID is a foreign/full ID or only an \"adapter local\" id\n * @param options optional\n * @throws Error when id is invalid\n */\n validateId(id: any, isForeignId: boolean, options?: ValidateIdOptions | null): asserts id is string {\n // there is a special maintenance mode to clear the DB from invalid IDs\n if (options && options.maintenance && options.user === SYSTEM_ADMIN_USER) {\n return;\n }\n\n if (!id && id !== 0) {\n throw new Error('The id is empty! Please provide a valid id.');\n }\n\n const type = typeof id;\n\n if (!isForeignId && type === 'number') {\n this.log.warn(\n `${this.namespaceLog} The id \"${id}\" has an invalid type! Expected \"string\" or \"object\", received \"number\".`,\n );\n this.log.warn(\n `${this.namespaceLog} This will be refused in future versions. Please report this to the developer.`,\n );\n } else if (type !== 'string' && !tools.isObject(id)) {\n throw new Error(`The id \"${id}\" has an invalid type! Expected \"string\" or \"object\", received \"${type}\".`);\n }\n\n if (tools.isObject(id)) {\n // id can be an object, at least one of the following properties has to exist\n const reqProperties = ['device', 'channel', 'state'];\n let found = false;\n for (const reqProperty of reqProperties) {\n if (id[reqProperty] !== undefined) {\n if (typeof id[reqProperty] !== 'string') {\n throw new Error(\n `The id's property \"${reqProperty}\" of \"${JSON.stringify(\n id,\n )}\" has an invalid type! Expected \"string\", received \"${typeof id[reqProperty]}\".`,\n );\n }\n\n if (id[reqProperty].includes('.')) {\n throw new Error(\n `The id's property \"${reqProperty}\" of \"${JSON.stringify(\n id,\n )}\" contains the invalid character \".\"!`,\n );\n }\n found = true;\n }\n }\n if (!found) {\n throw new Error(\n `The id \"${JSON.stringify(\n id,\n )}\" is an invalid object! Expected at least one of the properties \"device\", \"channel\" or \"state\" to exist.`,\n );\n }\n } else {\n if (type !== 'string') {\n throw new Error(\n `The id \"${JSON.stringify(id)}\" has an invalid type! Expected \"string\", received \"${type}\".`,\n );\n }\n if (id.endsWith('.')) {\n throw new Error(`The id \"${id}\" is invalid. Ids are not allowed to end in \".\"`);\n }\n }\n }\n\n /**\n * Look up the error description for an error code\n *\n * @param code error code\n * @returns error description\n */\n static getErrorText(code: number): string {\n code = code || 0;\n return (EXIT_CODES[code] || code).toString();\n }\n\n /**\n * Throws if a type is not matching the expected type\n *\n * @param value value to check a type of\n * @param name name of the parameter for logging\n */\n static assertString(value: unknown, name: string): asserts value is string {\n if (typeof value !== 'string') {\n throw new Error(\n `Parameter \"${name}\" needs to be of type \"string\" but type \"${typeof value}\" has been passed`,\n );\n }\n }\n\n /**\n * Throws if a type is not a pattern\n *\n * @param value value to check a type of\n * @param name name of the parameter for logging\n */\n static assertPattern(value: unknown, name: string): asserts value is Pattern {\n if (typeof value !== 'string' && !Array.isArray(value)) {\n throw new Error(\n `Parameter \"${name}\" needs to be of type \"string\" or an array of type \"string\", \"${typeof value}\" has been passed`,\n );\n } else if (Array.isArray(value)) {\n for (const entry of value) {\n if (typeof entry !== 'string') {\n throw new Error(\n `Parameter \"${name}\" needs to be of type \"string\" or an array of type \"string\", but the array contains a value of type \"${typeof value}\"`,\n );\n }\n }\n }\n }\n\n /**\n * Throws if a type is not matching the expected type\n *\n * @param value value to check a type of\n * @param name name of the parameter for logging\n */\n static assertBoolean(value: unknown, name: string): asserts value is boolean {\n if (typeof value !== 'boolean') {\n throw new Error(\n `Parameter \"${name}\" needs to be of type \"boolean\" but type \"${typeof value}\" has been passed`,\n );\n }\n }\n\n /**\n * Throws if a type is not matching the expected type\n *\n * @param value value to check a type of\n * @param name name of the parameter for logging\n */\n static assertNumber(value: unknown, name: string): asserts value is number {\n if (typeof value !== 'number') {\n throw new Error(\n `Parameter \"${name}\" needs to be of type \"number\" but type \"${typeof value}\" has been passed`,\n );\n }\n }\n\n /**\n * Throws if a type is not matching the expected type\n *\n * @param value value to check a type of\n * @param name name of the parameter for logging\n */\n static assertObject<T extends Record<string, any> = Record<string, any>>(\n value: unknown,\n name: string,\n ): asserts value is T {\n if (!tools.isObject(value)) {\n throw new Error(`Parameter \"${name}\" needs to be a real object but type \"${typeof value}\" has been passed`);\n }\n }\n\n /**\n * Throws if a type is not an optional callback\n *\n * @param value value to check a type of\n * @param name name of the parameter for logging\n */\n static assertBuffer(value: unknown, name: string): asserts value is Buffer {\n if (!Buffer.isBuffer(value)) {\n throw new Error(`Parameter \"${name}\" needs to be a Buffer but type \"${typeof value}\" has been passed`);\n }\n }\n\n /**\n * Throws if a type is not an optional callback\n *\n * @param value value to check a type of\n * @param name name of the parameter for logging\n */\n static assertOptionalCallback(value: unknown, name: string): asserts value is OptionalCallback {\n if (value && typeof value !== 'function') {\n throw new Error(\n `Parameter \"${name}\" needs to be of type \"null\", \"undefined\" or \"function\" but type \"${typeof value}\" has been passed`,\n );\n }\n }\n\n /**\n * Throws if a type is not an optional callback\n *\n * @param value value to check a type of\n * @param name name of the parameter for logging\n */\n static assertCallback(value: unknown, name: string): asserts value is Callback {\n if (typeof value !== 'function') {\n throw new Error(\n `Parameter \"${name}\" needs to be of type \"function\" but type \"${typeof value}\" has been passed`,\n );\n }\n }\n\n /**\n * Adds the namespace to the ID if it is missing, if an object is passed it will be converted to an id string\n *\n * @param id id which will be fixed\n * @param isPattern if the id is a pattern\n */\n fixId(id: string | ioBroker.IdObject, isPattern = false): string {\n if (!id) {\n id = '';\n }\n\n let result = '';\n if (typeof id === 'string') {\n result = id;\n\n // if not the instance name itself and also not starts with namespace and \".\"\n if (id !== this.namespace && !this.namespaceRegExp.test(id)) {\n if (!isPattern) {\n result = this.namespace + (id ? `.${id}` : '');\n } else {\n result = `${this.namespace}.${id ? id : ''}`;\n }\n }\n } else if (tools.isObject(id)) {\n // If ID is an object\n // Add namespace + device + channel\n result = `${this.namespace}.${id.device ? `${id.device}.` : ''}${id.channel ? `${id.channel}.` : ''}${\n id.state ? id.state : ''\n }`;\n }\n return result;\n }\n\n /**\n * Validates the object-type argument that is passed to setState\n *\n * @param obj object to validate\n */\n validateSetStateObjectArgument(obj: Record<string, any>): void {\n // Check that we have at least one existing non-undefined property at all, else invalid\n if (!Object.values(obj).some(prop => prop !== undefined)) {\n throw new Error(`The state contains no properties! At least one property is expected!`);\n }\n\n /*\n The following object parameters and types are allowed:\n val: any, (optional)\n ack: boolean, (optional)\n ts: number, (optional)\n q: number, (optional)\n from: string, (optional)\n c: string, (optional)\n expire: number (optional)\n lc: number (optional)\n user: string (optional)\n\n Everything else is forbidden\n */\n const optionalProperties: Record<string, string> = {\n val: 'any',\n ack: 'boolean',\n ts: 'number',\n q: 'number',\n from: 'string',\n c: 'string',\n expire: 'number',\n lc: 'number',\n user: 'string',\n };\n\n // Are there any forbidden properties?\n const forbiddenProperties = Object.keys(obj).filter(k => !optionalProperties[k]);\n if (forbiddenProperties.length) {\n throw new Error(`The state contains the forbidden properties ${forbiddenProperties.join(', ')}!`);\n }\n // Do all properties have the correct type?\n for (const [key, type] of Object.entries(optionalProperties)) {\n // any permits all types\n if (type === 'any') {\n continue;\n }\n // don't flag optional properties when they don't exist or are undefined\n if (!(key in obj) || obj[key] === undefined) {\n continue;\n }\n if (type !== typeof obj[key]) {\n throw new Error(\n `The state property \"${key}\" has the wrong type \"${typeof obj[key]}\" (should be \"${type}\")!`,\n );\n }\n }\n }\n\n /**\n * Validates that the timeout is not exceeding a 32-bit signed integer\n *\n * @param ms milliseconds to validate\n */\n static assertTimeout(ms: number): void {\n if (ms > MAX_TIMEOUT) {\n throw new Error(`Timeout (${ms}) is larger than a 32-bit signed integer (${MAX_TIMEOUT})`);\n }\n\n if (ms < 0) {\n throw new Error(`Timeout (${ms}) is smaller than 0`);\n }\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,uBAA+C;AAC/C,kCAAkC;AAa5B,MAAO,UAAS;EACD;EACA;EACA;EACA;EACA;EACA;;;;;;;;;;;EAYjB,YACI,SACA,QACA,cACA,QACA,WACA,iBAAuB;AAEvB,SAAK,UAAU;AACf,SAAK,SAAS;AACd,SAAK,eAAe;AACpB,SAAK,YAAY;AACjB,SAAK,kBAAkB;AACvB,SAAK,MAAM;EACf;;;;;;;;EASA,MAAM,yBAAyB,IAAY,OAA6B;AAGpE,QAAI;AACA,UAAI,MAAM,QAAQ,QAAW;AAGzB;MACJ;AAEA,YAAM,MAAM,MAAM,KAAK,QAAQ,eAAe,EAAE;AAEhD,UAAI,CAAC,KAAK;AACN,aAAK,IAAI,KACL,GAAG,KAAK,YAAY,WAAW,EAAE,0EAA0E;AAE/G;MACJ;AAGA,UAAI,IAAI,QAAQ,MAAM;AAElB,YAAI,CAAC,MAAM,OAAO,IAAI,OAAO,UAAU,OAAO;AAC1C,eAAK,IAAI,KACL,GAAG,KAAK,YAAY,qBAAqB,EAAE,mDAAmD,MAAM,GAAG,GAAG;QAElH;AAEA,YAAI,MAAM,QAAQ,MAAM;AAEpB,cACI,EACK,IAAI,OAAO,SAAS,WAAW,OAAO,MAAM,QAAQ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AAG;MACH,QAAQ;MACR,IAAI;MACJ,MAAM;;AAIV,UAAM,sBAAsB,OAAO,KAAK,GAAG,EAAE,OAAO,OAAK,CAAC,mBAAmB,CAAC,CAAC;AAC/E,QAAI,oBAAoB,QAAQ;AAC5B,YAAM,IAAI,MAAM,+CAA+C,oBAAoB,KAAK,IAAI,CAAC,GAAG;IACpG;AAEA,eAAW,CAAC,KAAK,IAAI,KAAK,OAAO,QAAQ,kBAAkB,GAAG;AAE1D,UAAI,SAAS,OAAO;AAChB;MACJ;AAEA,UAAI,EAAE,OAAO,QAAQ,IAAI,GAAG,MAAM,QAAW;AACzC;MACJ;AACA,UAAI,SAAS,OAAO,IAAI,GAAG,GAAG;AAC1B,cAAM,IAAI,MACN,uBAAuB,GAAG,yBAAyB,OAAO,IAAI,GAAG,CAAC,iBAAiB,IAAI,KAAK;MAEpG;IACJ;EACJ;;;;;;EAOA,OAAO,cAAc,IAAU;AAC3B,QAAI,KAAK,8BAAa;AAClB,YAAM,IAAI,MAAM,YAAY,EAAE,6CAA6C,4BAAW,GAAG;IAC7F;AAEA,QAAI,KAAK,GAAG;AACR,YAAM,IAAI,MAAM,YAAY,EAAE,qBAAqB;IACvD;EACJ;;",
4
+ "sourcesContent": ["import { MAX_TIMEOUT, SYSTEM_ADMIN_USER } from '@/lib/adapter/constants.js';\nimport { tools, EXIT_CODES } from '@iobroker/js-controller-common';\n\ntype Callback = (...args: any[]) => void | Promise<void>;\ntype OptionalCallback = undefined | Callback;\ntype Pattern = string | string[];\n\n/** Options for validating an object/state id */\nexport interface ValidateIdOptions {\n /** in maintenance mode, we can access invalid ids to delete them, only works with the admin user */\n maintenance?: boolean;\n /** User used to check for access rights */\n user?: string;\n}\n\n/**\n * Validates arguments passed to the adapter's public methods\n */\nexport class Validator {\n private readonly objects: any;\n private readonly states: any;\n private readonly namespaceLog: string;\n private readonly log: any;\n private readonly namespace: string;\n private readonly namespaceRegExp: RegExp;\n\n /**\n * Validator for internal adapter.js usage\n *\n * @param objects - Objects DB\n * @param states - States DB\n * @param namespaceLog - Log prefix\n * @param logger - Logger instance\n * @param namespace - the namespace of the adapter\n * @param namespaceRegExp - the namespace RegExp of the adapter `adapter.0`\n */\n constructor(\n objects: any,\n states: any,\n namespaceLog: string,\n logger: any,\n namespace: string,\n namespaceRegExp: RegExp,\n ) {\n this.objects = objects;\n this.states = states;\n this.namespaceLog = namespaceLog;\n this.namespace = namespace;\n this.namespaceRegExp = namespaceRegExp;\n this.log = logger;\n }\n\n /**\n * Performs the strict object check, which includes checking object existence, read-only logic, type and min/max\n * additionally it rounds state values whose objects have a `common.step` attribute defined\n *\n * @param id - id of the state\n * @param state - ioBroker setState object\n */\n async performStrictObjectCheck(id: string, state: ioBroker.SettableState): Promise<void> {\n // TODO: in js-c 3.5 (or 2 releases after 3.3) we should let it throw and add tests, maybe we\n // can already let the non existing object case throw with 3.4 because this is already producing a warning\n try {\n if (state.val === undefined) {\n // only ack etc. is also possible to acknowledge the current value,\n // if only undefined provided, it should have thrown before\n return;\n }\n\n const obj = await this.objects.getObjectAsync(id);\n // at first check object existence\n if (!obj) {\n this.log.warn(\n `${this.namespaceLog} State \"${id}\" has no existing object, this might lead to an error in future versions`,\n );\n return;\n }\n\n // for a state object, we require common.type to exist\n if (obj.common?.type) {\n // check if we are allowed to write (read-only can only be written with ack: true)\n if (!state.ack && obj.common.write === false) {\n this.log.warn(\n `${this.namespaceLog} Read-only state \"${id}\" has been written without ack-flag with value \"${state.val}\"`,\n );\n }\n\n if (state.val !== null) {\n // now check if a type is correct, null is always allowed\n if (\n !(\n (obj.common.type === 'mixed' && typeof state.val !== 'object') ||\n (obj.common.type !== 'object' && obj.common.type === typeof state.val) ||\n (obj.common.type === 'array' && typeof state.val === 'string') ||\n (obj.common.type === 'json' && typeof state.val === 'string') ||\n (obj.common.type === 'object' && typeof state.val === 'string')\n )\n ) {\n // types can be 'number', 'string', 'boolean', 'array', 'object', 'mixed', 'json';\n // 'array', 'object', 'json' need to be string\n if (['object', 'json', 'array'].includes(obj.common.type)) {\n this.log.info(\n `${\n this.namespaceLog\n } State value to set for \"${id}\" has to be stringified but received type \"${typeof state.val}\"`,\n );\n } else {\n this.log.info(\n `${this.namespaceLog} State value to set for \"${id}\" has to be ${\n obj.common.type === 'mixed'\n ? `one of type \"string\", \"number\", \"boolean\"`\n : `type \"${obj.common.type}\"`\n } but received type \"${typeof state.val}\" `,\n );\n }\n }\n\n // now round step and check min/max if it's a number\n if (typeof state.val === 'number') {\n if (typeof obj.common.step === 'number' && obj.common.step > 0) {\n // round to next step\n const inv = 1 / obj.common.step;\n state.val = Math.round(state.val * inv) / inv;\n }\n\n if (obj.common.max !== undefined && state.val > obj.common.max) {\n this.log.warn(\n `${this.namespaceLog} State value to set for \"${id}\" has value \"${state.val}\" greater than max \"${obj.common.max}\"`,\n );\n }\n\n if (obj.common.min !== undefined && state.val < obj.common.min) {\n this.log.warn(\n `${this.namespaceLog} State value to set for \"${id}\" has value \"${state.val}\" less than min \"${obj.common.min}\"`,\n );\n }\n }\n }\n } else {\n this.log.warn(\n `${this.namespaceLog} Object of state \"${id}\" is missing the required property \"common.type\"`,\n );\n }\n } catch (e) {\n this.log.warn(`${this.namespaceLog} Could not perform strict object check of state ${id}: ${e.message}`);\n }\n }\n\n /**\n * Checks if a passed ID is valid. Throws an error if id is invalid\n *\n * @param id id to check or object with properties device, channel and state\n * @param isForeignId true&false if the ID is a foreign/full ID or only an \"adapter local\" id\n * @param options optional\n * @throws Error when id is invalid\n */\n validateId(id: any, isForeignId: boolean, options?: ValidateIdOptions | null): asserts id is string {\n // there is a special maintenance mode to clear the DB from invalid IDs\n if (options && options.maintenance && options.user === SYSTEM_ADMIN_USER) {\n return;\n }\n\n if (!id && id !== 0) {\n throw new Error('The id is empty! Please provide a valid id.');\n }\n\n const type = typeof id;\n\n if (!isForeignId && type === 'number') {\n this.log.warn(\n `${this.namespaceLog} The id \"${id}\" has an invalid type! Expected \"string\" or \"object\", received \"number\".`,\n );\n this.log.warn(\n `${this.namespaceLog} This will be refused in future versions. Please report this to the developer.`,\n );\n } else if (type !== 'string' && !tools.isObject(id)) {\n throw new Error(`The id \"${id}\" has an invalid type! Expected \"string\" or \"object\", received \"${type}\".`);\n }\n\n if (tools.isObject(id)) {\n // id can be an object, at least one of the following properties has to exist\n const reqProperties = ['device', 'channel', 'state'];\n let found = false;\n for (const reqProperty of reqProperties) {\n if (id[reqProperty] !== undefined) {\n if (typeof id[reqProperty] !== 'string') {\n throw new Error(\n `The id's property \"${reqProperty}\" of \"${JSON.stringify(\n id,\n )}\" has an invalid type! Expected \"string\", received \"${typeof id[reqProperty]}\".`,\n );\n }\n\n if (id[reqProperty].includes('.')) {\n throw new Error(\n `The id's property \"${reqProperty}\" of \"${JSON.stringify(\n id,\n )}\" contains the invalid character \".\"!`,\n );\n }\n found = true;\n }\n }\n if (!found) {\n throw new Error(\n `The id \"${JSON.stringify(\n id,\n )}\" is an invalid object! Expected at least one of the properties \"device\", \"channel\" or \"state\" to exist.`,\n );\n }\n } else {\n if (type !== 'string') {\n throw new Error(\n `The id \"${JSON.stringify(id)}\" has an invalid type! Expected \"string\", received \"${type}\".`,\n );\n }\n if (id.endsWith('.')) {\n throw new Error(`The id \"${id}\" is invalid. Ids are not allowed to end in \".\"`);\n }\n }\n }\n\n /**\n * Look up the error description for an error code\n *\n * @param code error code\n * @returns error description\n */\n static getErrorText(code: number): string {\n code = code || 0;\n return (EXIT_CODES[code] || code).toString();\n }\n\n /**\n * Throws if a type is not matching the expected type\n *\n * @param value value to check a type of\n * @param name name of the parameter for logging\n */\n static assertString(value: unknown, name: string): asserts value is string {\n if (typeof value !== 'string') {\n throw new Error(\n `Parameter \"${name}\" needs to be of type \"string\" but type \"${typeof value}\" has been passed`,\n );\n }\n }\n\n /**\n * Throws if a type is not a pattern\n *\n * @param value value to check a type of\n * @param name name of the parameter for logging\n */\n static assertPattern(value: unknown, name: string): asserts value is Pattern {\n if (typeof value !== 'string' && !Array.isArray(value)) {\n throw new Error(\n `Parameter \"${name}\" needs to be of type \"string\" or an array of type \"string\", \"${typeof value}\" has been passed`,\n );\n } else if (Array.isArray(value)) {\n for (const entry of value) {\n if (typeof entry !== 'string') {\n throw new Error(\n `Parameter \"${name}\" needs to be of type \"string\" or an array of type \"string\", but the array contains a value of type \"${typeof value}\"`,\n );\n }\n }\n }\n }\n\n /**\n * Throws if a type is not matching the expected type\n *\n * @param value value to check a type of\n * @param name name of the parameter for logging\n */\n static assertBoolean(value: unknown, name: string): asserts value is boolean {\n if (typeof value !== 'boolean') {\n throw new Error(\n `Parameter \"${name}\" needs to be of type \"boolean\" but type \"${typeof value}\" has been passed`,\n );\n }\n }\n\n /**\n * Throws if a type is not matching the expected type\n *\n * @param value value to check a type of\n * @param name name of the parameter for logging\n */\n static assertNumber(value: unknown, name: string): asserts value is number {\n if (typeof value !== 'number') {\n throw new Error(\n `Parameter \"${name}\" needs to be of type \"number\" but type \"${typeof value}\" has been passed`,\n );\n }\n }\n\n /**\n * Throws if a type is not matching the expected type\n *\n * @param value value to check a type of\n * @param name name of the parameter for logging\n */\n static assertObject<T extends Record<string, any> = Record<string, any>>(\n value: unknown,\n name: string,\n ): asserts value is T {\n if (!tools.isObject(value)) {\n throw new Error(`Parameter \"${name}\" needs to be a real object but type \"${typeof value}\" has been passed`);\n }\n }\n\n /**\n * Throws if a type is not an optional callback\n *\n * @param value value to check a type of\n * @param name name of the parameter for logging\n */\n static assertBuffer(value: unknown, name: string): asserts value is Buffer {\n if (!Buffer.isBuffer(value)) {\n throw new Error(`Parameter \"${name}\" needs to be a Buffer but type \"${typeof value}\" has been passed`);\n }\n }\n\n /**\n * Throws if a type is not an optional callback\n *\n * @param value value to check a type of\n * @param name name of the parameter for logging\n */\n static assertOptionalCallback(value: unknown, name: string): asserts value is OptionalCallback {\n if (value && typeof value !== 'function') {\n throw new Error(\n `Parameter \"${name}\" needs to be of type \"null\", \"undefined\" or \"function\" but type \"${typeof value}\" has been passed`,\n );\n }\n }\n\n /**\n * Throws if a type is not an optional callback\n *\n * @param value value to check a type of\n * @param name name of the parameter for logging\n */\n static assertCallback(value: unknown, name: string): asserts value is Callback {\n if (typeof value !== 'function') {\n throw new Error(\n `Parameter \"${name}\" needs to be of type \"function\" but type \"${typeof value}\" has been passed`,\n );\n }\n }\n\n /**\n * Adds the namespace to the ID if it is missing, if an object is passed it will be converted to an id string\n *\n * @param id id which will be fixed\n * @param isPattern if the id is a pattern\n */\n fixId(id: string | ioBroker.IdObject, isPattern = false): string {\n if (!id) {\n id = '';\n }\n\n let result = '';\n if (typeof id === 'string') {\n result = id;\n\n // if not the instance name itself and also not starts with namespace and \".\"\n if (id !== this.namespace && !this.namespaceRegExp.test(id)) {\n if (!isPattern) {\n result = this.namespace + (id ? `.${id}` : '');\n } else {\n result = `${this.namespace}.${id ? id : ''}`;\n }\n }\n } else if (tools.isObject(id)) {\n // If ID is an object\n // Add namespace + device + channel\n result = `${this.namespace}.${id.device ? `${id.device}.` : ''}${id.channel ? `${id.channel}.` : ''}${\n id.state ? id.state : ''\n }`;\n }\n return result;\n }\n\n /**\n * Validates the object-type argument that is passed to setState\n *\n * @param obj object to validate\n */\n validateSetStateObjectArgument(obj: Record<string, any>): void {\n // Check that we have at least one existing non-undefined property at all, else invalid\n if (!Object.values(obj).some(prop => prop !== undefined)) {\n throw new Error(`The state contains no properties! At least one property is expected!`);\n }\n\n /*\n The following object parameters and types are allowed:\n val: any, (optional)\n ack: boolean, (optional)\n ts: number, (optional)\n q: number, (optional)\n from: string, (optional)\n c: string, (optional)\n expire: number (optional)\n lc: number (optional)\n user: string (optional)\n\n Everything else is forbidden\n */\n const optionalProperties: Record<string, string> = {\n val: 'any',\n ack: 'boolean',\n ts: 'number',\n q: 'number',\n from: 'string',\n c: 'string',\n expire: 'number',\n lc: 'number',\n user: 'string',\n };\n\n // Are there any forbidden properties?\n const forbiddenProperties = Object.keys(obj).filter(k => !optionalProperties[k]);\n if (forbiddenProperties.length) {\n throw new Error(`The state contains the forbidden properties ${forbiddenProperties.join(', ')}!`);\n }\n // Do all properties have the correct type?\n for (const [key, type] of Object.entries(optionalProperties)) {\n // any permits all types\n if (type === 'any') {\n continue;\n }\n // don't flag optional properties when they don't exist or are undefined\n if (!(key in obj) || obj[key] === undefined) {\n continue;\n }\n if (type !== typeof obj[key]) {\n throw new Error(\n `The state property \"${key}\" has the wrong type \"${typeof obj[key]}\" (should be \"${type}\")!`,\n );\n }\n }\n }\n\n /**\n * Validates that the timeout is not exceeding a 32-bit signed integer\n *\n * @param ms milliseconds to validate\n */\n static assertTimeout(ms: number): void {\n if (ms > MAX_TIMEOUT) {\n throw new Error(`Timeout (${ms}) is larger than a 32-bit signed integer (${MAX_TIMEOUT})`);\n }\n\n if (ms < 0) {\n throw new Error(`Timeout (${ms}) is smaller than 0`);\n }\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,uBAA+C;AAC/C,kCAAkC;AAiB5B,MAAO,UAAS;EACD;EACA;EACA;EACA;EACA;EACA;;;;;;;;;;;EAYjB,YACI,SACA,QACA,cACA,QACA,WACA,iBAAuB;AAEvB,SAAK,UAAU;AACf,SAAK,SAAS;AACd,SAAK,eAAe;AACpB,SAAK,YAAY;AACjB,SAAK,kBAAkB;AACvB,SAAK,MAAM;EACf;;;;;;;;EASA,MAAM,yBAAyB,IAAY,OAA6B;AAGpE,QAAI;AACA,UAAI,MAAM,QAAQ,QAAW;AAGzB;MACJ;AAEA,YAAM,MAAM,MAAM,KAAK,QAAQ,eAAe,EAAE;AAEhD,UAAI,CAAC,KAAK;AACN,aAAK,IAAI,KACL,GAAG,KAAK,YAAY,WAAW,EAAE,0EAA0E;AAE/G;MACJ;AAGA,UAAI,IAAI,QAAQ,MAAM;AAElB,YAAI,CAAC,MAAM,OAAO,IAAI,OAAO,UAAU,OAAO;AAC1C,eAAK,IAAI,KACL,GAAG,KAAK,YAAY,qBAAqB,EAAE,mDAAmD,MAAM,GAAG,GAAG;QAElH;AAEA,YAAI,MAA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