@iobroker/db-objects-jsonl 4.0.23 → 4.1.0-alpha.0-20220804-d8f17893

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.
@@ -0,0 +1,4 @@
1
+ export const Client: typeof import("@iobroker/db-objects-redis").Client;
2
+ export const Server: typeof import("./lib/objects/objectsInMemServerClass.js");
3
+ export function getDefaultPort(_host: any): number;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  module.exports = {
2
3
  Client: require('@iobroker/db-objects-redis').Client,
3
4
  Server: require('./lib/objects/objectsInMemServerClass.js'),
@@ -5,3 +6,4 @@ module.exports = {
5
6
  return 9001;
6
7
  }
7
8
  };
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,21 @@
1
+ export = ObjectsInMemoryJsonlDB;
2
+ declare const ObjectsInMemoryJsonlDB_base: typeof import("@iobroker/db-objects-file/build/lib/objects/objectsInMemFileDB");
3
+ /**
4
+ * This class inherits InMemoryFileDB class and adds all relevant logic for objects
5
+ * including the available methods for use by js-controller directly
6
+ **/
7
+ declare class ObjectsInMemoryJsonlDB extends ObjectsInMemoryJsonlDB_base {
8
+ constructor(settings: any);
9
+ /** @type {JsonlDB<any>} */
10
+ _db: JsonlDB<any>;
11
+ _backupInterval: NodeJS.Timer | undefined;
12
+ /**
13
+ * Checks if an existing file DB should be migrated to JSONL
14
+ * @returns {Promise<boolean>} true if the file DB was migrated. false if not.
15
+ * If this returns true, the jsonl DB was opened and doesn't need to be opened again.
16
+ */
17
+ _maybeMigrateFileDB(): Promise<boolean>;
18
+ saveBackup(): Promise<void>;
19
+ }
20
+ import { JsonlDB } from "@alcalzone/jsonl-db";
21
+ //# sourceMappingURL=objectsInMemJsonlDB.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objectsInMemJsonlDB.d.ts","sourceRoot":"","sources":["../../../src/lib/objects/objectsInMemJsonlDB.js"],"names":[],"mappings":";;AAoFA;;;IAGI;AACJ;IACI,2BAeC;IAFG,2BAA2B;IAC3B,KADW,QAAQ,GAAG,CAAC,CACiE;IA6CpF,0CAE+B;IAIvC;;;;OAIG;IACH,uBAHa,QAAQ,OAAO,CAAC,CAwE5B;IAOD,4BA2BC;CAYJ"}
@@ -6,20 +6,17 @@
6
6
  * MIT License
7
7
  *
8
8
  */
9
-
10
9
  /* jshint -W097 */
11
10
  /* jshint strict: false */
12
11
  /* jslint node: true */
13
12
  /* jshint -W061 */
14
13
  'use strict';
15
-
16
- const ObjectsInMemoryFileDB = require('@iobroker/db-objects-file').ObjectsInMemoryFileDB;
14
+ const { ObjectsInMemoryFileDB } = require('@iobroker/db-objects-file');
17
15
  const { JsonlDB } = require('@alcalzone/jsonl-db');
18
16
  const path = require('path');
19
17
  const fs = require('fs');
20
18
  const os = require('os');
21
19
  const { tools } = require('@iobroker/js-controller-common');
