@5minds/node-red-contrib-processcube 1.8.3-feature-ce2509-m848p0ot → 1.8.3-feature-de7526-m876bxcq
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.
@@ -7,6 +7,7 @@
|
|
7
7
|
engine: { value: '', type: 'processcube-engine-config' },
|
8
8
|
query: { value: 'payload' },
|
9
9
|
query_type: { value: 'msg' },
|
10
|
+
onlyNewest: { value: true },
|
10
11
|
},
|
11
12
|
inputs: 1,
|
12
13
|
outputs: 1,
|
@@ -43,6 +44,10 @@
|
|
43
44
|
<label for="node-input-query"><i class="fa fa-tag"></i> Query</label>
|
44
45
|
<input type="text" id="node-input-query" />
|
45
46
|
</div>
|
47
|
+
<div class="form-row">
|
48
|
+
<label for="node-input-onlyNewest"><i class="fa fa-hand"></i>Only current instance per dataObject</label>
|
49
|
+
<input type="checkbox" id="node-input-onlyNewest" title="Applys a client-side filter, that returns just the newest instance per dataObject">
|
50
|
+
</div>
|
46
51
|
</script>
|
47
52
|
|
48
53
|
<script type="text/markdown" data-help-name="dataobject-instance-query">
|
@@ -113,6 +118,22 @@ A node to query dataobject instances on the ProcessCube Engine.
|
|
113
118
|
- array: 2021-01-01T00:00:00.000Z,2021-01-02T00:00:00.000Z
|
114
119
|
- Description: The created date of the DataObjectInstances to include in the results.
|
115
120
|
|
121
|
+
### Only current instance per dataObject
|
122
|
+
|
123
|
+
When checked, an additional filter is applied to the result of the query.
|
124
|
+
For each `dataObjectId`+`processInstanceId` in the result set, only the instance with the newest `createdAt` timestamp will be returned.
|
125
|
+
Therefore, it creates a list containing only the current values of each dataObject.
|
126
|
+
|
127
|
+
**Note**: This is not guranteed to work as described above. Since this is a client-side filter, that is applied after executing the server side query, there are some limitations.
|
128
|
+
Depending on your query, you might not load all instances of an dataObject. I.e. when setting a limit or offset. Or when querying such an amount of instances, that the engine applies an automatic limit.
|
129
|
+
In these cases, this filter will still be applied and return the newest instance from the result set, but that might not be the actual newest value for this dataObject, which would be available in the engines database.
|
130
|
+
To avoid thoses problems, make sure to write strict queries, which are guranteed to have a small result set, that can be retrieved in one request.
|
131
|
+
The `totalCount` property will, as well, not work as expected. Since this is a value created by the engine, it will not line up with the actual amount of instances, that are returned.
|
132
|
+
|
133
|
+
**Note**: This feature will be removed in a future version.
|
134
|
+
Due to the problems described above, this functionality should rather be provided by the engines interface.
|
135
|
+
As soon as the engine supports querying for the newest dataObject values, this filter becomes obsolete and you should instead alter your query to apply this filter server-side.
|
136
|
+
|
116
137
|
### References
|
117
138
|
|
118
139
|
- [The ProcessCube© Developer Network](https://processcube.io) - All documentation for the ProcessCube© platform
|
@@ -21,6 +21,19 @@ module.exports = function (RED) {
|
|
21
21
|
.then((matchingInstances) => {
|
22
22
|
msg.payload = matchingInstances;
|
23
23
|
|
24
|
+
if (config.onlyNewest) {
|
25
|
+
const newestInstances = {};
|
26
|
+
|
27
|
+
matchingInstances.dataObjectInstances.forEach(instance => {
|
28
|
+
newestInstances[instance.processInstanceId] ??= {};
|
29
|
+
if (!newestInstances[instance.processInstanceId][instance.dataObjectId] || newestInstances[instance.processInstanceId][instance.dataObjectId].createdAt < instance.createdAt) {
|
30
|
+
newestInstances[instance.processInstanceId][instance.dataObjectId] = instance;
|
31
|
+
}
|
32
|
+
})
|
33
|
+
|
34
|
+
msg.payload.dataObjectInstances = Object.values(newestInstances).flatMap(v => Object.values(v));
|
35
|
+
}
|
36
|
+
|
24
37
|
node.send(msg);
|
25
38
|
})
|
26
39
|
.catch((error) => {
|