iobroker.javascript 7.2.0 → 7.3.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.
Files changed (36) hide show
  1. package/README.md +7 -3
  2. package/admin/asset-manifest.json +15 -11
  3. package/admin/google-blockly/own/blocks_time.js +6 -5
  4. package/admin/google-blockly/own/blocks_words.js +2 -2
  5. package/admin/index_m.html +6 -4
  6. package/admin/static/css/{487.9934873c.chunk.css → 864.42bfc5f3.chunk.css} +1 -1
  7. package/admin/static/css/{487.9934873c.chunk.css.map → 864.42bfc5f3.chunk.css.map} +1 -1
  8. package/admin/static/js/238.c2010836.chunk.js.map +1 -1
  9. package/admin/static/js/360.01ffa94f.chunk.js +3 -0
  10. package/admin/static/js/360.01ffa94f.chunk.js.map +1 -0
  11. package/admin/static/js/694.9fd55578.chunk.js.map +1 -1
  12. package/admin/static/js/838.0ca9d95b.chunk.js +3 -0
  13. package/admin/static/js/838.0ca9d95b.chunk.js.map +1 -0
  14. package/admin/static/js/864.e099c8b3.chunk.js +2 -0
  15. package/admin/static/js/864.e099c8b3.chunk.js.map +1 -0
  16. package/admin/static/js/main.facd5370.js +2 -0
  17. package/admin/static/js/main.facd5370.js.map +1 -0
  18. package/admin/static/media/tileBlockly.42b0a9f0e66bc4e68f4b.png +0 -0
  19. package/admin/static/media/tileJS.8810e7b4835e61465c3a.png +0 -0
  20. package/admin/static/media/tileRules.7ed5885a66686cc288b1.png +0 -0
  21. package/admin/static/media/tileTS.446265dff5dc550d46a5.png +0 -0
  22. package/admin/tab.html +1 -1
  23. package/io-package.json +202 -39
  24. package/lib/sandbox.js +6 -6
  25. package/main.js +73 -37
  26. package/package.json +1 -1
  27. package/admin/static/js/360.8a86d051.chunk.js +0 -3
  28. package/admin/static/js/360.8a86d051.chunk.js.map +0 -1
  29. package/admin/static/js/487.08b3f5b3.chunk.js +0 -2
  30. package/admin/static/js/487.08b3f5b3.chunk.js.map +0 -1
  31. package/admin/static/js/838.7244f6d0.chunk.js +0 -3
  32. package/admin/static/js/838.7244f6d0.chunk.js.map +0 -1
  33. package/admin/static/js/main.23d47ef3.js +0 -2
  34. package/admin/static/js/main.23d47ef3.js.map +0 -1
  35. /package/admin/static/js/{360.8a86d051.chunk.js.LICENSE.txt → 360.01ffa94f.chunk.js.LICENSE.txt} +0 -0
  36. /package/admin/static/js/{838.7244f6d0.chunk.js.LICENSE.txt → 838.0ca9d95b.chunk.js.LICENSE.txt} +0 -0
package/lib/sandbox.js CHANGED
@@ -53,7 +53,7 @@ function sandBox(script, name, verbose, debug, context) {
53
53
  const debugMode = context.debugMode;
54
54
 
55
55
  function errorInCallback(e) {
56
- adapter.setState(`scriptProblem.${name.substring('script.js.'.length)}`, true, true);
56
+ adapter.setState(`scriptProblem.${name.substring('script.js.'.length)}`, { val: true, ack: true, c: 'errorInCallback' });
57
57
  context.logError('Error in callback', e);
58
58
  context.debugMode && console.log(`error$$${name}$$Exception in callback: ${e}`, Date.now());
59
59
  }
@@ -528,7 +528,7 @@ function sandBox(script, name, verbose, debug, context) {
528
528
  mods[md] = require(md);
529
529
  return mods[md];
530
530
  } catch (e) {
531
- adapter.setState(`scriptProblem.${name.substring('script.js.'.length)}`, true, true);
531
+ adapter.setState(`scriptProblem.${name.substring('script.js.'.length)}`, { val: true, ack: true, c: 'require' });
532
532
  context.logError(name, e, 6);
533
533
  }
534
534
  }