22
-
23
20
  /**
24
21
  * Normalizes options for the JsonlDB
25
22
  * @param {Record<string, any> | undefined} conf The jsonlOptions options from iobroker.json
@@ -46,7 +43,6 @@ function normalizeJsonlOptions(conf = {}) {
46
43
  staleMs: 2000
47
44
  }
48
45
  };
49
-
50
46
  // Be really careful what we allow here. Incorrect settings may cause problems in production.
51
47
  if (tools.isObject(conf.autoCompress)) {
52
48
  const ac = conf.autoCompress;
@@ -55,11 +51,9 @@ function normalizeJsonlOptions(conf = {}) {
55
51
  ret.autoCompress.sizeFactor = ac.sizeFactor;
56
52
  }
57
53
  // Also we should definitely compress once the DB has reached 100k lines or it might grow too big
58
- if (
59
- typeof ac.sizeFactorMinimumSize === 'number' &&
54
+ if (typeof ac.sizeFactorMinimumSize === 'number' &&
60
55
  ac.sizeFactorMinimumSize >= 0 &&
61
- ac.sizeFactorMinimumSize <= 100000
62
- ) {
56
+ ac.sizeFactorMinimumSize <= 100000) {
63
57
  ret.autoCompress.sizeFactorMinimumSize = ac.sizeFactorMinimumSize;
64
58
  }
65
59
  }
@@ -70,18 +64,14 @@ function normalizeJsonlOptions(conf = {}) {
70
64
  ret.throttleFS.intervalMs = thr.intervalMs;
71
65
  }
72
66
  // Don't keep too much in memory - 100k changes are more than enough
73
- if (
74
- typeof thr.maxBufferedCommands === 'number' &&
67
+ if (typeof thr.maxBufferedCommands === 'number' &&
75
68
  thr.maxBufferedCommands >= 0 &&
76
- thr.maxBufferedCommands <= 100000
77
- ) {
69
+ thr.maxBufferedCommands <= 100000) {
78
70
  ret.throttleFS.maxBufferedCommands = thr.maxBufferedCommands;
79
71
  }
80
72
  }
81
-
82
73
  return ret;
83
74
  }
84
-
85
75
  /**
86
76
  * This class inherits InMemoryFileDB class and adds all relevant logic for objects
87
77
  * including the available methods for use by js-controller directly
@@ -93,22 +83,18 @@ class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {
93
83
  fileName: 'objects.json',
94
84
  backupDirName: 'backup-objects'
95
85
  };
96
-
97
86
  const jsonlOptions = normalizeJsonlOptions(settings.connection.jsonlOptions);
98
87
  settings.jsonlDB = {
99
88
  fileName: 'objects.jsonl'
100
89
  };
101
90
  super(settings);
102
-
103
91
  /** @type {JsonlDB<any>} */
104
92
  this._db = new JsonlDB(path.join(this.dataDir, settings.jsonlDB.fileName), jsonlOptions);
105
93
  }
106
-
107
94
  async open() {
108
95
  if (!(await this._maybeMigrateFileDB())) {
109
96
  await this._db.open();
110
97
  }
111
-
112
98
  // Create an object-like wrapper around the internal Map
113
99
  this.dataset = new Proxy(this._db, {
114
100
  /** @param {any} prop */
@@ -144,14 +130,12 @@ class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {
144
130
  };
145
131
  }
146
132
  });
147
-
148
133
  if (this.settings.backup && this.settings.backup.period && !this.settings.backup.disabled) {
149
134
  this._backupInterval = setInterval(() => {
150
135
  this.saveBackup();
151
136
  }, this.settings.backup.period);
152
137
  }
153
138
  }
154
-
155
139
  /**
156
140
  * Checks if an existing file DB should be migrated to JSONL
157
141
  * @returns {Promise<boolean>} true if the file DB was migrated. false if not.
@@ -161,7 +145,6 @@ class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {
161
145
  const jsonlFileName = path.join(this.dataDir, this.settings.jsonlDB.fileName);
162
146
  const jsonFileName = path.join(this.dataDir, this.settings.fileDB.fileName);
163
147
  const bakFileName = path.join(this.dataDir, this.settings.fileDB.fileName + '.bak');
164
-
165
148
  // Check the timestamps of each file, defaulting to 0 if they don't exist
166
149
  let jsonlTimeStamp = 0;
167
150
  let jsonTimeStamp = 0;
@@ -171,7 +154,8 @@ class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {
171
154
  if (stat.isFile()) {
172
155
  jsonlTimeStamp = stat.mtime;
173
156
  }
174
- } catch {
157
+ }
158
+ catch {
175
159
  // ignore
176
160
  }
177
161
  try {
@@ -179,7 +163,8 @@ class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {
179
163
  if (stat.isFile()) {
180
164
  jsonTimeStamp = stat.mtime;
181
165
  }
182
- } catch {
166
+ }
167
+ catch {
183
168
  // ignore
184
169
  }
185
170
  try {
@@ -187,84 +172,76 @@ class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {
187
172
  if (stat.isFile()) {
188
173
  bakTimeStamp = stat.mtime;
189
174
  }
190
- } catch {
175
+ }
176
+ catch {
191
177
  // ignore
192
178
  }
193
-
194
179
  // Figure out which file needs to be imported
195
180
  /** @type {string} */
196
181
  let importFilename;
197
182
  if (jsonTimeStamp > 0 && jsonTimeStamp >= bakTimeStamp && jsonTimeStamp >= jsonlTimeStamp) {
198
183
  importFilename = jsonFileName;
199
- } else if (bakTimeStamp > 0 && bakTimeStamp >= jsonTimeStamp && bakTimeStamp >= jsonlTimeStamp) {
184
+ }
185
+ else if (bakTimeStamp > 0 && bakTimeStamp >= jsonTimeStamp && bakTimeStamp >= jsonlTimeStamp) {
200
186
  importFilename = bakFileName;
201
- } else {
187
+ }
188
+ else {
202
189
  // None of the File DB files are newer than the JSONL file
203
190
  // There is nothing to restore, we're done
204
191
  return false;
205
192
  }
