iotagent-node-lib 2.26.0 → 3.1.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 (130) hide show
  1. package/.github/workflows/ci.yml +1 -0
  2. package/CHANGES_NEXT_RELEASE +2 -0
  3. package/docker-compose-dev.yml +1 -1
  4. package/lib/fiware-iotagent-lib.js +0 -5
  5. package/lib/plugins/compressTimestamp.js +2 -7
  6. package/lib/plugins/expressionParser.js +0 -47
  7. package/lib/plugins/expressionPlugin.js +6 -78
  8. package/lib/plugins/jexlParser.js +0 -36
  9. package/lib/plugins/pluginUtils.js +0 -119
  10. package/lib/services/ngsi/entities-NGSI-LD.js +586 -199
  11. package/lib/services/ngsi/entities-NGSI-v2.js +607 -297
  12. package/lib/services/ngsi/ngsiUtils.js +15 -22
  13. package/package.json +2 -2
  14. package/test/unit/general/config-multi-core-test.js +2 -1
  15. package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +2 -1
  16. package/test/unit/general/deviceService-test.js +2 -1
  17. package/test/unit/general/loglevel-api_test.js +2 -3
  18. package/test/unit/general/startup-test.js +2 -1
  19. package/test/unit/general/statistics-persistence_test.js +1 -0
  20. package/test/unit/general/statistics-service_test.js +1 -0
  21. package/test/unit/lazyAndCommands/commandRegistry_test.js +1 -0
  22. package/test/unit/memoryRegistry/deviceRegistryMemory_test.js +1 -0
  23. package/test/unit/mongodb/mongodb-connectionoptions-test.js +1 -0
  24. package/test/unit/mongodb/mongodb-group-registry-test.js +1 -0
  25. package/test/unit/mongodb/mongodb-registry-test.js +2 -1
  26. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin1.json +0 -5
  27. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast10.json +1 -1
  28. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast8.json +1 -1
  29. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast9.json +1 -1
  30. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin32.json +16 -15
  31. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin4.json +8 -8
  32. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin4a.json +34 -34
  33. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin5.json +8 -8
  34. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin6.json +0 -20
  35. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin7.json +0 -5
  36. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin8.json +10 -10
  37. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +8 -7
  38. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +5 -4
  39. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin3.json +1 -1
  40. package/test/unit/ngsi-ld/examples/contextRequests/updateContextProcessTimestamp.json +4 -4
  41. package/test/unit/ngsi-ld/examples/contextRequests/updateContextTimestampOverride.json +4 -3
  42. package/test/unit/ngsi-ld/examples/contextRequests/updateContextTimestampOverrideWithoutMilis.json +4 -3
  43. package/test/unit/ngsi-ld/expressions/expressionBasedTransformations-test.js +4 -6
  44. package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +1 -7
  45. package/test/unit/ngsi-ld/general/config-jsonld-contexts-test.js +2 -1
  46. package/test/unit/ngsi-ld/general/contextBrokerOAuthSecurityAccess-test.js +2 -1
  47. package/test/unit/ngsi-ld/general/deviceService-test.js +2 -1
  48. package/test/unit/ngsi-ld/general/https-support-test.js +2 -1
  49. package/test/unit/ngsi-ld/general/iotam-autoregistration-test.js +2 -1
  50. package/test/unit/ngsi-ld/general/startup-test.js +3 -2
  51. package/test/unit/ngsi-ld/lazyAndCommands/active-devices-attribute-update-test.js +2 -1
  52. package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +5 -7
  53. package/test/unit/ngsi-ld/lazyAndCommands/lazy-devices-test.js +8 -6
  54. package/test/unit/ngsi-ld/lazyAndCommands/merge-patch-test.js +18 -22
  55. package/test/unit/ngsi-ld/lazyAndCommands/polling-commands-test.js +2 -1
  56. package/test/unit/ngsi-ld/ngsiService/active-devices-test.js +2 -1
  57. package/test/unit/ngsi-ld/ngsiService/autocast-test.js +17 -4
  58. package/test/unit/ngsi-ld/ngsiService/geoproperties-test.js +2 -1
  59. package/test/unit/ngsi-ld/ngsiService/languageProperties-test.js +32 -34
  60. package/test/unit/ngsi-ld/ngsiService/staticAttributes-test.js +2 -1
  61. package/test/unit/ngsi-ld/ngsiService/subscriptions-test.js +2 -1
  62. package/test/unit/ngsi-ld/ngsiService/unsupported-endpoints-test.js +11 -15
  63. package/test/unit/ngsi-ld/plugins/alias-plugin_test.js +2 -3
  64. package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +2 -1
  65. package/test/unit/ngsi-ld/plugins/compress-timestamp-plugin_test.js +2 -32
  66. package/test/unit/ngsi-ld/plugins/multientity-plugin_test.js +20 -19
  67. package/test/unit/ngsi-ld/plugins/timestamp-processing-plugin_test.js +21 -7
  68. package/test/unit/ngsi-ld/provisioning/device-provisioning-api_test.js +1 -0
  69. package/test/unit/ngsi-ld/provisioning/device-registration_test.js +2 -1
  70. package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +15 -12
  71. package/test/unit/ngsi-ld/provisioning/listProvisionedDevices-test.js +1 -0
  72. package/test/unit/ngsi-ld/provisioning/provisionDeviceMultientity-test.js +1 -0
  73. package/test/unit/ngsi-ld/provisioning/removeProvisionedDevice-test.js +1 -0
  74. package/test/unit/ngsi-ld/provisioning/singleConfigurationMode-test.js +1 -0
  75. package/test/unit/ngsi-ld/provisioning/updateProvisionedDevices-test.js +1 -0
  76. package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +13 -7
  77. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin1.json +2 -2
  78. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin32.json +6 -0
  79. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin11.json +5 -1
  80. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin5.json +4 -4
  81. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin6.json +0 -16
  82. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin7.json +0 -4
  83. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin8.json +8 -8
  84. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +42 -42
  85. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +7 -7
  86. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin4.json +0 -5
  87. package/test/unit/ngsiv2/examples/contextRequests/updateContextProcessTimestamp.json +6 -6
  88. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampOverride.json +7 -1
  89. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampOverrideWithoutMilis.json +7 -1
  90. package/test/unit/ngsiv2/expressions/expressionBasedTransformations-test.js +2 -4
  91. package/test/unit/ngsiv2/expressions/expressionCombinedTransformations-test.js +4 -8
  92. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +5 -9
  93. package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +2 -1
  94. package/test/unit/ngsiv2/general/deviceService-test.js +2 -1
  95. package/test/unit/ngsiv2/general/https-support-test.js +2 -1
  96. package/test/unit/ngsiv2/general/iotam-autoregistration-test.js +2 -1
  97. package/test/unit/ngsiv2/general/startup-test.js +2 -1
  98. package/test/unit/ngsiv2/lazyAndCommands/active-devices-attribute-update-test.js +2 -1
  99. package/test/unit/ngsiv2/lazyAndCommands/command-test.js +2 -1
  100. package/test/unit/ngsiv2/lazyAndCommands/lazy-devices-test.js +8 -6
  101. package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +2 -1
  102. package/test/unit/ngsiv2/ngsiService/active-devices-test.js +3 -2
  103. package/test/unit/ngsiv2/ngsiService/autocast-test.js +2 -1
  104. package/test/unit/ngsiv2/ngsiService/queryDeviceInformationInCb-test.js +2 -1
  105. package/test/unit/ngsiv2/ngsiService/staticAttributes-test.js +2 -1
  106. package/test/unit/ngsiv2/ngsiService/subscriptions-test.js +2 -1
  107. package/test/unit/ngsiv2/plugins/alias-plugin_test.js +2 -3
  108. package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +2 -5
  109. package/test/unit/ngsiv2/plugins/compress-timestamp-plugin_test.js +2 -33
  110. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +7 -16
  111. package/test/unit/ngsiv2/plugins/timestamp-processing-plugin_test.js +3 -2
  112. package/test/unit/ngsiv2/provisioning/device-group-api-test.js +1 -0
  113. package/test/unit/ngsiv2/provisioning/device-group-utils-test.js +1 -0
  114. package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +1 -0
  115. package/test/unit/ngsiv2/provisioning/device-registration_test.js +2 -1
  116. package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +15 -12
  117. package/test/unit/ngsiv2/provisioning/listProvisionedDevices-test.js +1 -0
  118. package/test/unit/ngsiv2/provisioning/provisionDeviceMultientity-test.js +1 -0
  119. package/test/unit/ngsiv2/provisioning/removeProvisionedDevice-test.js +1 -0
  120. package/test/unit/ngsiv2/provisioning/singleConfigurationMode-test.js +1 -0
  121. package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +1 -0
  122. package/test/unit/plugins/capture-configuration-inPlugins_test.js +2 -1
  123. package/test/unit/plugins/capture-provision-inPlugins_test.js +2 -1
  124. package/lib/plugins/addEvent.js +0 -32
  125. package/lib/plugins/attributeAlias.js +0 -107
  126. package/lib/plugins/multiEntity.js +0 -255
  127. package/lib/plugins/timestampProcessPlugin.js +0 -95
  128. package/test/unit/ngsi-ld/plugins/event-plugin_test.js +0 -116
  129. package/test/unit/ngsiv2/plugins/event-plugin_test.js +0 -118
  130. package/test/unit/ngsiv2/plugins/translation-inPlugins_test.js +0 -262
