@opengis/fastify-table 1.2.51 → 1.2.52

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.2.51",
3
+ "version": "1.2.52",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -1,9 +1,20 @@
1
+ import config from '../../../../config.js';
1
2
 
2
3
  const emailReg = /(?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/g;
3
4
 
4
- function checkField(key, val, options, idx) {
5
+ function checkField(key, val, options, idx, body) {
5
6
  // validators: [required]
6
7
  if (options?.validators?.includes('required') && !val) {
8
+ if (options?.conditions) {
9
+ const allowed = JSON.parse(options?.conditions?.[2] || null);
10
+ const check = options?.conditions?.[1] === 'in' && Array.isArray(allowed)
11
+ ? allowed.includes(body[options?.conditions?.[0] || ''])
12
+ : body[options?.conditions?.[0] || ''] === allowed;
13
+ if (!check) {
14
+ if (config.trace) console.log('validateData', 'skip conditions', key, body[options?.conditions?.[0] || ''], allowed);
15
+ return { key, val, idx };
16
+ }
17
+ }
7
18
  return {
8
19
  error: 'empty required', key, idx,
9
20
  };
@@ -32,7 +43,7 @@ function checkBody({ body = {}, arr = [], idx }) {
32
43
  return acc1;
33
44
  }
34
45
 
35
- const check = checkField(key, body[key], input, idx) || {};
46
+ const check = checkField(key, body[key], input, idx, body) || {};
36
47
  acc1.push({ key, val: body[key], ...check });
37
48
  return acc1;
38
49
  }, []);