206
-
207
193
  await this._db.open();
208
194
  this._db.clear();
209
195
  await this._db.importJson(importFilename);
210
-
211
196
  // And rename the existing files to avoid redoing the work next time
212
197
  if (fs.existsSync(jsonFileName)) {
213
198
  try {
214
199
  fs.renameSync(jsonFileName, `${jsonFileName}.migrated`);
215
- } catch {
200
+ }
201
+ catch {
216
202
  // ignore
217
203
  }
218
204
  }
219
205
  if (fs.existsSync(bakFileName)) {
220
206
  try {
221
207
  fs.renameSync(bakFileName, `${bakFileName}.migrated`);
222
- } catch {
208
+ }
209
+ catch {
223
210
  // ignore
224
211
  }
225
212
  }
226
-
227
213
  // Signal to the caller that the DB is already open
228
214
  return true;
229
215
  }
230
-
231
216
  async saveState() {
232
217
  // Nothing to do, the DB saves behind the scenes
233
218
  }
234
-
235
219
  // Is regularly called and stores a compressed backup of the DB
236
220
  async saveBackup() {
237
221
  const now = Date.now();
238
222
  const tmpBackupFileName = path.join(os.tmpdir(), `${this.getTimeStr(now)}_${this.settings.jsonlDB.fileName}`);
239
- const backupFileName = path.join(
240
- this.backupDir,
241
- `${this.getTimeStr(now)}_${this.settings.jsonlDB.fileName}.gz`
242
- );
243
-
223
+ const backupFileName = path.join(this.backupDir, `${this.getTimeStr(now)}_${this.settings.jsonlDB.fileName}.gz`);
244
224
  if (!this._db.isOpen) {
245
225
  this.log.warn(`${this.namespace} Cannot save backup ${backupFileName}: DB is closed`);
246
226
  return;
247
227
  }
248
-
249
228
  try {
250
229
  if (fs.existsSync(backupFileName)) {
251
230
  return;
252
231
  }
253
-
254
232
  // Create a DB dump
255
233
  await this._db.dump(tmpBackupFileName);
256
234
  // and zip it
257
235
  await tools.compressFileGZip(tmpBackupFileName, backupFileName, { deleteInput: true });
258
236
  // figure out if older files need to be deleted
259
237
  this.deleteOldBackupFiles(this.settings.jsonlDB.fileName);
260
- } catch (e) {
238
+ }
239
+ catch (e) {
261
240
  this.log.error(`${this.namespace} Cannot save backup ${backupFileName}: ${e.message}`);
262
241
  }
263
242
  }
264
-
265
243
  async destroy() {
266
244
  await super.destroy();
267
-
268
245
  if (this._backupInterval) {
269
246
  clearInterval(this._backupInterval);
270
247
  }
@@ -273,5 +250,5 @@ class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {
273
250
  }
274
251
  }
275
252
  }
276
-
277
253
  module.exports = ObjectsInMemoryJsonlDB;