@@ -1,118 +0,0 @@
1
- /*
2
- * Copyright 2015 Telefonica Investigación y Desarrollo, S.A.U
3
- *
4
- * This file is part of fiware-iotagent-lib
5
- *
6
- * fiware-iotagent-lib is free software: you can redistribute it and/or
7
- * modify it under the terms of the GNU Affero General Public License as
8
- * published by the Free Software Foundation, either version 3 of the License,
9
- * or (at your option) any later version.
10
- *
11
- * fiware-iotagent-lib is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
- * See the GNU Affero General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Affero General Public
17
- * License along with fiware-iotagent-lib.
18
- * If not, see http://www.gnu.org/licenses/.
19
- *
20
- * For those usages not covered by the GNU Affero General Public License
21
- * please contact with::daniel.moranjimenez@telefonica.com
22
- *
23
- * Modified by: Daniel Calvo - ATOS Research & Innovation
24
- */
25
-
26
- const iotAgentLib = require('../../../../lib/fiware-iotagent-lib');
27
- const should = require('should');
28
- const logger = require('logops');
29
- const nock = require('nock');
30
- let contextBrokerMock;
31
- const iotAgentConfig = {
32
- contextBroker: {
33
- host: '192.168.1.1',
34
- port: '1026',
35
- ngsiVersion: 'v2'
36
- },
37
- server: {
38
- port: 4041
39
- },
40
- types: {
41
- Light: {
42
- commands: [],
43
- type: 'Light',
44
- lazy: [
45
- {
46
- name: 'temperature',
47
- type: 'centigrades'
48
- }
49
- ],
50
- active: [
51
- {
52
- name: 'pressure',
53
- type: 'Hgmm'
54
- }
55
- ]
56
- }
57
- },
58
- service: 'smartgondor',
59
- subservice: 'gardens',
60
- providerUrl: 'http://smartgondor.com'
61
- };
62
-
63
- describe('NGSI-v2 - Event plugin', function () {
64
- beforeEach(function (done) {
65
- logger.setLevel('FATAL');
66
-
67
- iotAgentLib.activate(iotAgentConfig, function () {
68
- iotAgentLib.clearAll(function () {
69
- iotAgentLib.addUpdateMiddleware(iotAgentLib.dataPlugins.addEvents.update);
70
- iotAgentLib.addQueryMiddleware(iotAgentLib.dataPlugins.addEvents.query);
71
- done();
72
- });
73
- });
74
- });
75
-
76
- afterEach(function (done) {
77
- iotAgentLib.clearAll(function () {
78
- iotAgentLib.deactivate(done);
79
- });
80
- });
81
- describe('When an update comes with an event to the plugin', function () {
82
- const values = [
83
- {
84
- name: 'state',
85
- type: 'Boolean',
86
- value: 'true'
87
- },
88
- {
89
- name: 'activation',
90
- type: 'Event',
91
- value: '1'
92
- }
93
- ];
94
-
95
- beforeEach(function () {
96
- nock.cleanAll();
97
-
98
- contextBrokerMock = nock('http://192.168.1.1:1026')
99
- .matchHeader('fiware-service', 'smartgondor')
100
- .matchHeader('fiware-servicepath', 'gardens')
101
- .patch('/v2/entities/light1/attrs', function (body) {
102
- const dateRegex = /\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d.\d{3}Z/;
103
-
104
- return body.activation.value.match(dateRegex);
105
- })
106
- .query({ type: 'Light' })
107
- .reply(204);
108
- });
109
-
110
- it('should return an entity with all its timestamps expanded to have separators', function (done) {
111
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
112
- should.not.exist(error);
113
- contextBrokerMock.done();
114
- done();
115
- });
116
- });
117
- });
118
- });
@@ -1,262 +0,0 @@
1
- /*
2
- * Copyright 2014 Telefonica Investigación y Desarrollo, S.A.U
3
- *
4
- * This file is part of fiware-iotagent-lib
5
- *
6
- * fiware-iotagent-lib is free software: you can redistribute it and/or
7
- * modify it under the terms of the GNU Affero General Public License as
8
- * published by the Free Software Foundation, either version 3 of the License,
9
- * or (at your option) any later version.
10
- *
11
- * fiware-iotagent-lib is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
- * See the GNU Affero General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Affero General Public
17
- * License along with fiware-iotagent-lib.
18
- * If not, see http://www.gnu.org/licenses/.
19
- *
20
- * For those usages not covered by the GNU Affero General Public License
21
- * please contact with::[contacto@tid.es]
22
- */
23
-
24
- /* eslint-disable no-unused-vars */
25
-
26
- const iotAgentLib = require('../../../../lib/fiware-iotagent-lib');
27
- const utils = require('../../../tools/utils');
28
- const request = utils.request;
29
- const should = require('should');
30
- const logger = require('logops');
31
- const nock = require('nock');
32
- let contextBrokerMock;
33
- const iotAgentConfig = {
34
- contextBroker: {
35
- host: '192.168.1.1',
36
- port: '1026',
37
- nsgiVersion: 'v2'
38
- },
39
- server: {
40
- port: 4041
41
- },
42
- types: {
43
- Light: {
44
- commands: [],
45
- type: 'Light',
46
- lazy: [
47
- {
48
- name: 'temperature',
49
- type: 'centigrades'
50
- }
51
- ],
52
- active: [
53
- {
54
- name: 'pressure',
55
- type: 'Hgmm'
56
- }
57
- ]
58
- },
59
- BrokenLight: {
60
- commands: [],
61
- lazy: [
62
- {
63
- name: 'temperature',
64
- type: 'centigrades'
65
- }
66
- ],
67
- active: [
68
- {
69
- name: 'pressure',
70
- type: 'Hgmm'
71
- }
72
- ]
73
- },
74
- Termometer: {
75
- type: 'Termometer',
76
- commands: [],
77
- lazy: [
78
- {
79
- name: 'temp',
80
- type: 'kelvin'
81
- }
82
- ],
83
- active: []
84
- },
85
- Humidity: {
86
- type: 'Humidity',
87
- cbHost: 'http://192.168.1.1:3024',
88
- commands: [],
89
- lazy: [],
90
- active: [
91
- {
92
- name: 'humidity',
93
- type: 'percentage'
94
- }
95
- ]
96
- },
97
- Motion: {
98
- type: 'Motion',
99
- commands: [],
100
- lazy: [],
101
- staticAttributes: [
102
- {
103
- name: 'location',
104
- type: 'Vector',
105
- value: '(123,523)'
106
- }
107
- ],
108
- active: [
109
- {
110
- name: 'humidity',
111
- type: 'percentage'
112
- }
113
- ]
114
- }
115
- },
116
- service: 'smartgondor',
117
- subservice: 'gardens',
118
- providerUrl: 'http://smartgondor.com',
119
- deviceRegistrationDuration: 'P1M'
120
- };
121
-
122
- describe('NGSI-v2 - Data Mapping Plugins: translation', function () {
123
- beforeEach(function (done) {
124
- logger.setLevel('FATAL');
125
-
126
- iotAgentLib.activate(iotAgentConfig, function () {
127
- iotAgentLib.clearAll(done);
128
- });
129
- });
130
-
131
- afterEach(function (done) {
132
- iotAgentLib.clearAll(function () {
133
- iotAgentLib.deactivate(done);
134
- });
135
- });
136
-
137
- describe('When a new update translation middleware is added to the IoT Agent', function () {
138
- beforeEach(function () {
139
- nock.cleanAll();
140
-
141
- contextBrokerMock = nock('http://192.168.1.1:1026')
142
- .matchHeader('fiware-service', 'smartgondor')
143
- .matchHeader('fiware-servicepath', 'gardens')
144
- .patch(
145
- '/v2/entities/light1/attrs?type=Light',
146
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/updateContextMiddleware1.json')
147
- )
148
- .reply(204);
149
- });
150
-
151
- it('should execute the translation middlewares', function (done) {
152
- const values = [
153
- {
154
- name: 'state',
155
- type: 'Boolean',
156
- value: 'true'
157
- },
158
- {
159
- name: 'dimming',
160
- type: 'Percentage',
161
- value: '87'
162
- }
163
- ];
164
-
165
- let executed = false;
166
-
167
- function testMiddleware(entity, typeInformation, callback) {
168
- entity.dimming.value = entity.dimming.value + '%';
169
- executed = true;
170
- callback(null, entity, typeInformation);
171
- }
172
-
173
- iotAgentLib.addUpdateMiddleware(testMiddleware);
174
-
175
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
176
- should.not.exist(error);
177
- executed.should.equal(true);
178
- done();
179
- });
180
- });
181
-
182
- it('should translate the appropriate attributes', function (done) {
183
- const values = [
184
- {
185
- name: 'state',
186
- type: 'Boolean',
187
- value: 'true'
188
- },
189
- {
190
- name: 'dimming',
191
- type: 'Percentage',
192
- value: '87'
193
- }
194
- ];
195
-
196
- function testMiddleware(entity, typeInformation, callback) {
197
- entity.dimming.value = entity.dimming.value + '%';
198
- callback(null, entity, typeInformation);
199
- }
200
-
201
- iotAgentLib.addUpdateMiddleware(testMiddleware);
202
-
203
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
204
- should.not.exist(error);
205
- contextBrokerMock.done();
206
- done();
207
- });
208
- });
209
- });
210
-
211
- describe('When a new query translation middleware is added to the IoT Agent', function () {
212
- const attributes = ['state', 'dimming'];
213
-
214
- beforeEach(function () {
215
- nock.cleanAll();
216
-
217
- contextBrokerMock = nock('http://192.168.1.1:1026')
218
- .matchHeader('fiware-service', 'smartgondor')
219
- .matchHeader('fiware-servicepath', 'gardens')
220
- .get('/v2/entities/light1/attrs?attrs=state,dimming&type=Light')
221
-
222
- .reply(
223
- 200,
224
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/updateContextMiddleware2.json')
225
- );
226
- });
227
-
228
- it('should call the middleware', function (done) {
229
- let called = false;
230
-
231
- function testMiddleware(entity, typeInformation, callback) {
232
- entity.dimming.value = entity.dimming.value + '%';
233
-
234
- called = true;
235
-
236
- callback(null, entity, typeInformation);
237
- }
238
-
239
- iotAgentLib.addQueryMiddleware(testMiddleware);
240
-
241
- iotAgentLib.query('light1', 'Light', '', attributes, function (error, result) {
242
- should.not.exist(error);
243
- called.should.equal(true);
244
- done();
245
- });
246
- });
247
- it('should call the middleware', function (done) {
248
- function testMiddleware(entity, typeInformation, callback) {
249
- entity.dimming.value = entity.dimming.value + '%';
250
- callback(null, entity, typeInformation);
251
- }
252
-
253
- iotAgentLib.addQueryMiddleware(testMiddleware);
254
-
255
- iotAgentLib.query('light1', 'Light', '', attributes, function (error, result) {
256
- should.not.exist(error);
257
- result.dimming.value.should.equal('23%');
258
- done();
259
- });
260
- });
261
- });
262
- });