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.
- package/.github/workflows/ci.yml +1 -0
- package/config.js +5 -5
- package/doc/api.md +1540 -298
- package/doc/deprecated.md +3 -1
- package/doc/development.md +120 -0
- package/doc/installationguide.md +3 -6
- package/docker-compose-dev.yml +1 -1
- package/lib/commonConfig.js +7 -10
- package/lib/fiware-iotagent-lib.js +0 -10
- package/lib/jexlTranformsMap.js +2 -1
- package/lib/plugins/bidirectionalData.js +8 -26
- package/lib/plugins/expressionPlugin.js +8 -40
- package/lib/plugins/jexlParser.js +28 -0
- package/lib/services/commands/commandService.js +1 -1
- package/lib/services/devices/deviceService.js +2 -1
- package/lib/services/ngsi/entities-NGSI-LD.js +15 -73
- package/lib/services/ngsi/entities-NGSI-v2.js +149 -124
- package/lib/services/northBound/deviceProvisioningServer.js +17 -14
- package/lib/templates/createDevice.json +5 -2
- package/lib/templates/createDeviceLax.json +7 -5
- package/lib/templates/updateDevice.json +5 -2
- package/lib/templates/updateDeviceLax.json +3 -5
- package/package.json +2 -2
- package/test/unit/examples/deviceProvisioningRequests/provisionBidirectionalDevice.json +5 -5
- package/test/unit/examples/deviceProvisioningRequests/provisionMinimumDevice4.json +1 -0
- package/test/unit/examples/groupProvisioningRequests/bidirectionalGroup.json +4 -4
- package/test/unit/general/config-multi-core-test.js +2 -1
- package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +2 -1
- package/test/unit/general/deviceService-test.js +2 -1
- package/test/unit/general/loglevel-api_test.js +2 -1
- package/test/unit/general/startup-test.js +2 -1
- package/test/unit/general/statistics-persistence_test.js +1 -0
- package/test/unit/general/statistics-service_test.js +1 -0
- package/test/unit/lazyAndCommands/commandRegistry_test.js +1 -0
- package/test/unit/memoryRegistry/deviceRegistryMemory_test.js +1 -0
- package/test/unit/mongodb/mongodb-connectionoptions-test.js +1 -0
- package/test/unit/mongodb/mongodb-group-registry-test.js +1 -0
- package/test/unit/mongodb/mongodb-registry-test.js +2 -1
- package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +0 -2
- package/test/unit/ngsi-ld/general/config-jsonld-contexts-test.js +2 -1
- package/test/unit/ngsi-ld/general/contextBrokerOAuthSecurityAccess-test.js +2 -1
- package/test/unit/ngsi-ld/general/deviceService-test.js +2 -1
- package/test/unit/ngsi-ld/general/https-support-test.js +2 -1
- package/test/unit/ngsi-ld/general/iotam-autoregistration-test.js +2 -1
- package/test/unit/ngsi-ld/general/startup-test.js +3 -2
- package/test/unit/ngsi-ld/lazyAndCommands/active-devices-attribute-update-test.js +2 -1
- package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +5 -7
- package/test/unit/ngsi-ld/lazyAndCommands/lazy-devices-test.js +8 -6
- package/test/unit/ngsi-ld/lazyAndCommands/merge-patch-test.js +18 -22
- package/test/unit/ngsi-ld/lazyAndCommands/polling-commands-test.js +2 -1
- package/test/unit/ngsi-ld/ngsiService/active-devices-test.js +2 -1
- package/test/unit/ngsi-ld/ngsiService/autocast-test.js +2 -1
- package/test/unit/ngsi-ld/ngsiService/geoproperties-test.js +2 -1
- package/test/unit/ngsi-ld/ngsiService/languageProperties-test.js +32 -34
- package/test/unit/ngsi-ld/ngsiService/staticAttributes-test.js +2 -1
- package/test/unit/ngsi-ld/ngsiService/subscriptions-test.js +2 -1
- package/test/unit/ngsi-ld/ngsiService/unsupported-endpoints-test.js +11 -15
- package/test/unit/ngsi-ld/plugins/alias-plugin_test.js +2 -1
- package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +10 -9
- package/test/unit/ngsi-ld/plugins/compress-timestamp-plugin_test.js +2 -1
- package/test/unit/ngsi-ld/plugins/custom-plugin_test.js +152 -0
- package/test/unit/ngsi-ld/plugins/multientity-plugin_test.js +3 -2
- package/test/unit/ngsi-ld/plugins/timestamp-processing-plugin_test.js +2 -1
- package/test/unit/ngsi-ld/provisioning/device-provisioning-api_test.js +1 -0
- package/test/unit/ngsi-ld/provisioning/device-registration_test.js +2 -1
- package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +15 -12
- package/test/unit/ngsi-ld/provisioning/listProvisionedDevices-test.js +1 -0
- package/test/unit/ngsi-ld/provisioning/provisionDeviceMultientity-test.js +1 -0
- package/test/unit/ngsi-ld/provisioning/removeProvisionedDevice-test.js +1 -0
- package/test/unit/ngsi-ld/provisioning/singleConfigurationMode-test.js +1 -0
- package/test/unit/ngsi-ld/provisioning/updateProvisionedDevices-test.js +1 -0
- package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +13 -7
- package/test/unit/ngsiv2/examples/contextRequests/createMinimumProvisionedDevice4.json +5 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin31.json +0 -8
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin32.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin35.json +20 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin40.json +42 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin41.json +32 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin25.json +37 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextProcessTimestamp.json +7 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampOverride.json +7 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampOverrideWithoutMilis.json +7 -1
- package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +232 -8
- package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +2 -1
- package/test/unit/ngsiv2/general/deviceService-test.js +2 -1
- package/test/unit/ngsiv2/general/https-support-test.js +2 -1
- package/test/unit/ngsiv2/general/iotam-autoregistration-test.js +2 -1
- package/test/unit/ngsiv2/general/startup-test.js +2 -1
- package/test/unit/ngsiv2/lazyAndCommands/active-devices-attribute-update-test.js +2 -1
- package/test/unit/ngsiv2/lazyAndCommands/command-test.js +2 -1
- package/test/unit/ngsiv2/lazyAndCommands/lazy-devices-test.js +8 -6
- package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +3 -3
- package/test/unit/ngsiv2/ngsiService/active-devices-test.js +3 -2
- package/test/unit/ngsiv2/ngsiService/autocast-test.js +2 -1
- package/test/unit/ngsiv2/ngsiService/queryDeviceInformationInCb-test.js +2 -1
- package/test/unit/ngsiv2/ngsiService/staticAttributes-test.js +2 -1
- package/test/unit/ngsiv2/ngsiService/subscriptions-test.js +2 -1
- package/test/unit/ngsiv2/plugins/alias-plugin_test.js +2 -1
- package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +8 -7
- package/test/unit/ngsiv2/plugins/compress-timestamp-plugin_test.js +2 -1
- package/test/unit/ngsiv2/plugins/custom-plugin_test.js +151 -0
- package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +87 -13
- package/test/unit/ngsiv2/plugins/timestamp-processing-plugin_test.js +2 -1
- package/test/unit/ngsiv2/provisioning/device-group-api-test.js +1 -0
- package/test/unit/ngsiv2/provisioning/device-group-utils-test.js +1 -0
- package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +12 -3
- package/test/unit/ngsiv2/provisioning/device-registration_test.js +2 -1
- package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +15 -12
- package/test/unit/ngsiv2/provisioning/listProvisionedDevices-test.js +1 -0
- package/test/unit/ngsiv2/provisioning/provisionDeviceMultientity-test.js +1 -0
- package/test/unit/ngsiv2/provisioning/removeProvisionedDevice-test.js +1 -0
- package/test/unit/ngsiv2/provisioning/singleConfigurationMode-test.js +1 -0
- package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +1 -0
- package/test/unit/plugins/capture-configuration-inPlugins_test.js +2 -1
- package/test/unit/plugins/capture-provision-inPlugins_test.js +2 -1
- package/doc/advanced-topics.md +0 -626
- package/doc/expressionLanguage.md +0 -762
- package/lib/plugins/expressionParser.js +0 -205
- package/test/unit/expressions/expression-test.js +0 -197
- package/test/unit/ngsi-ld/expressions/expressionBasedTransformations-test.js +0 -881
- package/test/unit/ngsiv2/expressions/expressionBasedTransformations-test.js +0 -950
- 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)
|
|
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
|
|
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
|
-
|
|
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 >
|
|
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 =
|
|
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;
|