254
+ //# sourceMappingURL=objectsInMemJsonlDB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objectsInMemJsonlDB.js","sourceRoot":"","sources":["../../../src/lib/objects/objectsInMemJsonlDB.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,kBAAkB;AAClB,0BAA0B;AAC1B,uBAAuB;AACvB,kBAAkB;AAClB,YAAY,CAAC;AAEb,MAAM,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AACvE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;AACnD,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACzB,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACzB,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,gCAAgC,CAAC,CAAC;AAE5D;;;;GAIG;AACH,SAAS,qBAAqB,CAAC,IAAI,GAAG,EAAE;IACpC,gEAAgE;IAChE,MAAM,GAAG,GAAG;QACR,YAAY,EAAE;YACV,UAAU,EAAE,CAAC;YACb,qBAAqB,EAAE,KAAK;SAC/B;QACD,gBAAgB,EAAE,IAAI;QACtB,UAAU,EAAE;YACR,UAAU,EAAE,KAAK;YACjB,mBAAmB,EAAE,IAAI;SAC5B;QACD,QAAQ,EAAE;YACN,uDAAuD;YACvD,oGAAoG;YACpG,OAAO,EAAE,CAAC;YACV,iBAAiB,EAAE,GAAG;YACtB,iFAA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;YACA,IAAI,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE;gBAC/B,OAAO;aACV;YAED,mBAAmB;YACnB,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;YACvC,aAAa;YACb,MAAM,KAAK,CAAC,gBAAgB,CAAC,iBAAiB,EAAE,cAAc,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;YACvF,+CAA+C;YAC/C,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;SAC7D;QAAC,OAAO,CAAC,EAAE;YACR,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,uBAAuB,cAAc,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;SAC1F;IACL,CAAC;IAED,KAAK,CAAC,OAAO;QACT,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;QAEtB,IAAI,IAAI,CAAC,eAAe,EAAE;YACtB,aAAa,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;SACvC;QACD,IAAI,IAAI,CAAC,GAAG,EAAE;YACV,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;SAC1B;IACL,CAAC;CACJ;AAED,MAAM,CAAC,OAAO,GAAG,sBAAsB,CAAC"}
@@ -0,0 +1,14 @@
1
+ export = ObjectsInMemoryServerClass;
2
+ declare class ObjectsInMemoryServerClass extends ObjectsInRedisClient {
3
+ constructor(settings: any);
4
+ objectsServer: ObjectsInMemServer;
5
+ syncFileDirectory(limitId: any): {
6
+ numberSuccess: number;
7
+ notifications: any[];
8
+ };
9
+ dirExists(id: any, name: any): boolean;
10
+ }
11
+ import ObjectsInRedisClient_1 = require("@iobroker/db-objects-redis/build/lib/objects/objectsInRedisClient");
12
+ import ObjectsInRedisClient = ObjectsInRedisClient_1.Client;
13
+ import ObjectsInMemServer = require("./objectsInMemServerRedis");
14
+ //# sourceMappingURL=objectsInMemServerClass.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objectsInMemServerClass.d.ts","sourceRoot":"","sources":["../../../src/lib/objects/objectsInMemServerClass.js"],"names":[],"mappings":";AAmBA;IACI,2BAcC;IADG,kCAA2D;IAY/D;;;MAEC;IAED,uCAEC;CACJ;;qDApCkE,MAAM"}
@@ -6,22 +6,17 @@
6
6
  * MIT License
7
7
  *
8
8
  */
9
-
10
9
  /** @module statesInMemory */
11
-
12
10
  /* jshint -W097 */
13
11
  /* jshint strict:false */
14
12
  /* jslint node: true */
15
13
  'use strict';
16
-
17
14
  const ObjectsInRedisClient = require('@iobroker/db-objects-redis').Client;
18
15
  const ObjectsInMemServer = require('./objectsInMemServerRedis');
