cht-conf 5.3.0 → 5.4.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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [5.4.0](https://github.com/medic/cht-conf/compare/v5.3.0...v5.4.0) (2025-09-11)
2
+
3
+
4
+ ### Features
5
+
6
+ * **#561:** add form validation for `instance::db-doc-ref` ([#738](https://github.com/medic/cht-conf/issues/738)) ([941a6f5](https://github.com/medic/cht-conf/commit/941a6f5b7504d6ff8c1682845d6e38efd6ea017b)), closes [#561](https://github.com/medic/cht-conf/issues/561)
7
+
1
8
  # [5.3.0](https://github.com/medic/cht-conf/compare/v5.2.1...v5.3.0) (2025-09-04)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cht-conf",
3
- "version": "5.3.0",
3
+ "version": "5.4.0",
4
4
  "description": "Configure CHT deployments",
5
5
  "main": "./src/lib/main.js",
6
6
  "engines": {
@@ -1,7 +1,6 @@
1
1
  const { getPrimaryInstanceNode, getNodes, getPrimaryInstanceNodeChildPath } = require('../../forms-utils');
2
2
 
3
3
  module.exports = {
4
- name: 'db-doc-is-valid.js',
5
4
  requiresInstance: false,
6
5
  execute: async ({ xmlDoc, xformPath }) => {
7
6
  const errors = [];
@@ -0,0 +1,28 @@
1
+ const { getPrimaryInstanceNode, getNodes, getNode, getPrimaryInstanceNodeChildPath } = require('../../forms-utils');
2
+
3
+ module.exports = {
4
+ requiresInstance: false,
5
+ execute: ({ xmlDoc, xformPath }) => {
6
+ const errors = [];
7
+ const primaryInstance = getPrimaryInstanceNode(xmlDoc);
8
+ const formRootNode = Array
9
+ .from(primaryInstance.childNodes)
10
+ .find(n => n.nodeType === 1);
11
+ const refNodes = getNodes(xmlDoc, '//*[@db-doc-ref]', primaryInstance);
12
+ refNodes.forEach(node => {
13
+ const refPath = node
14
+ .getAttribute('db-doc-ref')
15
+ .trim()
16
+ .replace(/^\//, '');
17
+ const targetNode = getNode(primaryInstance, refPath);
18
+ if (!targetNode || (targetNode !== formRootNode && targetNode.getAttribute('db-doc') !== 'true')) {
19
+ const nodeName = getPrimaryInstanceNodeChildPath(node);
20
+ errors.push(` - ${nodeName}: the db-doc-ref value [${refPath}] does not reference a valid doc node.`);
21
+ }
22
+ });
23
+
24
+ const header = `Form at ${xformPath} contains invalid db-doc-ref configuration. A db-doc-ref value should point `
25
+ + `to either the root node of the form or to a group that is adding a new doc (with db-doc set to "true"):`;
26
+ return { errors: errors.length ? [header, ...errors]: errors };
27
+ },
28
+ };