iotagent-node-lib 3.0.0 → 3.2.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 (122) hide show
  1. package/.github/workflows/ci.yml +1 -0
  2. package/config.js +5 -5
  3. package/doc/api.md +1540 -298
  4. package/doc/deprecated.md +3 -1
  5. package/doc/development.md +120 -0
  6. package/doc/installationguide.md +3 -6
  7. package/docker-compose-dev.yml +1 -1
  8. package/lib/commonConfig.js +7 -10
  9. package/lib/fiware-iotagent-lib.js +0 -10
  10. package/lib/jexlTranformsMap.js +2 -1
  11. package/lib/plugins/bidirectionalData.js +8 -26
  12. package/lib/plugins/expressionPlugin.js +8 -40
  13. package/lib/plugins/jexlParser.js +28 -0
  14. package/lib/services/commands/commandService.js +1 -1
  15. package/lib/services/devices/deviceService.js +2 -1
  16. package/lib/services/ngsi/entities-NGSI-LD.js +15 -73
  17. package/lib/services/ngsi/entities-NGSI-v2.js +149 -124
  18. package/lib/services/northBound/deviceProvisioningServer.js +17 -14
  19. package/lib/templates/createDevice.json +5 -2
  20. package/lib/templates/createDeviceLax.json +7 -5
  21. package/lib/templates/updateDevice.json +5 -2
  22. package/lib/templates/updateDeviceLax.json +3 -5
  23. package/package.json +2 -2
  24. package/test/unit/examples/deviceProvisioningRequests/provisionBidirectionalDevice.json +5 -5
  25. package/test/unit/examples/deviceProvisioningRequests/provisionMinimumDevice4.json +1 -0
  26. package/test/unit/examples/groupProvisioningRequests/bidirectionalGroup.json +4 -4
  27. package/test/unit/general/config-multi-core-test.js +2 -1
  28. package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +2 -1
  29. package/test/unit/general/deviceService-test.js +2 -1
  30. package/test/unit/general/loglevel-api_test.js +2 -1
  31. package/test/unit/general/startup-test.js +2 -1
  32. package/test/unit/general/statistics-persistence_test.js +1 -0
  33. package/test/unit/general/statistics-service_test.js +1 -0
  34. package/test/unit/lazyAndCommands/commandRegistry_test.js +1 -0
  35. package/test/unit/memoryRegistry/deviceRegistryMemory_test.js +1 -0
  36. package/test/unit/mongodb/mongodb-connectionoptions-test.js +1 -0
  37. package/test/unit/mongodb/mongodb-group-registry-test.js +1 -0
  38. package/test/unit/mongodb/mongodb-registry-test.js +2 -1
  39. package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +0 -2
  40. package/test/unit/ngsi-ld/general/config-jsonld-contexts-test.js +2 -1
  41. package/test/unit/ngsi-ld/general/contextBrokerOAuthSecurityAccess-test.js +2 -1
  42. package/test/unit/ngsi-ld/general/deviceService-test.js +2 -1
  43. package/test/unit/ngsi-ld/general/https-support-test.js +2 -1
  44. package/test/unit/ngsi-ld/general/iotam-autoregistration-test.js +2 -1
  45. package/test/unit/ngsi-ld/general/startup-test.js +3 -2
  46. package/test/unit/ngsi-ld/lazyAndCommands/active-devices-attribute-update-test.js +2 -1
  47. package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +5 -7
  48. package/test/unit/ngsi-ld/lazyAndCommands/lazy-devices-test.js +8 -6
  49. package/test/unit/ngsi-ld/lazyAndCommands/merge-patch-test.js +18 -22
  50. package/test/unit/ngsi-ld/lazyAndCommands/polling-commands-test.js +2 -1
  51. package/test/unit/ngsi-ld/ngsiService/active-devices-test.js +2 -1
  52. package/test/unit/ngsi-ld/ngsiService/autocast-test.js +2 -1
  53. package/test/unit/ngsi-ld/ngsiService/geoproperties-test.js +2 -1
  54. package/test/unit/ngsi-ld/ngsiService/languageProperties-test.js +32 -34
  55. package/test/unit/ngsi-ld/ngsiService/staticAttributes-test.js +2 -1
  56. package/test/unit/ngsi-ld/ngsiService/subscriptions-test.js +2 -1
  57. package/test/unit/ngsi-ld/ngsiService/unsupported-endpoints-test.js +11 -15
  58. package/test/unit/ngsi-ld/plugins/alias-plugin_test.js +2 -1
  59. package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +10 -9
  60. package/test/unit/ngsi-ld/plugins/compress-timestamp-plugin_test.js +2 -1
  61. package/test/unit/ngsi-ld/plugins/custom-plugin_test.js +152 -0
  62. package/test/unit/ngsi-ld/plugins/multientity-plugin_test.js +3 -2
  63. package/test/unit/ngsi-ld/plugins/timestamp-processing-plugin_test.js +2 -1
  64. package/test/unit/ngsi-ld/provisioning/device-provisioning-api_test.js +1 -0
  65. package/test/unit/ngsi-ld/provisioning/device-registration_test.js +2 -1
  66. package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +15 -12
  67. package/test/unit/ngsi-ld/provisioning/listProvisionedDevices-test.js +1 -0
  68. package/test/unit/ngsi-ld/provisioning/provisionDeviceMultientity-test.js +1 -0
  69. package/test/unit/ngsi-ld/provisioning/removeProvisionedDevice-test.js +1 -0
  70. package/test/unit/ngsi-ld/provisioning/singleConfigurationMode-test.js +1 -0
  71. package/test/unit/ngsi-ld/provisioning/updateProvisionedDevices-test.js +1 -0
  72. package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +13 -7
  73. package/test/unit/ngsiv2/examples/contextRequests/createMinimumProvisionedDevice4.json +5 -1
  74. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin31.json +0 -8
  75. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin32.json +6 -0
  76. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin35.json +20 -0
  77. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin40.json +42 -0
  78. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin41.json +32 -0
  79. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin25.json +37 -0
  80. package/test/unit/ngsiv2/examples/contextRequests/updateContextProcessTimestamp.json +7 -1
  81. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampOverride.json +7 -1
  82. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampOverrideWithoutMilis.json +7 -1
  83. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +232 -8
  84. package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +2 -1
  85. package/test/unit/ngsiv2/general/deviceService-test.js +2 -1
  86. package/test/unit/ngsiv2/general/https-support-test.js +2 -1
  87. package/test/unit/ngsiv2/general/iotam-autoregistration-test.js +2 -1
  88. package/test/unit/ngsiv2/general/startup-test.js +2 -1
  89. package/test/unit/ngsiv2/lazyAndCommands/active-devices-attribute-update-test.js +2 -1
  90. package/test/unit/ngsiv2/lazyAndCommands/command-test.js +2 -1
  91. package/test/unit/ngsiv2/lazyAndCommands/lazy-devices-test.js +8 -6
  92. package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +3 -3
  93. package/test/unit/ngsiv2/ngsiService/active-devices-test.js +3 -2
  94. package/test/unit/ngsiv2/ngsiService/autocast-test.js +2 -1
  95. package/test/unit/ngsiv2/ngsiService/queryDeviceInformationInCb-test.js +2 -1
  96. package/test/unit/ngsiv2/ngsiService/staticAttributes-test.js +2 -1
  97. package/test/unit/ngsiv2/ngsiService/subscriptions-test.js +2 -1
  98. package/test/unit/ngsiv2/plugins/alias-plugin_test.js +2 -1
  99. package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +8 -7
  100. package/test/unit/ngsiv2/plugins/compress-timestamp-plugin_test.js +2 -1
  101. package/test/unit/ngsiv2/plugins/custom-plugin_test.js +151 -0
  102. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +87 -13
  103. package/test/unit/ngsiv2/plugins/timestamp-processing-plugin_test.js +2 -1
  104. package/test/unit/ngsiv2/provisioning/device-group-api-test.js +1 -0
  105. package/test/unit/ngsiv2/provisioning/device-group-utils-test.js +1 -0
  106. package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +12 -3
  107. package/test/unit/ngsiv2/provisioning/device-registration_test.js +2 -1
  108. package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +15 -12
  109. package/test/unit/ngsiv2/provisioning/listProvisionedDevices-test.js +1 -0
  110. package/test/unit/ngsiv2/provisioning/provisionDeviceMultientity-test.js +1 -0
  111. package/test/unit/ngsiv2/provisioning/removeProvisionedDevice-test.js +1 -0
  112. package/test/unit/ngsiv2/provisioning/singleConfigurationMode-test.js +1 -0
  113. package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +1 -0
  114. package/test/unit/plugins/capture-configuration-inPlugins_test.js +2 -1
  115. package/test/unit/plugins/capture-provision-inPlugins_test.js +2 -1
  116. package/doc/advanced-topics.md +0 -626
  117. package/doc/expressionLanguage.md +0 -762
  118. package/lib/plugins/expressionParser.js +0 -205
  119. package/test/unit/expressions/expression-test.js +0 -197
  120. package/test/unit/ngsi-ld/expressions/expressionBasedTransformations-test.js +0 -881
  121. package/test/unit/ngsiv2/expressions/expressionBasedTransformations-test.js +0 -950
  122. package/test/unit/ngsiv2/expressions/expressionCombinedTransformations-test.js +0 -294