19
-
20
16
  class ObjectsInMemoryServerClass extends ObjectsInRedisClient {
21
17
  constructor(settings) {
22
18
  settings.autoConnect = false; // delay Client connection to when we need it
23
19
  super(settings);
24
-
25
20
  const serverSettings = {
26
21
  namespace: settings.namespace ? `${settings.namespace}-Server` : 'Server',
27
22
  connection: settings.connection,
@@ -33,22 +28,19 @@ class ObjectsInMemoryServerClass extends ObjectsInRedisClient {
33
28
  };
34
29
  this.objectsServer = new ObjectsInMemServer(serverSettings);
35
30
  }
36
-
37
31
  async destroy() {
38
32
  await super.destroy(); // destroy client first
39
33
  await this.objectsServer.destroy(); // server afterwards too
40
34
  }
41
-
42
35
  getStatus() {
43
36
  return this.objectsServer.getStatus(); // return Status as Server
44
37
  }
45
-
46
38
  syncFileDirectory(limitId) {
47
39
  return this.objectsServer.syncFileDirectory(limitId);
48
40
  }
49
-
50
41
  dirExists(id, name) {
51
42
  return this.objectsServer.dirExists(id, name);
52
43
  }
53
44
  }
54
45
  module.exports = ObjectsInMemoryServerClass;
46
+ //# sourceMappingURL=objectsInMemServerClass.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objectsInMemServerClass.js","sourceRoot":"","sources":["../../../src/lib/objects/objectsInMemServerClass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,OAAO,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;CACJ;AACD,MAAM,CAAC,OAAO,GAAG,0BAA0B,CAAC"}
@@ -0,0 +1,89 @@
1
+ /// <reference types="node" />
2
+ export = ObjectsInMemoryServer;
3
+ /**
4
+ * This class inherits statesInMemoryJsonlDB class and adds redis communication layer
5
+ * to access the methods via redis protocol
6
+ **/
7
+ declare class ObjectsInMemoryServer extends ObjectsInMemoryJsonlDB {
8
+ /**
9
+ * Constructor
10
+ * @param settings State and InMem-DB settings
11
+ */
12
+ constructor(settings: any);
13
+ serverConnections: {};
14
+ namespaceObjects: string;
15
+ namespaceFile: string;
16
+ namespaceObj: string;
17
+ namespaceSet: string;
18
+ namespaceSetLen: number;
19
+ namespaceFileLen: number;
20
+ namespaceObjLen: number;
21
+ namespaceMeta: string;
22
+ namespaceMetaLen: number;
23
+ knownScripts: {};
24
+ normalizeFileRegex1: RegExp;
25
+ normalizeFileRegex2: RegExp;
26
+ /**
27
+ * Separate Namespace from ID and return both
28
+ * @param idWithNamespace ID or Array of IDs containing a redis namespace and the real ID
29
+ * @returns {{namespace: (string); id: string; name?: string; isMeta?: boolean}} Object with namespace and the
30
+ * ID/Array of IDs without the namespace
31
+ * @private
32
+ */
33
+ private _normalizeId;
34
+ /**
35
+ * Publish a subscribed value to one of the redis connections in redis format
36
+ * @param client Instance of RedisHandler
37
+ * @param type Type of subscribed key
38
+ * @param id Subscribed ID
39
+ * @param obj Object to publish
40
+ * @returns {number} Publish counter 0 or 1 depending on if send out or not
41
+ */
42
+ publishToClients(client: any, type: any, id: any, obj: any): number;
43
+ /**
44
+ * Generate ID for a File
45
+ * @param id ID of the File
46
+ * @param name Name of the file
47
+ * @param isMeta generate a META ID or a Data ID?
48
+ * @returns {string} File-ID
49
+ */
50
+ getFileId(id: any, name: any, isMeta: any): string;
51
+ /**
52
+ * Register all event listeners for Handler and implement the relevant logic
53
+ * @param handler RedisHandler instance
54
+ * @private
55
+ */
56
+ private _socketEvents;
57
+ /**
58
+ * Return connected RedisHandlers/Connections
59
+ * @returns {{}|*}
60
+ */
61
+ getClients(): {} | any;
62
+ /**
63
+ * Get keys matching pattern and send it to given responseId, for "SCAN" and "KEYS" - Objects and files supported
64
+ *
65
+ * @param handler RedisHandler instance
66
+ * @param {string} pattern - pattern without namespace prefix
67
+ * @param {number} responseId - Id where response will be sent to
68
+ * @param {boolean} isScan - if used by "SCAN" this flag should be true
69
+ * @private
70
+ */
71
+ private _handleScanOrKeys;
72
+ /**
73
+ * Initialize RedisHandler for a new network connection
74
+ * @param socket Network socket
75
+ * @private
76
+ */
77
+ private _initSocket;
78
+ /**
79
+ * Initialize Redis Server
80
+ * @param settings Settings object
81
+ * @private
82
+ * @return {Promise<void>}
83
+ */
84
+ private _initRedisServer;
85
+ server: net.Server | undefined;
86
+ }
87
+ import ObjectsInMemoryJsonlDB = require("./objectsInMemJsonlDB");
88
+ import net = require("net");
89
+ //# sourceMappingURL=objectsInMemServerRedis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objectsInMemServerRedis.d.ts","sourceRoot":"","sources":["../../../src/lib/objects/objectsInMemServerRedis.js"],"names":[],"mappings":";;AA8CA;;;IAGI;AACJ;IACI;;;OAGG;IACH,2BA8CC;IA3CG,sBAA2B;IAC3B,yBAEO;IACP,sBAAiD;IACjD,qBAAgD;IAChD,qBAAgD;IAChD,wBAA+C;IAG/C,yBAAiD;IACjD,wBAA+C;IAC/C,sBAAgE;IAChE,yBAAiD;IAEjD,iBAAsB;IAEtB,4BAA4E;IAC5E,4BAAiE;IA2BrE;;;;;;OAMG;IACH,qBAwDC;IAED;;;;;;;OAOG;IACH,6DAFa,MAAM,CAgClB;IAED;;;;;;OAMG;IACH,4CAFa,MAAM,CAclB;IAED;;;;OAIG;IACH,sBAsmBC;IAED;;;OAGG;IACH,cAFa,EAAE,MAAE,CAIhB;IA4BD;;;;;;;;OAQG;IACH,0BAkEC;IAED;;;;OAIG;IACH,oBAmBC;IAED;;;;;OAKG;IACH,yBAyBC;IAnBW,+BAAgC;CAoB/C"}