iotagent-node-lib
iotagent-node-lib copied to clipboard
Add Merge-Patch Support Handling
merge-patch is an advanced operation which would be usefully supported by some robotics IoT Agents - e.g. ROS2, OPC-UA. This PR adds a new merge-patch handler and forwards NGSI-LD merge-patch requests to the handler as necessary.
- Update server
- Add Unit Tests
- Update Docs
Not all IoT Agents will need to support advanced services such as merge-patch, NGSI-LD null or datasetId, flags have been included to allow support for these payloads to be withdrawn.
When in ld
mode, the defaults for the NSGI-LD server of the IoT Agent handling null
and datasetId
should both be true
, as supporting both is standard for NSGI-LD 1.5 - how this works in practice will depend on the handler within the relevant IoT Agent.
For example, a payload like this
{
"position": [
{
"type": "Property",
"value": [ 1, 2, 3 ],
"datasetId": "urn:ngsi-ld:this"
},
{
"type": "Property",
"value": [ 28, -104, 23 ],
"datasetId": "urn:ngsi-ld:that"
}
]
}
Will send two copies of the position
attribute to be processed. Whether that is to be interpreted as "two sequential commands" or "do nothing at all with attributes containing a datasetId
" will depend on the handler in the IoT Agent.
Without further changes downstream, at the moment, the IoT Agent for JSON and IoT Agent for Ultralight will accept this as two sequential commands on the default datasetId
- additional code will be required to allow for other options.
This PR will close the remaining issues from #1259
The main part still missing is an ability to reject
null
and/ordatasetId
on purpose - i.e. "This IoT Agent can't understand that payload" - and make that configurable throughconfig.js
and environment variables.
CHANGES_NEXT_RELEASE entry is missing
CHANGES_NEXT_RELEASE entry is missing
Fixed ce7746b
@jason-fox please fix the small conflict in CHANGES_NEXT_RELEASE file so this PR becomes mergeable again.
@jason-fox weirdly, test are failing
825 passing (25s)
[1802](https://github.com/telefonicaid/iotagent-node-lib/actions/runs/4418276954/jobs/7745258389#step:5:1803)
11 pending
[1803](https://github.com/telefonicaid/iotagent-node-lib/actions/runs/4418276954/jobs/7745258389#step:5:1804)
1 failing
[1804](https://github.com/telefonicaid/iotagent-node-lib/actions/runs/4418276954/jobs/7745258389#step:5:1805)
[1805](https://github.com/telefonicaid/iotagent-node-lib/actions/runs/4418276954/jobs/7745258389#step:5:1806)
1) NGSI-LD - Merge-Patch functionalities
[1806](https://github.com/telefonicaid/iotagent-node-lib/actions/runs/4418276954/jobs/7745258389#step:5:1807)
When a merge-patch PATCH arrives to the IoT Agent as Context Provider
[1807](https://github.com/telefonicaid/iotagent-node-lib/actions/runs/4418276954/jobs/7745258389#step:5:1808)
should call the client handler once:
[1808](https://github.com/telefonicaid/iotagent-node-lib/actions/runs/4418276954/jobs/7745258389#step:5:1809)
Error: Timeout of 8000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/runner/work/iotagent-node-lib/iotagent-node-lib/test/unit/ngsi-ld/lazyAndCommands/merge-patch-test.js)
[1809](https://github.com/telefonicaid/iotagent-node-lib/actions/runs/4418276954/jobs/7745258389#step:5:1810)
at listOnTimeout (internal/timers.js:557:17)
[1810](https://github.com/telefonicaid/iotagent-node-lib/actions/runs/4418276954/jobs/7745258389#step:5:1811)
at processTimers (internal/timers.js:500:7)
[1811](https://github.com/telefonicaid/iotagent-node-lib/actions/runs/4418276954/jobs/7745258389#step:5:1812)
test was failing
@mapedraza this is because this PR predates #1302 which has just been merged, and therefore the updated 1.6.1 NGSI-LD registration is required when provisioning - fixed 8510ad2