@@ -410,16 +410,6 @@ function addLinkedEntities(typeInformation, json) {
410
410
  });
411
411
  }
412
412
 
413
- /**
414
- * Determines if a value is of type float
415
- *
416
- * @param {String} value Value to be analyzed
417
- * @return {boolean} True if float, False otherwise.
418
- */
419
- function isFloat(value) {
420
- return !isNaN(value) && value.toString().indexOf('.') !== -1;
421
- }
422
-
423
413
  /**
424
414
  * Makes an update in the Device's entity in the context broker, with the values given in the 'attributes' array.
425
415
  * This array should comply to the NGSI-LD's attribute format.
@@ -535,7 +525,7 @@ function sendUpdateValueNgsiLD(entityName, attributes, typeInformation, token, c
535
525
  }
536
526
  }
537
527
  // This context is just to calculate explicitAttrs when is an expression
538
- let ctxt = expressionPlugin.extractContext(attributesCtxt.concat(idTypeSSSList), typeInformation);
528
+ let ctxt = expressionPlugin.extractContext(attributesCtxt.concat(idTypeSSSList));
539
529
  // typeInformation.active attrs with expressions expanded by current ctxt
540
530
  if (typeInformation.active) {
541
531
  typeInformation.active.forEach(function (att) {
@@ -547,10 +537,7 @@ function sendUpdateValueNgsiLD(entityName, attributes, typeInformation, token, c
547
537
  type: att.type
548
538
  };
549
539
  attributesCtxt.push(expandedAttr);
550
- ctxt = expressionPlugin.extractContext(
551
- attributesCtxt.concat(idTypeSSSList),
552
- typeInformation
553
- );
540
+ ctxt = expressionPlugin.extractContext(attributesCtxt.concat(idTypeSSSList));
554
541
  }
555
542
  }
556
543
  });
@@ -689,7 +676,7 @@ function sendUpdateValueNgsiLD(entityName, attributes, typeInformation, token, c
689
676
  });
690
677
  }
691
678
  attributesCtxt = attributesCtxt.concat(idTypeSSSList);
692
- const ctxt = expressionPlugin.extractContext(attributesCtxt, typeInformation);
679
+ const ctxt = expressionPlugin.extractContext(attributesCtxt);
693
680
  logger.debug(context, 'sendUpdateValueNgsiLD \n initial ctxt %j ', ctxt);
694
681
 
695
682
  // Sort currentEntity to get first attrs without expressions (checking attrs in typeInformation.active)
@@ -791,47 +778,12 @@ function sendUpdateValueNgsiLD(entityName, attributes, typeInformation, token, c
791
778
  }
792
779
  } catch (e) {
793
780
  logger.error(context, 'sendUpdateValueNgsiLD \n apply expression exception %j \n', e);
794
- if (!expressionPlugin.checkJexl(typeInformation)) {
795
- return callback(e); // just throw error with legacy parser for backward compatiblity
796
- } else {
797
- res = ctxt[attr.name]; // TBD: add reference to test
798
- }
799
- }
800
- if (!expressionPlugin.checkJexl(typeInformation)) {
801
- // legacy expression plugin: Involves some legacy checks performed by applierExpression
802
- if (
803
- res &&
804
- res !== 'undefined' &&
805
- res !== 'null' &&
806
- (typeof res === 'string' || res instanceof String) &&
807
- !res.includes('NaN')
808
- ) {
809
- newAttr.value = res;
810
- if (newAttr.type === 'Number' && isFloat(newAttr.value)) {
811
- newAttr.value = Number.parseFloat(newAttr.value);
812
- } else if (newAttr.type === 'Number' && !Number.isNaN(Number.parseInt(newAttr.value))) {
813
- newAttr.value = Number.parseInt(newAttr.value);
814
- } else if (newAttr.type === 'Boolean') {
815
- newAttr.value = newAttr.value === 'true' || newAttr.value === '1';
816
- } else if (newAttr.type === 'None') {
817
- newAttr.value = null;
818
- }
819
- } else if (isNaN(res) || res === 'undefined' || res === 'null') {
820
- logger.debug(
821
- context,
822
- 'sendUpdateValueNgsiLD \n apply expression result: isNaN || undefined || null'
823
- );
824
- if (res === 'null' && newAttr.type === 'None') {
825
- newAttr.value = null;
826
- } else {
827
- delete payload[0][j]; // remove measure attr
828
- attr = undefined; // stop process attr
829
- }
830
- }
831
- } else {
832
- // jexl expression plugin
833
- newAttr.value = res;
781
+ res = ctxt[attr.name]; // TBD: add reference to test
834
782
  }
783
+
784
+ // jexl expression plugin
785
+ newAttr.value = res;
786
+
835
787
  logger.debug(
836
788
  context,
837
789
  'sendUpdateValueNgsiLD \n apply expression result %j \n newAttr %j',
@@ -973,23 +925,9 @@ function sendUpdateValueNgsiLD(entityName, attributes, typeInformation, token, c
973
925
  ) {
974
926
  if (timestampValue) {
975
927
  // timeInstant is provided as measure
976
- if (Object.keys(payload[0]).length > 3) {
928
+ if (Object.keys(payload[0]).length > 1) {
977
929
  // include metadata with TimeInstant in attrs when TimeInstant is provided as measure in all entities
978
- payload[0] = NGSIv2.addTimestamp(
979
- payload[0],
980
- typeInformation.timezone,
981
- timestampValue,
982
- false // skipMetadataAtt
983
- );
984
- } else {
985
- // Do not include metadata with TimeInstant in attrs when TimeInstant is provided as measure
986
- // and no more entities
987
- payload[0] = NGSIv2.addTimestamp(
988
- payload[0],
989
- typeInformation.timezone,
990
- timestampValue,
991
- true // skipMetadataAtt
992
- );
930
+ payload[0] = NGSIv2.addTimestamp(payload[0], typeInformation.timezone, timestampValue);
993
931
  }
994
932
  } else {
995
933
  // jshint maxdepth:5
@@ -1062,5 +1000,9 @@ function sendUpdateValueNgsiLD(entityName, attributes, typeInformation, token, c
1062
1000
 
1063
1001
  exports.convertAttrNGSILD = convertAttrNGSILD;
1064
1002
  exports.formatAsNGSILD = formatAsNGSILD;
1065
- exports.sendUpdateValue = sendUpdateValueNgsiLD;
1003
+ exports.sendUpdateValue = function (entityName, attributes, typeInformation, token, callback) {
1004
+ NGSIUtils.applyMiddlewares(NGSIUtils.updateMiddleware, attributes, typeInformation, () => {
1005
+ return sendUpdateValueNgsiLD(entityName, attributes, typeInformation, token, callback);
1006
+ });
1007
+ };
1066
1008
  exports.sendQueryValue = sendQueryValueNgsiLD;