@@ -2031,7 +2031,7 @@ function sandBox(script, name, verbose, debug, context) {
2031
2031
  try {
2032
2032
  result = JSON.parse(JSON.stringify(objects[id]));
2033
2033
  } catch (err) {
2034
- adapter.setState(`scriptProblem.${name.substring('script.js.'.length)}`, true, true);
2034
+ adapter.setState(`scriptProblem.${name.substring('script.js.'.length)}`, { val: true, ack: true, c: 'getObject' });
2035
2035
  sandbox.log(`Object "${id}" can't be copied: ${JSON.stringify(err)}`, 'error');
2036
2036
  return cb();
2037
2037
  }
@@ -2065,7 +2065,7 @@ function sandBox(script, name, verbose, debug, context) {
2065
2065
  try {
2066
2066
  result = JSON.parse(JSON.stringify(objects[id]));
2067
2067
  } catch (err) {
2068
- adapter.setState(`scriptProblem.${name.substring('script.js.'.length)}`, true, true);
2068
+ adapter.setState(`scriptProblem.${name.substring('script.js.'.length)}`, { val: true, ack: true, c: 'getObject' });
2069
2069
  sandbox.log(`Object "${id}" can't be copied: ${JSON.stringify(err)}`, 'error');
2070
2070
  return null;
2071
2071
  }
@@ -3537,7 +3537,7 @@ function sandBox(script, name, verbose, debug, context) {
3537
3537
  try {
3538
3538
  obj = JSON.parse(obj);
3539
3539
  } catch (e) {
3540
- adapter.setState(`scriptProblem.${name.substring('script.js.'.length)}`, true, true);
3540
+ adapter.setState(`scriptProblem.${name.substring('script.js.'.length)}`, { val: true, ack: true, c: 'getAttr' });
3541
3541
  sandbox.log(`Cannot parse "${obj.substring(0, 30)}"${e}`, 'error');
3542
3542
  return null;
3543
3543
  }
@@ -3547,7 +3547,7 @@ function sandBox(script, name, verbose, debug, context) {
3547
3547
  try {
3548
3548
  obj = obj[attr];
3549
3549
  } catch (e) {
3550
- adapter.setState(`scriptProblem.${name.substring('script.js.'.length)}`, true, true);
3550
+ adapter.setState(`scriptProblem.${name.substring('script.js.'.length)}`, { val: true, ack: true, c: 'getAttr' });
3551
3551
  sandbox.log(`Cannot get ${attr} of ${JSON.stringify(obj)}`, 'error');
3552
3552
  return null;
3553
3553
  }
package/main.js CHANGED
@@ -22,7 +22,6 @@ const CoffeeScript = require('coffeescript');
22
22
  const tsc = require('virtual-tsc');
23
23
  const Mirror = require('./lib/mirror');
24
24
  const fork = require('child_process').fork;
25
- const { astroList } = require('./lib/consts');
26
25
 
27
26
  const mods = {
28
27
  fs: {},
@@ -67,6 +66,9 @@ const words = require('./lib/words');
67
66
  const sandBox = require('./lib/sandbox');
68
67
  const eventObj = require('./lib/eventObj');
69
68
  const Scheduler = require('./lib/scheduler');
69
+ const { targetTsLib, tsCompilerOptions, jsDeclarationCompilerOptions } = require('./lib/typescriptSettings');
70
+ const { hashSource, isObject } = require('./lib/tools');
71
+ const { isDeepStrictEqual } = require('node:util');
70
72
  const {
71
73
  resolveTypescriptLibs,
72
74
  resolveTypings,
@@ -74,14 +76,10 @@ const {
74
76
  transformScriptBeforeCompilation,
75
77
  transformGlobalDeclarations
76
78
  } = require('./lib/typescriptTools');
77
- const { targetTsLib, tsCompilerOptions, jsDeclarationCompilerOptions } = require('./lib/typescriptSettings');
78
- const { hashSource, isObject } = require('./lib/tools');
79
79
 
80
80
  const packageJson = require('./package.json');
81
- const { EXIT_CODES } = require('@iobroker/adapter-core');
82
- const { isDeepStrictEqual } = require('util');
83
- const adapterName = packageJson.name.split('.').pop();
84
- const scriptCodeMarker = 'script.js.';
81
+ const SCRIPT_CODE_MARKER = 'script.js.';
82
+
85
83
  const stopCounters = {};
86
84
  let setStateCountCheckInterval = null;
87
85
 
@@ -407,9 +405,7 @@ let adapter;
407
405
  function startAdapter(options) {
408
406
  options = options || {};
409
407
  Object.assign(options, {
410
-
411
- name: adapterName,
412
-
408
+ name: 'javascript',
413
409
  useFormatDate: true, // load float formatting
414
410
 
415
411
  /**
@@ -515,12 +511,12 @@ function startAdapter(options) {
515
511
  stop(id);
516
512
 
517
513
  // delete scriptEnabled.blabla variable
518
- const idActive = 'scriptEnabled.' + id.substring('script.js.'.length);
514
+ const idActive = 'scriptEnabled.' + id.substring(SCRIPT_CODE_MARKER.length);
519
515
  adapter.delObject(idActive);
520
516
  adapter.delState(idActive);
521
517
 
522
518
  // delete scriptProblem.blabla variable
523
- const idProblem = 'scriptProblem.' + id.substring('script.js.'.length);
519
+ const idProblem = 'scriptProblem.' + id.substring(SCRIPT_CODE_MARKER.length);
524
520
  adapter.delObject(idProblem);
525
521
  adapter.delState(idProblem);
526
522
  }
@@ -688,7 +684,7 @@ function startAdapter(options) {
688
684
  const eventData = event.exception.values[0];
689
685
  if (eventData.stacktrace && eventData.stacktrace.frames && Array.isArray(eventData.stacktrace.frames) && eventData.stacktrace.frames.length) {
690
686
  // Exclude event if script Marker is included
691
- if (eventData.stacktrace.frames.find(frame => frame.filename && frame.filename.includes(scriptCodeMarker))) {
687
+ if (eventData.stacktrace.frames.find(frame => frame.filename && frame.filename.includes(SCRIPT_CODE_MARKER))) {
692
688
  return null;
693
689
  }
694
690
  //Exclude event if own directory is included but not inside own node_modules
@@ -741,7 +737,7 @@ function startAdapter(options) {
741
737
  handler.cb.call(handler.sandbox, obj.message.data, result => {/* nop */ });
742
738
  }
743
739
  } catch (e) {
744
- adapter.setState('scriptProblem.' + name.substring('script.js.'.length), true, true);
740
+ adapter.setState('scriptProblem.' + name.substring(SCRIPT_CODE_MARKER.length), true, true);
745
741
  context.logError('Error in callback', e);
746
742
  }
747
743
  });
@@ -907,7 +903,7 @@ function startAdapter(options) {
907
903
  // Identify unhandled errors originating from callbacks in scripts
908
904
  // These are not caught by wrapping the execution code in try-catch
909
905
  if (err && typeof err.stack === 'string') {
910
- const scriptCodeMarkerIndex = err.stack.indexOf(scriptCodeMarker);
906
+ const scriptCodeMarkerIndex = err.stack.indexOf(SCRIPT_CODE_MARKER);
911
907
  if (scriptCodeMarkerIndex > -1) {
912
908
  // This is a script error
913
909
  let scriptName = err.stack.substr(scriptCodeMarkerIndex);
@@ -1091,6 +1087,7 @@ function main() {
1091
1087
  getData(() => {
1092
1088
  context.scheduler = new Scheduler(adapter.log, Date, mods.suncalc, adapter.config.latitude, adapter.config.longitude);
1093
1089
  dayTimeSchedules(adapter, context);
1090
+ sunTimeSchedules(adapter, context);
1094
1091
  timeSchedule(adapter, context);
1095
1092
 
1096
1093
  // Warning. It could have a side-effect in compact mode, so all adapters will accept self signed certificates
@@ -1319,7 +1316,8 @@ let knownGlobalDeclarationsByScript = {};
1319
1316
  let globalScriptLines = 0;
1320
1317
  // let activeRegEx = null;
1321
1318
  let activeStr = ''; // enabled state prefix
1322
- let daySchedule = null; // schedule for astrological day
1319
+ let dayScheduleTimer = null; // schedule for astrological day
1320
+ let sunScheduleTimer = null; // schedule for sun moment times
1323
1321
  let timeScheduleTimer = null; // schedule for astrological day
1324
1322
 
1325
1323
  function getNextTimeEvent(time, useNextDay) {
@@ -1379,9 +1377,11 @@ function timeSchedule(adapter, context) {
1379
1377
  }
1380
1378
  }
1381
1379
  if (context.timeSettings.leadingZeros) {
1382
- hours = hours.toString().padStart(2, '0');
1380
+ hours = parseInt(hours.toString().padStart(2, '0'));
1383
1381
  }
1384
- adapter.setState('variables.dayTime', `${hours}:${minutes.toString().padStart(2, '0')}`, true);
1382
+
1383
+ adapter.setState('variables.dayTime', {val: `${hours}:${minutes.toString().padStart(2, '0')}`, ack: true});
1384
+
1385
1385
  now.setMinutes(now.getMinutes() + 1);
1386
1386
  now.setSeconds(0);
1387
1387
  now.setMilliseconds(0);
@@ -1433,17 +1433,17 @@ function dayTimeSchedules(adapter, context) {
1433
1433
  }
1434
1434
 
1435
1435
  const val = state ? !!state.val : false;
1436
- if (val !== isDay) {
1437
- adapter.setState('variables.isDayTime', isDay, true);
1436
+ if (val !== isDay || state === null) {
1437
+ adapter.setState('variables.isDayTime', {val: isDay, ack: true});
1438
1438
  }
1439
1439
  });
1440
1440
 
1441
1441
  adapter.getState('variables.isDaylightSaving', (err, state) => {
1442
1442
  const isDayLightSaving = dstOffsetAtDate(nowDate) !== 0;
1443
-
1444
1443
  const val = state ? !!state.val : false;
1445
- if (val !== isDayLightSaving) {
1446
- adapter.setState('variables.isDaylightSaving', isDayLightSaving, true);
1444
+
1445
+ if (val !== isDayLightSaving || state === null) {
1446
+ adapter.setState('variables.isDaylightSaving', {val: isDayLightSaving, ack: true});
1447
1447
  }
1448
1448
  });
1449
1449
 
@@ -1456,11 +1456,46 @@ function dayTimeSchedules(adapter, context) {
1456
1456
  nextTimeout = 3000;
1457
1457
  }
1458
1458
 
1459
- daySchedule = setTimeout(dayTimeSchedules, nextTimeout, adapter, context);
1459
+ dayScheduleTimer = setTimeout(dayTimeSchedules, nextTimeout, adapter, context);
1460
+ }
1461
+
1462
+ async function sunTimeSchedules(adapter, context) {
1463
+ const todayDate = new Date();
1464
+ todayDate.setHours(0);
1465
+ todayDate.setMinutes(0);
1466
+ todayDate.setSeconds(1);
1467
+ todayDate.setDate(todayDate.getDate() + 1);
1468
+
1469
+ const times = mods.suncalc.getTimes(new Date(), adapter.config.latitude, adapter.config.longitude);
1470
+
1471
+ for (const t in times) {
1472
+ const h = times[t].getHours();
1473
+ const m = times[t].getMinutes();
1474
+
1475
+ const timeFormatted = `${h < 10 ? '0' + h : h}:${m < 10 ? '0' + m : m}`;
1476
+ const objId = `variables.astro.${t}`;
1477
+
1478
+ await adapter.setObjectNotExistsAsync(objId, {
1479
+ type: 'state',
1480
+ common: {
1481
+ name: `Astro ${t}`,
1482
+ type: 'string',
1483
+ role: 'value',
1484
+ read: true,
1485
+ write: false,
1486
+ },
1487
+ native: {},
1488
+ });
1489
+ await adapter.setStateAsync(objId, { val: timeFormatted, ack: true });
1490
+ }
1491
+
1492
+ adapter.log.debug(`[sunTimeSchedules] Next: ${todayDate.toISOString()}`);
1493
+ sunScheduleTimer = setTimeout(sunTimeSchedules, todayDate.getTime() - Date.now(), adapter, context);
1460
1494
  }
1461
1495
 
1462
1496
  function stopTimeSchedules() {
1463
- daySchedule && clearTimeout(daySchedule);
1497
+ dayScheduleTimer && clearTimeout(dayScheduleTimer);
1498
+ sunScheduleTimer && clearTimeout(sunScheduleTimer);
1464
1499
  timeScheduleTimer && clearTimeout(timeScheduleTimer);
1465
1500
  }
1466
1501
 
@@ -1553,13 +1588,13 @@ context.logError = function (msg, e, offs) {
1553
1588
  };
1554
1589
 
1555
1590
  function createActiveObject(id, enabled, cb) {
1556
- const idActive = `${adapter.namespace}.scriptEnabled.${id.substring('script.js.'.length)}`;
1591
+ const idActive = `${adapter.namespace}.scriptEnabled.${id.substring(SCRIPT_CODE_MARKER.length)}`;
1557
1592
 
1558
1593
  if (!context.objects[idActive]) {
1559
1594
  context.objects[idActive] = {
1560
1595
  _id: idActive,
1561
1596
  common: {
1562
- name: `scriptEnabled.${id.substring('script.js.'.length)}`,
1597
+ name: `scriptEnabled.${id.substring(SCRIPT_CODE_MARKER.length)}`,
1563
1598
  desc: 'controls script activity',
1564
1599
  type: 'boolean',
1565
1600
  write: true,
@@ -1602,13 +1637,13 @@ function createActiveObject(id, enabled, cb) {
1602
1637
  }
1603
1638
 
1604
1639
  function createProblemObject(id, cb) {
1605
- const idProblem = adapter.namespace + '.scriptProblem.' + id.substring('script.js.'.length);
1640
+ const idProblem = adapter.namespace + '.scriptProblem.' + id.substring(SCRIPT_CODE_MARKER.length);
1606
1641
 
1607
1642
  if (!context.objects[idProblem]) {
1608
1643
  context.objects[idProblem] = {
1609
1644
  _id: idProblem,
1610
1645
  common: {
1611
- name: 'scriptProblem.' + id.substring('script.js.'.length),
1646
+ name: 'scriptProblem.' + id.substring(SCRIPT_CODE_MARKER.length),
1612
1647
  desc: 'is the script has a problem',
1613
1648
  type: 'boolean',
1614
1649
  expert: true,
@@ -1754,7 +1789,8 @@ function installLibraries(callback) {
1754
1789
  if (libraries[lib] && libraries[lib].trim()) {
1755
1790
  libraries[lib] = libraries[lib].trim();
1756
1791
  let libName = libraries[lib];
1757
- let versionChunkPos = libName.indexOf('@', 1);
1792
+
1793
+ const versionChunkPos = libName.indexOf('@', 1);
1758
1794
  if (versionChunkPos > -1) {
1759
1795
  libName = libName.slice(0, versionChunkPos);
1760
1796
  }
@@ -1826,7 +1862,7 @@ function execute(script, name, verbose, debug) {
1826
1862
  script.subscribesFile = {};
1827
1863
  script.setStatePerMinuteCounter = 0;
1828
1864
  script.setStatePerMinuteProblemCounter = 0;
1829
- adapter.setState(`scriptProblem.${name.substring('script.js.'.length)}`, { val: false, ack: true, expire: 1000 });
1865
+ adapter.setState(`scriptProblem.${name.substring(SCRIPT_CODE_MARKER.length)}`, { val: false, ack: true, expire: 1000 });
1830
1866
 
1831
1867
  const sandbox = sandBox(script, name, verbose, debug, context);
1832
1868
 
@@ -1837,7 +1873,7 @@ function execute(script, name, verbose, debug) {
1837
1873
  // lineOffset: globalScriptLines
1838
1874
  });
1839
1875
  } catch (e) {
1840
- adapter.setState(`scriptProblem.${name.substring('script.js.'.length)}`, true, true);
1876
+ adapter.setState(`scriptProblem.${name.substring(SCRIPT_CODE_MARKER.length)}`, { val: true, ack: true, c: 'execute' });
1841
1877
  context.logError(name, e);
1842
1878
  }
1843
1879
  }
@@ -1897,7 +1933,7 @@ function updateLogSubscriptions() {
1897
1933
  function stop(name, callback) {
1898
1934
  adapter.log.info('Stop script ' + name);
1899
1935
 
1900
- adapter.setState('scriptEnabled.' + name.substring('script.js.'.length), false, true);
1936
+ adapter.setState('scriptEnabled.' + name.substring(SCRIPT_CODE_MARKER.length), false, true);
1901
1937
 
1902
1938
  if (context.messageBusHandlers[name]) {
1903
1939
  delete context.messageBusHandlers[name];
@@ -2038,7 +2074,7 @@ function prepareScript(obj, callback) {
2038
2074
  ) {
2039
2075
  const name = obj._id;
2040
2076
 
2041
- const nameId = name.substring('script.js.'.length);
2077
+ const nameId = name.substring(SCRIPT_CODE_MARKER.length);
2042
2078
  if (!nameId.length || nameId.endsWith('.')) {
2043
2079
  adapter.log.error(`Script name ${name} is invalid!`);
2044
2080
  typeof callback === 'function' && callback(false, name);
@@ -2139,7 +2175,7 @@ function prepareScript(obj, callback) {
2139
2175
  let _name;
2140
2176
  if (obj && obj._id) {
2141
2177
  _name = obj._id;
2142
- const scriptIdName = _name.substring('script.js.'.length);
2178
+ const scriptIdName = _name.substring(SCRIPT_CODE_MARKER.length);
2143
2179
 
2144
2180
  if (!scriptIdName.length || scriptIdName.endsWith('.')) {
2145
2181
  adapter.log.error(`Script name ${_name} is invalid!`);
@@ -2202,7 +2238,7 @@ async function getData(callback) {
2202
2238
  if (!adapter.config.subscribe) {
2203
2239
  if (err || !res) {
2204
2240
  adapter.log.error(`Could not initialize states: ${err ? err.message : 'no result'}`);
2205
- adapter.terminate(EXIT_CODES.START_IMMEDIATELY_AFTER_STOP);
2241
+ adapter.terminate(utils.EXIT_CODES.START_IMMEDIATELY_AFTER_STOP);
2206
2242
  return;
2207
2243
  }
2208
2244
  context.states = Object.assign(res, context.states);
@@ -2226,7 +2262,7 @@ async function getData(callback) {
2226
2262
  adapter.getObjectList({ include_docs: true }, (err, res) => {
2227
2263
  if (err || !res || !res.rows) {
2228
2264
  adapter.log.error(`Could not initialize objects: ${err ? err.message : 'no result'}`);
2229
- adapter.terminate(EXIT_CODES.START_IMMEDIATELY_AFTER_STOP);
2265
+ adapter.terminate(utils.EXIT_CODES.START_IMMEDIATELY_AFTER_STOP);
2230
2266
  return;
2231
2267
  }
2232
2268
  context.objects = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.javascript",
3
- "version": "7.2.0",
3
+ "version": "7.3.0",
4
4
  "description": "Rules Engine for ioBroker",
5
5
  "author": "bluefox <dogafox@gmail.com>",
6
6
  "contributors": [